[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
This commit is contained in:
Andreas Schwab 2022-10-01 12:47:42 -04:00 committed by Paul Smith
parent c2eddf9be2
commit c801a7fb67
2 changed files with 9 additions and 2 deletions

View file

@ -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);

View file

@ -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;
}