From 92d66625794057081046f051f7564e0789de0ace Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Jan 2015 20:42:14 +0100 Subject: [PATCH] busctl: exit cleanly when the bus connection is severed --- src/libsystemd/sd-bus/busctl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c index c9eeb91b0c0..c0d51e06a3b 100644 --- a/src/libsystemd/sd-bus/busctl.c +++ b/src/libsystemd/sd-bus/busctl.c @@ -1127,6 +1127,8 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL return log_error_errno(r, "Failed to add match: %m"); } + log_info("Monitoring bus message stream."); + for (;;) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; @@ -1136,6 +1138,12 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL if (m) { dump(m, stdout); + + if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected") > 0) { + log_info("Connection terminated, exiting."); + return 0; + } + continue; }