richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
594167
From a0464b064c46f9a63fd3f8d6f2d8560c7e5d32d3 Mon Sep 17 00:00:00 2001
594167
From: Frantisek Sumsal <frantisek@sumsal.cz>
594167
Date: Tue, 21 Jun 2022 10:20:12 +0200
594167
Subject: [PATCH] test: make the shutdown routine a bit more "robust"
594167
594167
Replace the call to the `end.service` with `systemctl poweroff`, since
594167
it seems to cause issues no matter what `--job-mode=` is used:
594167
594167
```
594167
[  129.070993] testsuite-21.sh[380]: ++ systemctl start --job-mode=flush end.service
594167
[  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).
594167
[  129.159636] testsuite-21.sh[912]: See system logs and 'systemctl status end.service' for details.
594167
```
594167
594167
Also, add a "safety net" which bypasses the manager and does the
594167
poweroff directly, since sometimes the D-Bus call performed by
594167
`systemctl` might timeout (as the manager might be still processing data
594167
from the fuzzing):
594167
594167
```
594167
[  115.776778] sh[894]: + systemctl poweroff --no-block
594167
[  166.164242] testsuite-21.sh[893]: Failed to start transient service unit: Connection timed out
594167
[  166.269289] sh[894]: Call to PowerOff failed: Connection timed out
594167
```
594167
594167
(cherry picked from commit 56e8ee55d58e38d47992ca6b5b6466fdb5be4781)
594167
594167
Related: #2087652
594167
---
594167
 test/units/testsuite-21.sh | 8 ++++++--
594167
 1 file changed, 6 insertions(+), 2 deletions(-)
594167
594167
diff --git a/test/units/testsuite-21.sh b/test/units/testsuite-21.sh
594167
index 053d571a90..e9bf18603a 100755
594167
--- a/test/units/testsuite-21.sh
594167
+++ b/test/units/testsuite-21.sh
594167
@@ -9,11 +9,15 @@ systemctl list-jobs | grep -F 'end.service' && SHUTDOWN_AT_EXIT=1 || SHUTDOWN_AT
594167
 
594167
 at_exit() {
594167
     set +e
594167
-    # We have to call the end.service explicitly even if it's specified on
594167
+    # We have to call the end.service/poweroff explicitly even if it's specified on
594167
     # the kernel cmdline via systemd.wants=end.service, since dfuzzer calls
594167
     # org.freedesktop.systemd1.Manager.ClearJobs() which drops the service
594167
     # from the queue
594167
-    [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && systemctl start --job-mode=flush end.service
594167
+    if [[ $SHUTDOWN_AT_EXIT -ne 0 ]] && ! systemctl poweroff; then
594167
+        # PID1 is down let's try to save the journal
594167
+        journalctl --sync || : # journal can be down as well so let's ignore exit codes here
594167
+        systemctl -ff poweroff # sync() and reboot(RB_POWER_OFF)
594167
+    fi
594167
 }
594167
 
594167
 trap at_exit EXIT