From nobody Wed Mar 20 01:07: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 4Tzr695yW6z5FxrC; Wed, 20 Mar 2024 01:07: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 4Tzr695640z4YFg; Wed, 20 Mar 2024 01:07:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710896833; 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=IhaPRIqaK/Lb8ERg98M91LwQKvB4MY01bqBSCIhD9vE=; b=JII4QGfiTXiDVWW+zL5D+OaUZ7Xtjy1cPGwLGPhU5qt9Oivt63ikrECnUPgH0vsb6PVtkH lLcQ6fZAyfqSVw7lJ6lBwmV3Z1C/EV+5V+CM8Hqbjv5OWq4nP7LDbSKqW3wy71x2/KzHe3 fbh1IB9iaLXF6TAAe5N85j/OjcsuzzYjTk5YKBkcTgJtY1ZWyLZslDDGt2c0oIEEfitNJc JjGlElBZUhdteUAntU1T0GH1rTFsSCsMgIGEeUZ5LthrRA7mQq34h9NYByG0tjVd8wn+Sh f32dS6DI5J+yc7aEQ2yJP4zxQlvyMV/h7yOcPolMv5jJf7SwftOWDml3IhlBKw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710896833; a=rsa-sha256; cv=none; b=JaXX2CT+71fTbN78CZZ4Q4S9Efv0qB4VKQBBHB1znE+N5zh77kXtE6InwpQlCQwwRV7eGN arP22qRgi1fgzT7EDgEF6EojDemI2dXaxTxGQzIeMbYAQW5zNnjbIFuFq9bLmXD/S7nKYw ZcaRNTunYvp6ge9nOOTkY4B7HA7QqLclKAkjmUInuezKcRi7RpJKLN0gQuqjE9nAgw2hsK SZLMZWODHEoG1JqG0v1fUAi+6OfXXUUd8zwR4vHq71gi4FcvHX6FtzWzT1EBOJ8khLILT3 5ImUrwhB1ZPMzZO9o3Zakl+v/LAMfIghfG5oYd5mAmmtBgpnWAw8XWCVrd/Kjg== 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=1710896833; 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=IhaPRIqaK/Lb8ERg98M91LwQKvB4MY01bqBSCIhD9vE=; b=A1iqV5+jFg7FKpQ5z4ct6QY42zV8UlQeAsInHHNIVBObBlxzf9Okh1mEYWB6LiAi+2rHn1 as27bsmVxel9rtuD9F1mue/CT4aiYzkLmhsXNA/T6kG6+5dNQbOQxpNjKfcbBK6AfC2aaK ry1OZGzuGCDIYNfdTPhlUTh3ENP9Oais+oPf5Q3WniUzm9BpfWnsOeKH1ZlFoHJ+gOeukk xPuX1QUlJFmOR9rMsJQ2O9nval31jT4vszWaihmwvJAUxjkRDJwOWpRHiqYbUPYyT0w6R4 8xTclkly0QIo0aQIEzp/H0S/b5jFsIVBcbASrNPJF9vYBXTsAs1RpGJaoTYnYw== 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 4Tzr694jn8zVJN; Wed, 20 Mar 2024 01:07: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 42K17D65066542; Wed, 20 Mar 2024 01:07:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42K17DBr066539; Wed, 20 Mar 2024 01:07:13 GMT (envelope-from git) Date: Wed, 20 Mar 2024 01:07:13 GMT Message-Id: <202403200107.42K17DBr066539@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 8eaa6be80d6a - main - 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/main X-Git-Reftype: branch X-Git-Commit: 8eaa6be80d6aef6a118fa854a860bfdaeb7ed753 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=8eaa6be80d6aef6a118fa854a860bfdaeb7ed753 commit 8eaa6be80d6aef6a118fa854a860bfdaeb7ed753 Author: Konstantin Belousov AuthorDate: 2024-03-18 08:44:39 +0000 Commit: Konstantin Belousov CommitDate: 2024-03-20 01:07:00 +0000 daemon(8): handle case of waitpid() returning without exited child Not checking for either WIFEXITED(status) or zero result results in never finishing the loop. PR: 277764 Reviewed by: kevans (previous version) Discussed with: Daniel Tameling Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44401 --- 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 6cde194cf16e..bce215af75d1 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -755,18 +755,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;