From owner-dev-commits-src-all@freebsd.org Thu Jan 21 21:36:42 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 745CC4E026F; Thu, 21 Jan 2021 21:36:42 +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 4DMG1Q2qVDz3CxW; Thu, 21 Jan 2021 21:36:42 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 53B8C12E7E; Thu, 21 Jan 2021 21:36:42 +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 10LLag2P030552; Thu, 21 Jan 2021 21:36:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10LLag3F030551; Thu, 21 Jan 2021 21:36:42 GMT (envelope-from git) Date: Thu, 21 Jan 2021 21:36:42 GMT Message-Id: <202101212136.10LLag3F030551@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 5bdce6ff546e - main - Remove deadlock in rc caused by pwait waiting for itself. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5bdce6ff546e00673f9f515d2165d02901e858aa Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2021 21:36:42 -0000 The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=5bdce6ff546e00673f9f515d2165d02901e858aa commit 5bdce6ff546e00673f9f515d2165d02901e858aa Author: Alexander V. Chernikov AuthorDate: 2021-01-21 21:26:15 +0000 Commit: Alexander V. Chernikov CommitDate: 2021-01-21 21:36:37 +0000 Remove deadlock in rc caused by pwait waiting for itself. The following situation can trigger the deadlock: 1) Long time ago a_service was started through rc.d 2) We want to restart a_service and issue service a_service restart 3) rc.subr reads current process PID (via file or process), sends TERM signal and runs pwait with PID harvested 4) a_service process dies very quickly so it's PID becomes available. It is possible that while original process was running, PID counter overflowed and pwait got assigned a_service's PID. This patch ignores pid(s) to wait that are equal to pwait PID. Reported by: Dan McGregor, Boris Lytochkin Submitted by: Boris Lytochkin Reviewed By: 0mp MFC after: 2 weeks PR: 218598 Differential Revision: https://reviews.freebsd.org/D28240 --- bin/pwait/pwait.1 | 6 +++++- bin/pwait/pwait.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1 index 0452203eb4a1..b9b651bfc905 100644 --- a/bin/pwait/pwait.1 +++ b/bin/pwait/pwait.1 @@ -32,7 +32,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 5, 2020 +.Dd January 21, 2021 .Dt PWAIT 1 .Os .Sh NAME @@ -145,6 +145,10 @@ is not a substitute for the .Xr wait 1 builtin as it will not clean up any zombies or state in the parent process. +.Pp +To avoid deadlock, +.Nm +will ignore its own pid, if it is provided as a process id to wait for. .Sh HISTORY A .Nm diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c index f39922b48eb9..85cc6b994acf 100644 --- a/bin/pwait/pwait.c +++ b/bin/pwait/pwait.c @@ -146,6 +146,10 @@ main(int argc, char *argv[]) warnx("%s: bad process id", s); continue; } + if (pid == getpid()) { + warnx("%s: skiping my own pid", s); + continue; + } for (i = 0; i < nleft; i++) { if (e[i].ident == (uintptr_t)pid) { break;