chiark / gitweb /
bus: don't fail if GetAll() is used to get properties of the built-in interfaces
[elogind.git] / src / libsystemd-bus / bus-objects.c
index 0c935e947d89e9e44b36c53676bd72778a474f0c..aa0be37a9de8061d918e9bbb258c651cd0d252f2 100644 (file)
@@ -313,7 +313,7 @@ static int invoke_property_get(
                 void *userdata) {
 
         int r;
-        void *p;
+        const void *p;
 
         assert(bus);
         assert(v);
@@ -333,9 +333,13 @@ static int invoke_property_get(
         switch (v->x.property.signature[0]) {
 
         case SD_BUS_TYPE_STRING:
-        case SD_BUS_TYPE_OBJECT_PATH:
         case SD_BUS_TYPE_SIGNATURE:
+                p = strempty(*(char**) userdata);
+                break;
+
+        case SD_BUS_TYPE_OBJECT_PATH:
                 p = *(char**) userdata;
+                assert(p);
                 break;
 
         default:
@@ -581,7 +585,7 @@ static int property_get_all_callbacks_run(
 
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         struct node_vtable *c;
-        bool found_interface = false;
+        bool found_interface;
         int r;
 
         assert(bus);
@@ -596,6 +600,11 @@ static int property_get_all_callbacks_run(
         if (r < 0)
                 return r;
 
+        found_interface =
+                streq(iface, "org.freedesktop.DBus.Properties") ||
+                streq(iface, "org.freedesktop.DBus.Peer") ||
+                streq(iface, "org.freedesktop.DBus.Introspectable");
+
         LIST_FOREACH(vtables, c, first) {
                 _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                 void *u;
@@ -1972,8 +1981,7 @@ int sd_bus_emit_properties_changed(
                 const char *interface,
                 const char *name, ...)  {
 
-        _cleanup_strv_free_ char **names = NULL;
-        va_list ap;
+        char **names;
 
         assert_return(bus, -EINVAL);
         assert_return(object_path_is_valid(path), -EINVAL);
@@ -1984,12 +1992,7 @@ int sd_bus_emit_properties_changed(
         if (!name)
                 return 0;
 
-        va_start(ap, name);
-        names = strv_new_ap(name, ap);
-        va_end(ap);
-
-        if (!names)
-                return -ENOMEM;
+        names = strv_from_stdarg_alloca(name);
 
         return sd_bus_emit_properties_changed_strv(bus, path, interface, names);
 }
@@ -2153,20 +2156,14 @@ int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **inte
 }
 
 int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) {
-        _cleanup_strv_free_ char **interfaces = NULL;
-        va_list ap;
+        char **interfaces;
 
         assert_return(bus, -EINVAL);
         assert_return(object_path_is_valid(path), -EINVAL);
         assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        va_start(ap, interface);
-        interfaces = strv_new_ap(interface, ap);
-        va_end(ap);
-
-        if (!interfaces)
-                return -ENOMEM;
+        interfaces = strv_from_stdarg_alloca(interface);
 
         return sd_bus_emit_interfaces_added_strv(bus, path, interfaces);
 }
@@ -2199,20 +2196,14 @@ int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **in
 }
 
 int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) {
-        _cleanup_strv_free_ char **interfaces = NULL;
-        va_list ap;
+        char **interfaces;
 
         assert_return(bus, -EINVAL);
         assert_return(object_path_is_valid(path), -EINVAL);
         assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        va_start(ap, interface);
-        interfaces = strv_new_ap(interface, ap);
-        va_end(ap);
-
-        if (!interfaces)
-                return -ENOMEM;
+        interfaces = strv_from_stdarg_alloca(interface);
 
         return sd_bus_emit_interfaces_removed_strv(bus, path, interfaces);
 }