From 7ec22d7d4b9694462d2c6f98eaccc887f42f9b94 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 21 Nov 2023 15:55:08 +0100 Subject: [PATCH] bsod: install the signal handler only just before we need it Otherwise we might get stuck in sd_journal_wait(), since it handles EINTR internally. Resolves: #30084 --- src/journal/bsod.c | 3 ++- test/units/testsuite-04.bsod.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/journal/bsod.c b/src/journal/bsod.c index 516a47c7195..a88cb66b81d 100644 --- a/src/journal/bsod.c +++ b/src/journal/bsod.c @@ -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"); diff --git a/test/units/testsuite-04.bsod.sh b/test/units/testsuite-04.bsod.sh index 774707d476b..8f5ff5f35c8 100755 --- a/test/units/testsuite-04.bsod.sh +++ b/test/units/testsuite-04.bsod.sh @@ -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' -- 2.47.3