From c801a7fb6703e9aeeed2605eaa0c715cadecbfb3 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 1 Oct 2022 12:47:42 -0400 Subject: [PATCH] [SV 63111] Ensure output-sync is cleaned on re-exec and recursion Now that output-sync is using a separate file as a mutex rather than stdout, ensure the new file descriptor is closed before re-exec and not inherited by children. * src/main.c (main): Call osync_clear() before re-exec. * src/posixos.c (osync_setup): Reset output-sync handle inheritance. (osync_parse_mutex): Ditto. Copyright-paperwork-exempt: yes --- src/main.c | 2 ++ src/posixos.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 3821089c..2daf2dba 100644 --- a/src/main.c +++ b/src/main.c @@ -2727,6 +2727,8 @@ main (int argc, char **argv, char **envp) fflush (stdout); fflush (stderr); + osync_clear(); + /* The exec'd "child" will be another make, of course. */ jobserver_pre_child(1); diff --git a/src/posixos.c b/src/posixos.c index d587f9c8..c6500efa 100644 --- a/src/posixos.c +++ b/src/posixos.c @@ -462,7 +462,7 @@ jobserver_acquire (int timeout) case EBADF: /* Someone closed the jobs pipe. That shouldn't happen but if it does we're done. */ - O (fatal, NILF, _("job server shut down")); + O (fatal, NILF, _("job server shut down")); default: pfatal_with_name (_("pselect jobs pipe")); @@ -628,7 +628,10 @@ osync_setup () { osync_handle = get_tmpfd (&osync_tmpfile); if (osync_handle >= 0) - sync_parent = 1; + { + fd_noinherit (osync_handle); + sync_parent = 1; + } } char * @@ -662,6 +665,8 @@ osync_parse_mutex (const char *mutex) OSS (fatal, NILF, _("cannot open output sync mutex %s: %s"), osync_tmpfile, strerror (errno)); + fd_noinherit (osync_handle); + return 1; }