>From 5ec4d920e4acb45225320c3df9ae32fdff928413 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 28 Apr 2020 12:35:19 +0200 Subject: [PATCH 2/2] posix_spawn_file_actions_addfchdir tests: Enhance test. * tests/test-posix_spawn5.c: Include findprog.h. (test): New function, extracted from main. (main): Invoke it. Also, invoke it with a program name such as "bin/pwd". * modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add findprog. --- ChangeLog | 10 +++++++++ modules/posix_spawn_file_actions_addfchdir-tests | 1 + tests/test-posix_spawn5.c | 27 +++++++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4986ad2..ec8db18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2020-04-28 Bruno Haible + posix_spawn_file_actions_addfchdir tests: Enhance test. + * tests/test-posix_spawn5.c: Include findprog.h. + (test): New function, extracted from main. + (main): Invoke it. Also, invoke it with a program name such as + "bin/pwd". + * modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add + findprog. + +2020-04-28 Bruno Haible + posix_spawn_file_actions_addchdir tests: Enhance test. * tests/test-posix_spawn4.c: Include findprog.h. (test): New function, extracted from main. diff --git a/modules/posix_spawn_file_actions_addfchdir-tests b/modules/posix_spawn_file_actions_addfchdir-tests index 5e50695..809d238 100644 --- a/modules/posix_spawn_file_actions_addfchdir-tests +++ b/modules/posix_spawn_file_actions_addfchdir-tests @@ -7,6 +7,7 @@ tests/macros.h Depends-on: posix_spawn_file_actions_init posix_spawnp-tests +findprog configure.ac: diff --git a/tests/test-posix_spawn5.c b/tests/test-posix_spawn5.c index 375f08f..c5ca2a3 100644 --- a/tests/test-posix_spawn5.c +++ b/tests/test-posix_spawn5.c @@ -31,6 +31,8 @@ #include #include +#include "findprog.h" + static int fd_safer (int fd) { @@ -46,8 +48,8 @@ fd_safer (int fd) return fd; } -int -main () +static void +test (const char *pwd_prog) { char *argv[2] = { (char *) "pwd", NULL }; int rootfd; @@ -97,7 +99,7 @@ main () || (attrs_allocated = true, (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0 || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0) - || (err = posix_spawnp (&child, "pwd", &actions, &attrs, argv, environ)) != 0)) + || (err = posix_spawnp (&child, pwd_prog, &actions, &attrs, argv, environ)) != 0)) { if (actions_allocated) posix_spawn_file_actions_destroy (&actions); @@ -144,5 +146,24 @@ main () fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus); exit (1); } +} + +int +main () +{ + test ("pwd"); + + /* Verify that if a program is given as a relative file name with at least one + slash, it is interpreted w.r.t. the current directory after fchdir has been + executed. */ + { + const char *abs_pwd_prog = find_in_path ("pwd"); + + if (abs_pwd_prog != NULL + && abs_pwd_prog[0] == '/' + && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/') + test (&abs_pwd_prog[1]); + } + return 0; } -- 2.7.4