From nobody Wed Mar 27 08:27:40 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 4V4KY90pMpz5GjBZ; Wed, 27 Mar 2024 08:27:41 +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 4V4KY86v8kz4FgV; Wed, 27 Mar 2024 08:27:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711528061; 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=EPxwrr7wlq4sWr2wlA3T1ks18drSxz/UkmPdGO4ta3M=; b=hvXZ+I/7xYcL546v8QvvntfqARqORk2uja9DljSiQ9nA9V/fXfuJBNqxcE/qhLvIkEYN+v xD5IL41+JBOdQrp7z1nTGx9f0hhMInDtSFlFQ5zev03i7I53mP5E/AFe2VgpM3qRkRWM2t 1owpsfyHgkZR5dT8gvQdVqsBShJCWpJt4qQk6kAyaWf+4lzxJ0Ty8Ku1Xh2pyp/1QbV3e0 PQlnhGG97yaHmI3cQSLQQBs8dTzptG/SQA4zYiEFwiYeoejnpl+Qj89oKkFdb9qAogr4yJ 3QPM6HpmrHxCHgjAhyzucfIDRWI3z9kKfUY5Thnmb3DDFO2uFDCN0B1kPq45Xg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711528061; a=rsa-sha256; cv=none; b=JNIhHto/lvIb7tsxZE+YZKqIvKIfMfjf01d6yXx6u98zApFP7OyWebLIblQpC6RsTd1X0p v3A1oa3+W/XnRniZ7eVe8SABnj27UB+Ub1v+ZB5w2MvKmdL9ScVPBZHbcpUuqa84yhtcRI 2nPnwssDea3miBMAnj1GZMqC0DqtnET0BQDnmcM+puIMZRE585Y0YMTCqgikoa8mngva8n slUV/Cp/x+4HfpIUPjMQFmbxJtr5R+UZqSdThHmPSOOVX+JFgxatMLfm5GQJUxJS5Bj+uj gx+PndluZlNkhT5dkL5gEr8xvHMGRhw7UtpQ40Ioy9djfLpuH1fa7lf/0tjcIw== 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=1711528061; 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=EPxwrr7wlq4sWr2wlA3T1ks18drSxz/UkmPdGO4ta3M=; b=iO9yagPqV+KMHAPKmVj9fi0dmcna2drLux53aq35pxPzACQ3lFPIKX8lGVXionXs0TdGZN 3a0s3+XiIBGjMu84yaSrcQ0iU4mVV1zvB1IuZTmr9hHVmM5bfKk9qBCQqY+8khLq/tzUDY GRYhUoKXdWSYhTUO9w4CPu0zkeraQFCqvGJIqYsBpxtPfDqWS+h3uWMFonXe16vz4zPfZ5 XRBWqm3i5YRyJL4pQYU7hY1BTgfXBIOK4moS/gUx+H8YflBmt44fZ6h7cECoMP+/YKWxl4 zdPw96/S1Ht6ZdcjbOcX7iZGjG9DI37eEZiw7sCe6c4go4W7AehVj1uFIGS/1Q== 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 4V4KY86W0Jzc3H; Wed, 27 Mar 2024 08:27:40 +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 42R8Re8Y096571; Wed, 27 Mar 2024 08:27:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42R8RerZ096568; Wed, 27 Mar 2024 08:27:40 GMT (envelope-from git) Date: Wed, 27 Mar 2024 08:27:40 GMT Message-Id: <202403270827.42R8RerZ096568@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: daefc4bda7c5 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: daefc4bda7c5a9728ec62eddcfd9af492531a7f8 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=daefc4bda7c5a9728ec62eddcfd9af492531a7f8 commit daefc4bda7c5a9728ec62eddcfd9af492531a7f8 Author: Konstantin Belousov AuthorDate: 2024-03-18 08:44:39 +0000 Commit: Konstantin Belousov CommitDate: 2024-03-27 08:27:23 +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;