test: make TEST-07-PID1.issue-14566 more robust

The test slept a fixed 4s after starting the service, then read the
child PID from /leakedtestpid. On a loaded host the executor had not
exec'd the script yet:

[ 1571.079978] TEST-07-PID1.sh[17329]: + systemctl start issue14566-repro
[ 1571.079978] TEST-07-PID1.sh[17329]: + sleep 4
[ 1571.079978] TEST-07-PID1.sh[17329]: + systemctl status issue14566-repro
[ 1562.350438] systemd[1]: init.scope: Child 17296 belongs to init.scope.
[ 1571.081084] TEST-07-PID1.sh[17333]: ● issue14566-repro.service - Issue 14566 Repro
[ 1571.081084] TEST-07-PID1.sh[17333]:      Loaded: loaded (/usr/lib/systemd/tests/testdata/TEST-07-PID1.units/issue14566-repro.service; static)
[ 1571.081084] TEST-07-PID1.sh[17333]:     Drop-In: /usr/lib/systemd/system/service.d
[ 1571.081084] TEST-07-PID1.sh[17333]:              └─10-timeout-abort.conf
[ 1571.081084] TEST-07-PID1.sh[17333]:      Active: active (running) since Mon 2026-06-29 06:19:07 UTC; 4s ago
[ 1571.081084] TEST-07-PID1.sh[17333]:  Invocation: b3356aa5fff24eee85e302250ecb06b1
[ 1571.081084] TEST-07-PID1.sh[17333]:    Main PID: 17331 (9)
[ 1571.081084] TEST-07-PID1.sh[17333]:       Tasks: 1 (limit: 4468)
[ 1571.081084] TEST-07-PID1.sh[17333]:      Memory: 768K (peak: 768K)
[ 1571.081084] TEST-07-PID1.sh[17333]:         CPU: 1ms
[ 1571.081084] TEST-07-PID1.sh[17333]:      CGroup: /system.slice/issue14566-repro.service
[ 1571.081084] TEST-07-PID1.sh[17333]:              └─17331 systemd-executor --deserialize 66 --log-level debug,console:info --log-target journal
[ 1562.350492] systemd[1]: Child 17297 ((sd-close)) died (code=exited, status=0/SUCCESS)
[ 1571.082379] TEST-07-PID1.sh[17334]: ++ cat /leakedtestpid
[ 1571.082379] TEST-07-PID1.sh[17334]: cat: /leakedtestpid: No such file or directory

Make the service Type=notify and notify readiness after writing the PID
file, and wait for the service to go inactive in a timeout loop instead
of fixed sleeps.

Follow-up for c1566ef0d2

(cherry picked from commit e9482b9ebb)
This commit is contained in:
Luca Boccassi
2026-06-29 11:56:30 +01:00
parent 5323aefd49
commit 5827c35fd8
3 changed files with 4 additions and 2 deletions

View File

@@ -3,6 +3,8 @@
Description=Issue 14566 Repro
[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/lib/systemd/tests/testdata/TEST-07-PID1.units/%N.sh
ExecStopPost=true
KillMode=mixed

View File

@@ -3,4 +3,5 @@
sleep infinity &
echo $! >/leakedtestpid
systemd-notify --ready
wait $!

View File

@@ -14,13 +14,12 @@ if [[ -v ASAN_OPTIONS ]]; then
fi
systemctl start issue14566-repro
sleep 4
systemctl status issue14566-repro
leaked_pid=$(cat /leakedtestpid)
systemctl stop issue14566-repro
sleep 4
timeout 30 bash -c 'while systemctl is-active issue14566-repro; do sleep .5; done'
# Leaked PID will still be around if we're buggy.
# I personally prefer to see 42.