test: reap the watchdog's sleep in wdkill()

Every test left a stray `sleep 300` behind, reparented to PID 1, where
it lingered for up to five minutes after the test had finished.

wdstart() runs the watchdog in a subshell, so $! is the pid of the
subshell, not of the sleep it forks.  wdkill() killed the subshell and
orphaned the sleep.

Kill the child first, killing the subshell puts the sleep beyond the
reach of pkill -P.  Neither kill is sure to match, and wdkill() runs
from the EXIT trap under set -e, so both must tolerate failure.  Also
return early when wdpid is unset, for failures before wdstart() runs.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-07-30 15:21:24 +02:00
parent ad750a13c3
commit ee5038e7af
+5 -1
View File
@@ -255,8 +255,12 @@ wdstart()
wdkill()
{
[ -n "${wdpid:-}" ] || return 0
say "Stopping test watchdog, pid $wdpid"
kill -KILL $wdpid
# Reap the sleep first, killing its subshell orphans it to PID 1.
pkill -KILL -P "$wdpid" 2>/dev/null || true
kill -KILL "$wdpid" 2>/dev/null || true
}
teardown()