From nobody Tue Dec 06 14:42:17 2022 X-Original-To: dev-commits-src-all@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 4NRNRZ1j1bz4jq2j; Tue, 6 Dec 2022 14:42:18 +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 4NRNRZ1Cwwz3rGq; Tue, 6 Dec 2022 14:42:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670337738; 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=pXSegUcS/5+Vhq5JHynCXGRbmVRIQ+QALKjELMJHUnA=; b=FTsD7fwhjEzxxoK/u5flC2uaW9sztpQLD7JWypaQ89mXwXfpVt8ql4xWT1gu7fJp10dnaY DKQja4x7wu+o0TxVDgZVfyNSB3wk7rdblevhdliffO0ek/lnS9EuxlJT4IoZxk+ktmkLKm nDeSLg3UnR4WEt3tWJuuYmFFQLRWnO/YQx1eQQDe2GbXVoCZCGySJK384uU/8yE7xhmH9r C0gIkZB2NaLOV5dUk904+foaRxMBtKTBdP3/VA15zmqf/k7t0NSuoQdSroAM9/rXdXx9OU CMDbcxoVxFX7BKZLYJRKvaqu0UcbFQkasZoh4jsooEr/xvXyfHepsORTQGU1Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670337738; 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=pXSegUcS/5+Vhq5JHynCXGRbmVRIQ+QALKjELMJHUnA=; b=O9eu77XsSANqo53/eqeVafSvXYpTznelMwipJyXbOeh/u5+9zTqGK48fuDssPnkQzkV9HK GaoE5xZ8o8fCGmqJCT0rFZ/X0PXx9JOla20GlUwEjN5da/R3ciGre282YnWWRpYf4sZvfk dEswyoU522xpgZYR93iitUwBbWU4IPFlgbY3ACciDUmk5LvECZtX8L+F7x2M7p73CiCNB4 gyTB/mEyVS73SFs38p0pnzmA9NUMu3gimKh5K5zQ3vWDtp2qr44nMM8d+uHT3EcXEBHJuI OubfCTICzNt5xDWMA8O/oJY/byeQjtsvBYS9SbJLSYl1jwIyriqbQWWDkmXd9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670337738; a=rsa-sha256; cv=none; b=RwkNN6LBX48T6Az7Lc30zuuOSVr2GUKTh6gyngx6oMczTl7MyuyEP9sBoCMYCd8T641WnY rabjuIclFgCYwbEgnXvjcre02O2Iy0wTrh9N3s8Ymo9Jz3dIxFR+3K9NCbtWUP+AavWalM tTp1pwisG5Vhpmp00hP0my9x2mA7IVXvOOK62LlFXW8NOBkFOemfxrUzTn+gRlrnPsZL+X dF4LZy8/ZfULAyFbUPeS9m5G1l/ZAvn/RaG3YVxeFeFWsBjdsPwm4r+8ScJ79Yd41ahW3C q3iURfCTJyXl6jaA1TwqueY/s/FaERp7B0N/9CZHwuzTXvWdiw9AmQ1MMln/Iw== 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 4NRNRZ0GgDzh6j; Tue, 6 Dec 2022 14:42:18 +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 2B6EgHfd033185; Tue, 6 Dec 2022 14:42:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B6EgHid033184; Tue, 6 Dec 2022 14:42:17 GMT (envelope-from git) Date: Tue, 6 Dec 2022 14:42:17 GMT Message-Id: <202212061442.2B6EgHid033184@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 810fe03349df - stable/13 - init: fix shutdown race List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 810fe03349df4d4deb3eb59baa76075f2d3f5514 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=810fe03349df4d4deb3eb59baa76075f2d3f5514 commit 810fe03349df4d4deb3eb59baa76075f2d3f5514 Author: Corvin Köhne AuthorDate: 2022-09-06 07:06:51 +0000 Commit: Corvin Köhne CommitDate: 2022-12-06 14:41:34 +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 (cherry picked from commit 203f2c14c4b3c7a3e8f51a5a248201e1eb091886) --- 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 230c141bd351..3e53da6b99a7 100644 --- a/sbin/init/init.c +++ b/sbin/init/init.c @@ -1138,10 +1138,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 "