git: 934fde21fa2b - stable/14 - rc.subr: Fix premature return from wait_for_pids

Dag-Erling Smørgrav <[email protected]> Mon, 03 Aug 2026 11:38:48 +0000
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a707dc8.1bdc7.424d02cc__42382.9642751784$1785757259$gmane$org@gitrepo.freebsd.org>
The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=934fde21fa2b84298cde99649d28454caceebf93

commit 934fde21fa2b84298cde99649d28454caceebf93
Author:     Dag-Erling Smørgrav <[email protected]>
AuthorDate: 2026-07-27 10:15:47 +0000
Commit:     Dag-Erling Smørgrav <[email protected]>
CommitDate: 2026-08-03 11:32:14 +0000

    rc.subr: Fix premature return from wait_for_pids
    
    Use pwait's new -r option to wait until the target processes have not
    only terminated, but also been reaped.
    
    PR:             293183
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D58391
    
    (cherry picked from commit 356d0b79cf6fc693ed1a5564232e240ce15ccb8a)
---
 UPDATING                         | 12 ++++++++++++
 libexec/rc/rc.subr               |  4 ++--
 libexec/rc/tests/rc_subr_test.sh | 20 ++++++--------------
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/UPDATING b/UPDATING
index 4c3ea27970cb..eb1d65b8f455 100644
--- a/UPDATING
+++ b/UPDATING
@@ -12,6 +12,18 @@ Items affecting the ports and packages system can be found in
 /usr/ports/UPDATING.  Please read that file before updating system packages
 and/or ports.
 
+20260722:
+	The wait_for_pids() function in rc.subr, used by rc scripts
+	when stopping or restarting a service, has been modified to
+	use pwait(1)'s new -r option, which requires kernel support.
+	When upgrading across this change, you should install a new
+	kernel first, then reboot, then install a new world, run
+	etcupdate, and reboot again.  Otherwise, you may find that
+	rc.subr is unable to stop services because the running kernel
+	does not provide the support that the updated pwait(1) needs.
+	Alternatively, if you deem it safe, you may use fastboot(8) to
+	reboot without shutting down services first.
+
 20260116:
 	Bump __FreeBSD_version to 1403508 for various LinuxKPI changes
 	so they could be detected if needed.
diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr
index 2cc664cf473d..669fd0107181 100644
--- a/libexec/rc/rc.subr
+++ b/libexec/rc/rc.subr
@@ -634,7 +634,7 @@ sort_lite()
 #
 wait_for_pids()
 {
-	local _list _prefix _j
+	local _list= _prefix= _j=
 
 	for _j in "$@"; do
 		if kill -0 $_j 2>/dev/null; then
@@ -645,7 +645,7 @@ wait_for_pids()
 	while [ -n "$_list" ]; do
 		echo -n ${_prefix:-"Waiting for PIDS: "}$_list
 		_prefix=", "
-		_list=$(pwait -op $_list 2>/dev/null)
+		_list=$(pwait -opr $_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 d453338a7ea3..44ad9bf43fd5 100644
--- a/libexec/rc/tests/rc_subr_test.sh
+++ b/libexec/rc/tests/rc_subr_test.sh
@@ -125,20 +125,12 @@ wait_for_pids_progress_head()
 }
 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
+	a=$(sleep 4 >/dev/null & echo $!)
+	b=$(sleep 3 >/dev/null & echo $!)
+	c=$(sleep 2 >/dev/null & echo $!)
+	atf_check \
+	    -o inline:"Waiting for PIDS: $a $b $c, $a $b, $a.\n" \
+	    /bin/sh -c ". /etc/rc.subr; wait_for_pids $a $b $c"
 }
 
 atf_init_test_cases()