test: make the shutdown routine a bit more "robust"

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
```
This commit is contained in:
Frantisek Sumsal 2022-06-21 10:20:12 +02:00
parent 5309b56505
commit 56e8ee55d5

View file

@ -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