chiark / gitweb /
bus: make PropertiesChanged emission work
[elogind.git] / src / libsystemd-bus / sd-bus.c
index 5135253e6bef9fe91d334732352bc75ac885ec61..11194af007609651fa0ffac1ba5614cd1051f305 100644 (file)
@@ -2499,6 +2499,7 @@ static int object_manager_serialize_vtable(
 static int object_manager_serialize_path(
                 sd_bus *bus,
                 sd_bus_message *reply,
+                const char *prefix,
                 const char *path,
                 bool require_fallback,
                 sd_bus_error *error) {
@@ -2509,10 +2510,11 @@ static int object_manager_serialize_path(
 
         assert(bus);
         assert(reply);
+        assert(prefix);
         assert(path);
         assert(error);
 
-        n = hashmap_get(bus->nodes, path);
+        n = hashmap_get(bus->nodes, prefix);
         if (!n)
                 return 0;
 
@@ -2566,7 +2568,7 @@ static int object_manager_serialize_path_and_fallbacks(
         assert(error);
 
         /* First, add all vtables registered for this path */
-        r = object_manager_serialize_path(bus, reply, path, false, error);
+        r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
         if (sd_bus_error_is_set(error))
@@ -2587,7 +2589,7 @@ static int object_manager_serialize_path_and_fallbacks(
 
                         *e = 0;
 
-                        r = object_manager_serialize_path(bus, reply, p, true, error);
+                        r = object_manager_serialize_path(bus, reply, p, path, true, error);
                         if (r < 0)
                                 return r;
 
@@ -2687,7 +2689,13 @@ static int process_get_managed_objects(
         return 1;
 }
 
-static int object_find_and_run(sd_bus *bus, sd_bus_message *m, const char *p, bool require_fallback, bool *found_object) {
+static int object_find_and_run(
+                sd_bus *bus,
+                sd_bus_message *m,
+                const char *p,
+                bool require_fallback,
+                bool *found_object) {
+
         struct node *n;
         struct vtable_member vtable_key, *v;
         int r;
@@ -3390,7 +3398,6 @@ int sd_bus_emit_signal(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3404,11 +3411,15 @@ int sd_bus_emit_signal(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send(bus, m, NULL);
 }
@@ -3424,7 +3435,6 @@ int sd_bus_call_method(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3439,11 +3449,15 @@ int sd_bus_call_method(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
 }
@@ -3454,7 +3468,6 @@ int sd_bus_reply_method_return(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3477,11 +3490,15 @@ int sd_bus_reply_method_return(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send(bus, m, NULL);
 }
@@ -3639,7 +3656,7 @@ static int add_object_vtable_internal(
                 sd_bus_object_find_t find,
                 void *userdata) {
 
-        struct node_vtable *c, *i;
+        struct node_vtable *c = NULL, *i;
         const sd_bus_vtable *v;
         struct node *n;
         int r;
@@ -3977,18 +3994,16 @@ static int emit_properties_changed_on_interface(
 
                 if (streq(c->interface, interface))
                         break;
-
-                r = node_vtable_get_userdata(bus, path, c, &u);
-                if (r < 0)
-                        return r;
-                if (r > 0)
-                        break;
         }
 
         if (!c)
                 return 0;
 
-        r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus", "PropertiesChanged", &m);
+        r = node_vtable_get_userdata(bus, path, c, &u);
+        if (r <= 0)
+                return r;
+
+        r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
         if (r < 0)
                 return r;
 
@@ -4025,7 +4040,7 @@ static int emit_properties_changed_on_interface(
                 if (r < 0)
                         return r;
 
-                r = sd_bus_message_append(m, "s", *n);
+                r = sd_bus_message_append(m, "s", *property);
                 if (r < 0)
                         return r;
 
@@ -4033,7 +4048,7 @@ static int emit_properties_changed_on_interface(
                 if (r < 0)
                         return r;
 
-                r = v->vtable->property.get(bus, m->path, interface, *property, m, &error, u);
+                r = v->vtable->property.get(bus, m->path, interface, *property, m, &error, vtable_property_convert_userdata(v->vtable, u));
                 if (r < 0)
                         return r;