]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bsod: install the signal handler only just before we need it
authorFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 21 Nov 2023 14:55:08 +0000 (15:55 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 21 Nov 2023 16:58:33 +0000 (16:58 +0000)
Otherwise we might get stuck in sd_journal_wait(), since it handles
EINTR internally.

Resolves: #30084

src/journal/bsod.c
test/units/testsuite-04.bsod.sh

index 516a47c7195724751557062577319e92de08e788..a88cb66b81de05ce6862df2e43ba2967a91e83d3 100644 (file)
@@ -285,7 +285,6 @@ static int run(int argc, char *argv[]) {
         log_parse_environment();
 
         sigbus_install();
-        assert_se(sigaction_many(&nop_sigaction, SIGTERM, SIGINT) >= 0);
 
         r = parse_argv(argc, argv);
         if (r <= 0)
@@ -300,6 +299,8 @@ static int run(int argc, char *argv[]) {
                 return 0;
         }
 
+        assert_se(sigaction_many(&nop_sigaction, SIGTERM, SIGINT) >= 0);
+
         r = display_emergency_message_fullscreen((const char*) message);
         if (r < 0)
                 return log_error_errno(r, "Failed to display emergency message on terminal: %m");
index 774707d476b6953145d077f1a95801b1adb6b546..8f5ff5f35c8b864fbf7375af6cddc24b3e9ce13e 100755 (executable)
@@ -88,3 +88,16 @@ systemctl daemon-reload
 systemctl start systemd-bsod
 systemd-cat -p emerg echo "Service emergency message"
 vcs_dump_and_check "Service emergency message"
+systemctl stop systemd-bsod
+
+# Wipe the journal
+journalctl --vacuum-size=1 --rotate
+(! journalctl -q -b -p emerg --grep .)
+
+# Same as above, but make sure the service responds to signals even when there are
+# no "emerg" messages, see systemd/systemd#30084
+(! systemctl is-active systemd-bsod)
+systemctl start systemd-bsod
+timeout 5s bash -xec 'until systemctl is-active systemd-bsod; do sleep .5; done'
+timeout 5s systemctl stop systemd-bsod
+timeout 5s bash -xec 'while systemctl is-active systemd-bsod; do sleep .5; done'