From 7bd41e63f7c875088b11eac3291f43c7c025869b Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 15 Feb 2024 21:13:07 +0100 Subject: [PATCH] test: properly preserve journal from sd-bsod tests I (incorrectly) assumed that --relinquish-var does everything --flush does, including moving already existing stuff from /var/log/journal/ to /run/log/journal/, but that's not the case. To actually do that we need to shuffle things manually, so let's do just that. This should make issues like #31334 easier to debug, since with this patch we now have a coredump in the test journal as well: ~# make -C test/TEST-04-JOURNAL/ clean setup run TEST_MATCH_SUBTEST=bsod BUILD_DIR=$PWD/build TEST_NO_NSPAWN=1 ... [ 12.176089] testsuite-04.sh[712]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-04.bsod.sh failed' [ 12.176089] testsuite-04.sh[712]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-04.bsod.sh failed [ 12.176089] testsuite-04.sh[712]: + return 1 [ 12.177347] systemd[1]: testsuite-04.service: Failed with result 'exit-code'. [ 12.220580] systemd[1]: Failed to start testsuite-04.service. Spawning getter /home/mrc0mmand/repos/@systemd/systemd/build/journalctl -o export -D /var/tmp/systemd-tests/systemd-test.Qtqmmr/root/var/log/journal... Finishing after writing 7649 entries TEST-04-JOURNAL: (failed; see logs) -rw-r----- 1 root root 16777216 Feb 15 21:13 /var/tmp/systemd-tests/systemd-test.Qtqmmr/system.journal ... ~# coredumpctl --file /var/tmp/systemd-tests/systemd-test.Qtqmmr/system.journal TIME PID UID GID SIG COREFILE EXE SIZE Thu 2024-02-15 21:13:38 CET 812 0 0 SIGABRT journal /usr/lib/systemd/systemd-bsod - --- test/units/testsuite-04.bsod.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/units/testsuite-04.bsod.sh b/test/units/testsuite-04.bsod.sh index 30f0cb0bd4..36092fe821 100755 --- a/test/units/testsuite-04.bsod.sh +++ b/test/units/testsuite-04.bsod.sh @@ -17,8 +17,22 @@ at_exit() { fi if mountpoint -q /var/log/journal; then + # In order to preserve the journal from the just run test we need to do a little dance, as + # --relinquish-var is not a "true" opposite of --flush, meaning that it won't move the existing + # journal(s) from /var/log/ to /run/log/. To do that, let's rotate the journal first, so all + # important bits are in the archived journal(s)... + journalctl --rotate + # ...then instruct sd-journald to write further entries to the runtime journal... journalctl --relinquish-var + # ...make sure there are no outstanding writes to the persistent journal that might block us from + # unmounting the tmpfs... + journalctl --sync + # ...move the archived journals to the runtime storage... + mv -v "/var/log/journal/$(