Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Sep 2022 07:08:01 GMT
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 203f2c14c4b3 - main - init: fix shutdown race
Message-ID:  <202209060708.286781sr014184@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=203f2c14c4b3c7a3e8f51a5a248201e1eb091886

commit 203f2c14c4b3c7a3e8f51a5a248201e1eb091886
Author:     Corvin Köhne <CorvinK@beckhoff.com>
AuthorDate: 2022-09-06 07:06:51 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-09-06 07:06:51 +0000

    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
---
 sbin/init/init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sbin/init/init.c b/sbin/init/init.c
index 813387f63c81..cf48721faf8d 100644
--- a/sbin/init/init.c
+++ b/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 "



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202209060708.286781sr014184>