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
This commit is contained in:
+2
-2
@@ -800,7 +800,7 @@ wait_for_pids()
|
|||||||
fi
|
fi
|
||||||
_prefix=
|
_prefix=
|
||||||
while true; do
|
while true; do
|
||||||
_nlist="";
|
_nlist=""
|
||||||
for _j in $_list; do
|
for _j in $_list; do
|
||||||
if kill -0 $_j 2>/dev/null; then
|
if kill -0 $_j 2>/dev/null; then
|
||||||
_nlist="${_nlist}${_nlist:+ }$_j"
|
_nlist="${_nlist}${_nlist:+ }$_j"
|
||||||
@@ -813,7 +813,7 @@ wait_for_pids()
|
|||||||
_list=$_nlist
|
_list=$_nlist
|
||||||
echo -n ${_prefix:-"Waiting for PIDS: "}$_list
|
echo -n ${_prefix:-"Waiting for PIDS: "}$_list
|
||||||
_prefix=", "
|
_prefix=", "
|
||||||
pwait $_list 2>/dev/null
|
pwait -o $_list 2>/dev/null
|
||||||
done
|
done
|
||||||
if [ -n "$_prefix" ]; then
|
if [ -n "$_prefix" ]; then
|
||||||
echo "."
|
echo "."
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
#-
|
||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
#
|
#
|
||||||
# Copyright 2022 Mateusz Piotrowski <0mp@FreeBSD.org>
|
# Copyright 2022 Mateusz Piotrowski <0mp@FreeBSD.org>
|
||||||
|
# Copyright (c) 2025 Klara, Inc.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: BSD-2-Clause
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
#
|
#
|
||||||
@@ -104,8 +107,32 @@ oomprotect_yes_body()
|
|||||||
/bin/sh "$__script" "$__name" "$__pidfile" onestop
|
/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_init_test_cases()
|
||||||
{
|
{
|
||||||
atf_add_test_case oomprotect_all
|
atf_add_test_case oomprotect_all
|
||||||
atf_add_test_case oomprotect_yes
|
atf_add_test_case oomprotect_yes
|
||||||
|
atf_add_test_case wait_for_pids_progress
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user