chiark / gitweb /
sd-bus: add proper monitoring API
[elogind.git] / src / libsystemd / sd-bus / bus-control.c
index b4dbb5b7eeb2ab915b4a0e621d00245b17a4772e..bb6683efff6e0b7ee32d663202327d2391de02af 100644 (file)
@@ -237,11 +237,9 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
                         if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0)
                                 return -ENOMEM;
 
-                        r = strv_push(x, n);
-                        if (r < 0) {
-                                free(n);
-                                return -ENOMEM;
-                        }
+                        r = strv_consume(x, n);
+                        if (r < 0)
+                                return r;
 
                         previous_id = name->owner_id;
                 }
@@ -1100,13 +1098,22 @@ int bus_add_match_internal_kernel(
         return 0;
 }
 
+#define internal_match(bus, m)                                          \
+        ((bus)->hello_flags & KDBUS_HELLO_MONITOR                       \
+         ? (isempty(m) ? "eavesdrop='true'" : strappenda((m), ",eavesdrop='true'")) \
+         : (m))
+
 static int bus_add_match_internal_dbus1(
                 sd_bus *bus,
                 const char *match) {
 
+        const char *e;
+
         assert(bus);
         assert(match);
 
+        e = internal_match(bus, match);
+
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
@@ -1116,7 +1123,7 @@ static int bus_add_match_internal_dbus1(
                         NULL,
                         NULL,
                         "s",
-                        match);
+                        e);
 }
 
 int bus_add_match_internal(
@@ -1161,9 +1168,13 @@ static int bus_remove_match_internal_dbus1(
                 sd_bus *bus,
                 const char *match) {
 
+        const char *e;
+
         assert(bus);
         assert(match);
 
+        e = internal_match(bus, match);
+
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
@@ -1173,7 +1184,7 @@ static int bus_remove_match_internal_dbus1(
                         NULL,
                         NULL,
                         "s",
-                        match);
+                        e);
 }
 
 int bus_remove_match_internal(
@@ -1207,10 +1218,11 @@ _public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128
 
         r = sd_bus_message_new_method_call(
                         bus,
+                        &m,
                         name,
                         "/",
                         "org.freedesktop.DBus.Peer",
-                        "GetMachineId", &m);
+                        "GetMachineId");
         if (r < 0)
                 return r;