init: fix shutdown race

When calling shutdown, shutdown sends a signal to init and exits. This
causes a race condition for the waitpid function. If the signal wins the
race, wpid will be set to -1 and init calls death_single. If shutdown
wins the race, wpid will be set to the pid of the shutdown process and
the requested_transition will be ignored.

Reviewed by:		imp
Differential Revision:	https://reviews.freebsd.org/D36356
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
main
Corvin Köhne 3 months ago committed by Emmanuel Vadot
parent 95270f73ba
commit 203f2c14c4
  1. 6
      sbin/init/init.c

@ -1143,10 +1143,10 @@ run_script(const char *script)
do {
if ((wpid = waitpid(-1, &status, WUNTRACED)) != -1)
collect_child(wpid);
if (requested_transition == death_single ||
requested_transition == reroot)
return (state_func_t) requested_transition;
if (wpid == -1) {
if (requested_transition == death_single ||
requested_transition == reroot)
return (state_func_t) requested_transition;
if (errno == EINTR)
continue;
warning("wait for %s on %s failed: %m; going to "

Loading…
Cancel
Save