From nobody Fri Aug 1 23:13:03 2025 X-Original-To: dev-commits-src-main@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 4bv1vh6zn1z63FxT; Fri, 01 Aug 2025 23:13:04 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bv1vg5wM7z3VTl; Fri, 01 Aug 2025 23:13:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754089983; 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=7tzxl7Fjl3kv8lc040N0d9GodXINIszgY/PjGdM0778=; b=JNN6l/PfX8EkYyINSBI+OTDuzCya8uc6BOUHpeETq04u+9m9aMAvji6mSeOX2xR9/Rz5XT ajM60sTJOLXjRUZk5iFRwOLU96aYn2OUMFR3z6xprfduyBQOp1+WcFGpRsWyMZCCCQgo2R +W+DrUCRfLXYr6hvOnXQqfso6TJfVquqjzxRqmYbk/E7AMhxHPhenvLhbQdubw2AUmTSuJ 7AsN0AV6tW6AIfXnphDXLXFcK6PIWRseGzKmk5gJk2xCalPxB2UYmy353viOx+U7f80sPa s1wGvBY1V8+Ap0DJrGoPYeMDWeoMIiJs4BI1QJInqtnjD0DKv63tO2AFbj2c1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754089983; 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=7tzxl7Fjl3kv8lc040N0d9GodXINIszgY/PjGdM0778=; b=PGKUoKxYmy2fnH+nv4KF5K0fWjCUeVNV7jVi8caLnd0Sm8Qt51LimtZLp/58ujCX9z9aio HkhECvdAmnOOU+OvoWby8Ls9vyk4N1dG0BG+KzHSKksYtJNqtSttscDwSQ9G1ughwlkoyI xVwAWiOVMmvMMDj8eSo7obVV/pcmSP+aGR91/o5gL+fxBJchrpgAnNaDTmauGqV+u2MLhF r7IAn2bLU8jAfRCZdfW1jGIOcdUi9tPwN4dwlzoqpj82T99XM0FEXUH40pge3NfeTSEAXa anxkQrnbzVutuYRoCxqnm1Xqy3wySyelKA+FfTO48qHqReKgJpcEmBn8JQghDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754089983; a=rsa-sha256; cv=none; b=dqnuLI9+VeMJZCzD3z7d5hzpx0Mmb429rGXpqX0Rpgz2kvWJC1sYk6z2X41dSfCjrqDZYi lBzzEWiESYgRWBbnu1Y2HWKvk6z03zhvrYMaP7VIYNvi6FUBszbJ1X24qrO7VZRzccvZng YE7IKrX981k0u/oTKEyhjN+Xd9UtFA0LQAXyJ6ykAW94P6uQoXNBhQUeoivppDVIRHDKMD J+qowmbdqIjvd4aR9yNAlRzHS8PAc4anaXQWZ+YBjXfPeY9iNO/KSfFUewm9AwMmYDHkPT 6DtqHn7x04LRv90u0Q+TvAhOmogBmWHS+kv16sHNSxK/1PDIZC4Qy48QKBQgvg== 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 4bv1vg5VFjz17D8; Fri, 01 Aug 2025 23:13:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 571ND3ph053561; Fri, 1 Aug 2025 23:13:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 571ND3Zb053558; Fri, 1 Aug 2025 23:13:03 GMT (envelope-from git) Date: Fri, 1 Aug 2025 23:13:03 GMT Message-Id: <202508012313.571ND3Zb053558@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 7f04c09fe745 - main - rc.subr: Fix wait_for_pids List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7f04c09fe74535c1646a4af120f8f1342fe1c328 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=7f04c09fe74535c1646a4af120f8f1342fe1c328 commit 7f04c09fe74535c1646a4af120f8f1342fe1c328 Author: Dag-Erling Smørgrav AuthorDate: 2025-08-01 23:11:40 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-08-01 23:11:57 +0000 rc.subr: Fix wait_for_pids It looks like this function was intended to loop and print an update whenever at least one of the waited-for processes terminates. However, the default behavior of pwait is to block until none of the watched processes exist. Use pwait -o instead so it only blocks until at least one process terminates, and add a test. Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Reviewed by: siderop1_netapp.com, kevans Differential Revision: https://reviews.freebsd.org/D51691 --- libexec/rc/rc.subr | 4 ++-- libexec/rc/tests/rc_subr_test.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index a2e2e98a5087..06b1bd51384c 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -800,7 +800,7 @@ wait_for_pids() fi _prefix= while true; do - _nlist=""; + _nlist="" for _j in $_list; do if kill -0 $_j 2>/dev/null; then _nlist="${_nlist}${_nlist:+ }$_j" @@ -813,7 +813,7 @@ wait_for_pids() _list=$_nlist echo -n ${_prefix:-"Waiting for PIDS: "}$_list _prefix=", " - pwait $_list 2>/dev/null + pwait -o $_list 2>/dev/null done if [ -n "$_prefix" ]; then echo "." diff --git a/libexec/rc/tests/rc_subr_test.sh b/libexec/rc/tests/rc_subr_test.sh index 9931389e7a02..e8398c8d9b12 100644 --- a/libexec/rc/tests/rc_subr_test.sh +++ b/libexec/rc/tests/rc_subr_test.sh @@ -1,5 +1,8 @@ +#- +# SPDX-License-Identifier: BSD-2-Clause # # Copyright 2022 Mateusz Piotrowski <0mp@FreeBSD.org> +# Copyright (c) 2025 Klara, Inc. # # SPDX-License-Identifier: BSD-2-Clause # @@ -104,8 +107,32 @@ oomprotect_yes_body() /bin/sh "$__script" "$__name" "$__pidfile" onestop } +atf_test_case wait_for_pids_progress +wait_for_pids_progress_head() +{ + atf_set "descr" "Verify that wait_for_pids prints progress updates" +} +wait_for_pids_progress_body() +{ + cat >>script <<'EOF' +. /etc/rc.subr +sleep 15 & +a=$! +sleep 10 & +b=$! +sleep 5 & +c=$! +wait_for_pids $a $b $c +EOF + re="^Waiting for PIDS: [0-9]+ [0-9]+ [0-9]+" + re="${re}, [0-9]+ [0-9]+" + re="${re}, [0-9]+\.$" + atf_check -s exit:0 -o match:"${re}" /bin/sh script +} + atf_init_test_cases() { atf_add_test_case oomprotect_all atf_add_test_case oomprotect_yes + atf_add_test_case wait_for_pids_progress }