From 4ddf27c57bbaaa66bed5cfa951e60a83b9f64e29 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sun, 24 Dec 2023 12:53:53 +0100 Subject: [PATCH 1/2] test: flush the socket once the triggered unit exits Since the triggered unit intentionally fails without consuming any data from the socket, we'd try to trigger it again and again, and we might try to check the unit state in one of the "in-between" states, failing the test: [ 165.271698] H testsuite-07.sh[1032]: + systemctl start badbin_assert.socket [ 165.977637] H testsuite-07.sh[1032]: + socat - ABSTRACT-CONNECT:badbin_assert.socket [ 165.983787] H systemd[1]: Cannot find unit for notify message of PID 1039, ignoring. [ 166.817187] H testsuite-07.sh[1032]: + timeout 10 sh -c 'while systemctl is-active badbin_assert.service; do sleep .5; done' [ 167.049218] H testsuite-07.sh[1065]: active [ 167.146854] H systemd[1]: Listening on badbin_assert.socket. [ 167.163473] H systemd[1]: badbin_assert.socket: Incoming traffic [ 167.542626] H systemd[1]: Cannot find unit for notify message of PID 1065, ignoring. [ 167.543437] H (badbin)[1062]: badbin_assert.service: Failed to execute /tmp/badbin: Exec format error [ 167.548346] H systemd[1]: badbin_assert.service: Main process exited, code=exited, status=203/EXEC [ 167.549482] H systemd[1]: badbin_assert.service: Failed with result 'exit-code'. [ 167.561537] H systemd[1]: badbin_assert.socket: Incoming traffic [ 167.933390] H systemd[1]: Started badbin_assert.service. [ 167.950489] H (badbin)[1070]: badbin_assert.service: Failed to execute /tmp/badbin: Exec format error [ 167.956318] H systemd[1]: badbin_assert.service: Main process exited, code=exited, status=203/EXEC [ 167.957173] H systemd[1]: badbin_assert.service: Failed with result 'exit-code'. [ 167.974609] H systemd[1]: badbin_assert.socket: Incoming traffic [ 168.042838] H testsuite-07.sh[1072]: failed [ 168.094431] H testsuite-07.sh[1075]: ++ systemctl show -P ExecMainStatus badbin_assert.service [ 168.704022] H systemd[1]: Started badbin_assert.service. [ 168.778680] H (badbin)[1074]: badbin_assert.service: Failed to execute /tmp/badbin: Exec format error [ 168.826881] H systemd[1]: badbin_assert.service: Main process exited, code=exited, status=203/EXEC [ 168.833825] H systemd[1]: badbin_assert.service: Failed with result 'exit-code'. [ 168.923931] H testsuite-07.sh[1032]: + [[ 0 == 203 ]] [ 168.951492] H systemd[1]: Cannot find unit for notify message of PID 1075, ignoring. [ 168.999862] H testsuite-07.sh[615]: + echo 'Subtest /usr/lib/systemd/tests/testdata/units/testsuite-07.issue-30412.sh failed' [ 168.999862] H testsuite-07.sh[615]: Subtest /usr/lib/systemd/tests/testdata/units/testsuite-07.issue-30412.sh failed Follow-up for 1eeaa93de36 and 28a2d27650c. --- test/units/testsuite-07.issue-30412.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/units/testsuite-07.issue-30412.sh b/test/units/testsuite-07.issue-30412.sh index 61801c543a..c1cb00e071 100755 --- a/test/units/testsuite-07.issue-30412.sh +++ b/test/units/testsuite-07.issue-30412.sh @@ -20,6 +20,7 @@ EOF cat >/run/systemd/system/badbin_assert.socket < Date: Sun, 24 Dec 2023 14:49:23 +0100 Subject: [PATCH 2/2] busctl: avoid asserting on NULL message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid passing a NULL message to sd_bus_message_is_signal(), to not trip over an assertion: [ 132.869436] H testsuite-82.sh[614]: + systemctl --no-block --check-inhibitors=yes soft-reboot [ 132.967386] H systemd[1]: Created slice system-systemd\x2dcoredump.slice. [ 133.018292] H systemd[1]: Starting inhibit.service... [ 133.122610] H systemd[1]: Started systemd-coredump@0-665-0.service. [ 133.163643] H systemd[1]: Started inhibit.service. [ 133.206836] H testsuite-82.sh[614]: + exec sleep infinity [ 133.236762] H systemd-logind[611]: The system will reboot now! [ 135.891607] H systemd-coredump[667]: [🡕] Process 663 (busctl) of user 0 dumped core. Stack trace of thread 663: #0 0x00007f2ec45e6acf raise (libc.so.6 + 0x4eacf) #1 0x00007f2ec45b9ea5 abort (libc.so.6 + 0x21ea5) #2 0x00007f2ec4b5c9a6 log_assert_failed (libsystemd-shared-255.so + 0x1ff9a6) #3 0x00007f2ec4b5dca5 log_assert_failed_return (libsystemd-shared-255.so + 0x200ca5) #4 0x00007f2ec4bb3df6 sd_bus_message_is_signal (libsystemd-shared-255.so + 0x256df6) #5 0x000000000040e478 monitor (busctl + 0xe478) #6 0x000000000040e82f verb_monitor (busctl + 0xe82f) #7 0x00007f2ec4b202cb dispatch_verb (libsystemd-shared-255.so + 0x1c32cb) #8 0x00000000004074fa busctl_main (busctl + 0x74fa) #9 0x0000000000407525 run (busctl + 0x7525) #10 0x000000000040ff67 main (busctl + 0xff67) #11 0x00007f2ec45d2d85 __libc_start_main (libc.so.6 + 0x3ad85) #12 0x00000000004044be _start (busctl + 0x44be) ELF object binary architecture: AMD x86-64 [ 136.141152] H dbus-daemon[634]: [system] Monitoring connection :1.2 closed. [ 136.152233] H systemd[1]: busctl.service: Main process exited, code=dumped, status=6/ABRT [ 136.153996] H systemd[1]: busctl.service: Failed with result 'core-dump'. The asertion in question: Assertion 'm' failed at src/libsystemd/sd-bus/bus-message.c:1015, function sd_bus_message_is_signal(). Aborting. We can get a NULL message here through sd_bus_process() -> bus_process_internal() -> process_running(), so let's handle this case appropriately. --- src/busctl/busctl.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index d233fc55ad..b2c2bc644d 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -1320,24 +1320,24 @@ static int monitor(int argc, char **argv, int (*dump)(sd_bus_message *m, FILE *f if (r < 0) return log_error_errno(r, "Failed to process bus: %m"); - if (!is_monitor) { - const char *name; - - /* wait until we lose our unique name */ - if (sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameLost") <= 0) - continue; - - r = sd_bus_message_read(m, "s", &name); - if (r < 0) - return bus_log_parse_error(r); - - if (streq(name, unique_name)) - is_monitor = true; - - continue; - } - if (m) { + if (!is_monitor) { + const char *name; + + /* wait until we lose our unique name */ + if (sd_bus_message_is_signal(m, "org.freedesktop.DBus", "NameLost") <= 0) + continue; + + r = sd_bus_message_read(m, "s", &name); + if (r < 0) + return bus_log_parse_error(r); + + if (streq(name, unique_name)) + is_monitor = true; + + continue; + } + dump(m, stdout); fflush(stdout);