teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0131-test-make-the-shutdown-routine-a-bit-more-robust.patch

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