On POSIX systems the GNU make jobserver is implemented as a pipe, and these two unexpected descriptors make test-execute-child fail.
Workaround this by making all unexpected descriptors cloexec in test-execute-main so they are not inherited by test-execute-child. * tests/test-execute-main.c (cloexec_fds): New function. (main): Use it. --- OK to commit? ChangeLog | 6 ++++++ tests/test-execute-main.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 46496bc75..e65a96e8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-04-07 Dmitry V. Levin <[email protected]> + + tests: fix test-execute with GNU make jobserver. + * tests/test-execute-main.c (cloexec_fds): New function. + (main): Use it. + 2021-04-06 Paul Eggert <[email protected]> group-member: minor tweak to omit a * diff --git a/tests/test-execute-main.c b/tests/test-execute-main.c index 39e24af12..62f76de43 100644 --- a/tests/test-execute-main.c +++ b/tests/test-execute-main.c @@ -47,6 +47,21 @@ #define BASE "test-execute" +static void +cloexec_fds(int first, int last) +{ + int fd; + for (fd = first; fd <= last; ++fd) { + int dup_fd; + dup_fd = fcntl (fd, F_DUPFD_CLOEXEC, 0); + if (dup_fd >= 0) { + ASSERT (close (fd) == 0); + ASSERT (fcntl (dup_fd, F_DUPFD_CLOEXEC, fd) == fd); + ASSERT (close (dup_fd) == 0); + } + } +} + int main (int argc, char *argv[]) { @@ -288,6 +303,7 @@ main (int argc, char *argv[]) case 14: { /* Check file descriptors >= 3 can be inherited. */ + cloexec_fds(3, 19); ASSERT (dup2 (STDOUT_FILENO, 10) >= 0); const char *prog_argv[3] = { prog_path, "14", NULL }; int ret = execute (progname, prog_argv[0], prog_argv, NULL, @@ -298,6 +314,7 @@ main (int argc, char *argv[]) case 15: { /* Check file descriptors >= 3 can be inherited. */ + cloexec_fds(3, 19); ASSERT (fcntl (STDOUT_FILENO, F_DUPFD, 10) >= 0); const char *prog_argv[3] = { prog_path, "15", NULL }; int ret = execute (progname, prog_argv[0], prog_argv, NULL, @@ -308,6 +325,7 @@ main (int argc, char *argv[]) case 16: { /* Check file descriptors >= 3 with O_CLOEXEC bit are not inherited. */ + cloexec_fds(3, 19); ASSERT (fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC, 10) >= 0); const char *prog_argv[3] = { prog_path, "16", NULL }; int ret = execute (progname, prog_argv[0], prog_argv, NULL, -- ldv
