From nobody Wed Mar 27 08:28:13 2024 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 4V4KYn5c7tz5Gj6Y; Wed, 27 Mar 2024 08:28:13 +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 4V4KYn2yHYz4GfV; Wed, 27 Mar 2024 08:28:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711528093; 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=KllbveJeUr54WlLagTpVO0aFLWUfumTMeFj/NLgX/r0=; b=vwpztTQ2oVn+09xhFqbUjamA7W++FGeRedrpAvUOC1ZpeT6XjixBh69XGdj6F4zYcjPZ7h QdYtZZPZbBRTYGND2wabsDyZlnZLi8tgvazxYEImZaAyUcXUkOqtycl5t44TKDqHFEaUcI kTYKag2VeZWjwNNgIRL+zhAXMzOhir1q4h/EIgIhNzrY8qbeLKS4U4eWAt8SWyE1qFHj6N l9REv4v1K4Rj4Xa1ipi6JRZfv0OquJUGbXVpbvrFPp6+VBIwJE+vtGOvhsXL2q34xMc3QI e1qzYIDYG2n5lCfXp4AiQdJrnL2tIX8AOmZFoXqKbJr/olQ8JPnCtbveMb5WTg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711528093; a=rsa-sha256; cv=none; b=Nwqap4/wMn5W4Pql4kwW4Kn8d8EwB8mPytI+f60yBLnyLsJsx9tlqjMbFPc67GkIMZ+WVF VfPeK+A6VT8DjLqj+AGvHn41mzIXx/+bgJWEU4HzgXMSNcTwk16R4TAr8IBrPGEMEv8hci tMVF/l6bBwoU2wHAurAM77+t/L9lFGHOzd+961wuCqVZBT/oRFnZnPC4Tmk9LaWQPPPZcf DiaA/OPNhex77/wrY1Y38yn629/NFeYULM/e8j+1h1e66Y8vZNIVatkOAfsT4qKaLtbqLu hMG88MxyNzK1mfRaYuC7E5WU+lMXko2Gkl4qCVWX45XRec5HynAyiEKKOek0hg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711528093; 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=KllbveJeUr54WlLagTpVO0aFLWUfumTMeFj/NLgX/r0=; b=kNYFcQ7XKdxHamUDU8FEPJ+PMixHsFMKxO4XawSrkQzFnSu2GrqEB/MY3ZTS5+rThu+66i 0oLmZWEbFMTKUmww9NguadB7azeqR2ZWeQON19rTthLeRTJ/FDZkrbCdgitPBp/mMvqPlA NaY1epqSZZd0Jd6dT3s0nxsf/0gJ8miSnaPoVNfCcrUBQtCXVMx3hPjKCuvwUCkP3hCqOv 3Wa1SpxsWWQlUhQsgzNJnFqyWSFfjRAeOVDTfvcQPUL4rvNgu1CFkp3hhHU/WPptPHEZa2 X6ZMRsxQhCFPDp/CoLjYFnbz9WqymL63IhwYZBsA4jUVlaxTAHZYB7/YgkhVqg== 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 4V4KYn2YfKzcFb; Wed, 27 Mar 2024 08:28:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42R8SDNi096876; Wed, 27 Mar 2024 08:28:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42R8SDdN096873; Wed, 27 Mar 2024 08:28:13 GMT (envelope-from git) Date: Wed, 27 Mar 2024 08:28:13 GMT Message-Id: <202403270828.42R8SDdN096873@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 1d2a587ef9f8 - stable/13 - daemon(8): handle case of waitpid() returning without exited child 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1d2a587ef9f8310da6a9203bd1fff43d61ca66f7 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1d2a587ef9f8310da6a9203bd1fff43d61ca66f7 commit 1d2a587ef9f8310da6a9203bd1fff43d61ca66f7 Author: Konstantin Belousov AuthorDate: 2024-03-18 08:44:39 +0000 Commit: Konstantin Belousov CommitDate: 2024-03-27 08:27:52 +0000 daemon(8): handle case of waitpid() returning without exited child PR: 277764 (cherry picked from commit 8eaa6be80d6aef6a118fa854a860bfdaeb7ed753) --- usr.sbin/daemon/daemon.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index 65e6bb7ca190..da8e4895e19b 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -743,18 +743,22 @@ daemon_terminate(struct daemon_state *state) } /* - * Returns true if SIGCHILD came from state->pid - * This function could hang if SIGCHILD was emittied for a reason other than - * child dying (e.g., ptrace attach). + * Returns true if SIGCHILD came from state->pid due to its exit. */ static bool daemon_is_child_dead(struct daemon_state *state) { + int status; + for (;;) { - int who = waitpid(-1, NULL, WNOHANG); - if (state->pid == who) { + int who = waitpid(-1, &status, WNOHANG); + if (state->pid == who && (WIFEXITED(status) || + WIFSIGNALED(status))) { return true; } + if (who == 0) { + return false; + } if (who == -1 && errno != EINTR) { warn("waitpid"); return false;