]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: ignore EC from the second `systemctl status -a` as well
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 10 Nov 2025 18:26:43 +0000 (19:26 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 10 Nov 2025 21:31:09 +0000 (21:31 +0000)
There is a TOCTOU in the `systemctl status` where a unit might change
its state during the initial ListUnitsByPatterns call and the subsequent
individual GetAll calls, which then makes the systemctl call fail even
if the unit that was originally pulled in was active/running:

[ 1922.040463] TEST-26-SYSTEMCTL.sh[117]: + systemctl status -a --state active,running,plugged
[ 1922.051423] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=ListUnitsByPatterns  cookie=1 reply_cookie=0 signature=asas error-name=n/a error-message=n/a
[ 1922.052501] systemd[1]: Sent message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 signature=a(ssssssouso) error-name=n/a error-message=n/a
[ 1922.052650] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1/unit/_2d_2emount interface=org.freedesktop.DBus.Properties member=GetAll  cookie=2 reply_cookie=0 signature=s error-name=n/a error-message=n/a
...
[ 1922.222061] systemd-hostnamed[424]: Idle for 30s, exiting.
...
[ 1922.224961] systemd[1]: systemd-hostnamed.service: Got notification message from PID 424: STOPPING=1, STATUS=Shutting down...
[ 1922.224983] systemd[1]: systemd-hostnamed.service: Changed running ->stop-sigterm
...
[ 1922.228984] systemd[1]: Got message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1/unit/systemd_2dhostnamed_2eservice interface=org.freedesktop.DBus.Properties member=GetAll  cookie=41 reply_cookie=0 signature=s error-name=n/a error-message=n/a
[ 1922.234402] systemd[1]: Sent message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=43 reply_cookie=41 signature=a{sv} error-name=n/a error-message=n/a

Since in this case we care mostly about the code paths the command
triggers, ignore its exit code as we do for the previous one.

Resolves: #39612

test/units/TEST-26-SYSTEMCTL.sh

index 0bfffa54350597787e3c99f468eb269a8a0f0f53..4a2f4eabce8ab95f3ad614aeb300c10ba6c53664 100755 (executable)
@@ -359,7 +359,10 @@ systemctl show systemd-logind.service
 systemctl status
 # Ignore the exit code in this case, as it might try to load non-existing units
 systemctl status -a >/dev/null || :
-systemctl status -a --state active,running,plugged >/dev/null
+# Ditto - there is a window between the first ListUnitsByByPatterns and the querying of individual units in
+# which some units might change their state (e.g. running -> stop-sigterm), which then causes systemctl to
+# return EC > 0
+systemctl status -a --state active,running,plugged >/dev/null || :
 systemctl status "systemd-*.timer"
 systemctl status "systemd-journald*.socket"
 systemctl status "sys-devices-*-ttyS0.device"