]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: make the shutdown routine a bit more "robust"
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 21 Jun 2022 08:20:12 +0000 (10:20 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 21 Jun 2022 10:11:43 +0000 (12:11 +0200)
Replace the call to the `end.service` with `systemctl poweroff`, since
it seems to cause issues no matter what `--job-mode=` is used:

```
[  129.070993] testsuite-21.sh[380]: ++ systemctl start --job-mode=flush end.service
[  129.154985] testsuite-21.sh[912]: Failed to start end.service: Transaction for end.service/start is destructive (sysinit.target has 'stop' job queued, but 'start' is included in transaction).
[  129.159636] testsuite-21.sh[912]: See system logs and 'systemctl status end.service' for details.
```

Also, add a "safety net" which bypasses the manager and does the
poweroff directly, since sometimes the D-Bus call performed by
`systemctl` might timeout (as the manager might be still processing data
from the fuzzing):

```
[  115.776778] sh[894]: + systemctl poweroff --no-block
[  166.164242] testsuite-21.sh[893]: Failed to start transient service unit: Connection timed out
[  166.269289] sh[894]: Call to PowerOff failed: Connection timed out
```

test/units/testsuite-21.sh

index 053d571a90f1f5e52307c7ba662540cdda6a2e98..e9bf18603a24c17c491f081af2226ba413c02078 100755 (executable)
@@ -9,11 +9,15 @@ systemctl list-jobs | grep -F 'end.service' && SHUTDOWN_AT_EXIT=1 || SHUTDOWN_AT
 
 at_exit() {
     set +e
-    # We have to call the end.service explicitly even if it's specified on
+    # We have to call the end.service/poweroff explicitly even if it's specified on
     # the kernel cmdline via systemd.wants=end.service, since dfuzzer calls
     # org.freedesktop.systemd1.Manager.ClearJobs() which drops the service
     # from the queue
-    [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && systemctl start --job-mode=flush end.service
+    if [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && ! systemctl poweroff; then
+        # PID1 is down let's try to save the journal
+        journalctl --sync || : # journal can be down as well so let's ignore exit codes here
+        systemctl -ff poweroff # sync() and reboot(RB_POWER_OFF)
+    fi
 }
 
 trap at_exit EXIT