From nobody Tue Sep 06 07:08:01 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MMGgP4gnTz4cLL6; Tue, 6 Sep 2022 07:08:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MMGgP403pz3XqV; Tue, 6 Sep 2022 07:08:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662448081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HQNXGmKoCB1no4Gy8CVWC/DFY+hnU7CwsouwxuJCezY=; b=mBRbzXH5e7bijd2RM09aObpyqIn/9FGQjLrg40avUC8VD5/L7+L5r+3neyiVIBjjIg8T1i KHOUjwX8uctfDd76BJ+77sakuO/Y85biOIAo9Fy60JgHslWDrZbMZA+kgrDMQ38pRe4vEr q0GXANrVq+r0/R09QkMlFvOkUbBB2TLkAhaVm0U26WIIvoANNtlb/9m/M1zdJbRBeUYOxi RtjhKcZtF/lhFr6cRM7kPFt0dtHQhZeQEE2rrd2IJNTjk9NJ5X6yVauBEpovKh5t6tTn/Y oNWjzNX+toNSvbgVsgz464bb3VWIj+tBX5ELlrWII4i/PrTL8M5ESXkm03M3Zw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MMGgP2t34z15M2; Tue, 6 Sep 2022 07:08:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 286781Bq014185; Tue, 6 Sep 2022 07:08:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 286781sr014184; Tue, 6 Sep 2022 07:08:01 GMT (envelope-from git) Date: Tue, 6 Sep 2022 07:08:01 GMT Message-Id: <202209060708.286781sr014184@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 203f2c14c4b3 - main - init: fix shutdown race List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 203f2c14c4b3c7a3e8f51a5a248201e1eb091886 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1662448081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HQNXGmKoCB1no4Gy8CVWC/DFY+hnU7CwsouwxuJCezY=; b=HQpX4LHt78mRZXQVwxjLdeqSE5afuwqNVGMuMpQ5AowHG95MJ+fLZF6S/JmduwMsMhseQJ XeV9orvoDveVFwAFD1IW8Ccl1uAkROy5oBgCW2UG4mPY/EDi7uRyYZM6mu/743BavkeBUR uV1EGLxNChq+l5xjSz2snEqGMD0d81PRYMyXngqamRx5e/yHUtn92XclaTNMDv3jqciF9w 7ycMJNkvNokr7UFdY3jejugrzwRWTQrumnUhp8BRo4ONHNGQa7lncd2bwdw8fmROBN20eF pONhQt7TlIVdTrUP0+NbSQ0VIDd+LMR8pdSf3y5bCt8X7zaanOeYipiAAuHlaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1662448081; a=rsa-sha256; cv=none; b=r9thHQvPqGIwqPyd2a7XjW/D/PTcOEOcQMqI6JSsmn96ctdbSuO6PN7Hn737ECldywNmA6 bg5fKGDTVsbF/PSWiknqWWw5tLPq8d2CBmxafBV/tN3ZTTviN1X22+bUPFfW+qiYFSk6wQ knVwpAXaGjzkOnUO0LbB7e5HExGoW/k7HSgrX8aARpoODe4euCZZwXSVcbm580VQvjKr91 w+KgnMtlWWAduB0u4KdM1j2Qhb4E096JZes0SSu8WjprvkJ8D4tjuo/GWKBclOye91TwBb TZYlrIcxm3QNJn7jdx1s9YyxGHGOdTSHGf+2q78rTRnamrNoWTZRjKYwv4h9Pg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=203f2c14c4b3c7a3e8f51a5a248201e1eb091886 commit 203f2c14c4b3c7a3e8f51a5a248201e1eb091886 Author: Corvin Köhne AuthorDate: 2022-09-06 07:06:51 +0000 Commit: Emmanuel Vadot 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 "