chiark / gitweb /
bus: always talk to the full dbus driver object
[elogind.git] / src / libsystemd-bus / bus-control.c
index 333968aee4a6a46401a6f86b4e46f73cabccd77e..a38ce0cb600b40f8f64360b0c083deb7e594c68a 100644 (file)
@@ -96,7 +96,7 @@ static int bus_request_name_dbus1(sd_bus *bus, const char *name, uint64_t flags)
         r = sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "RequestName",
                         NULL,
@@ -173,7 +173,7 @@ static int bus_release_name_dbus1(sd_bus *bus, const char *name) {
         r = sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "ReleaseName",
                         NULL,
@@ -295,7 +295,7 @@ static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatab
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "ListNames",
                                 NULL,
@@ -315,7 +315,7 @@ static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatab
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "ListActivatableNames",
                                 NULL,
@@ -387,6 +387,10 @@ static int bus_get_owner_kdbus(
 
         conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
 
+        /* Non-activated names are considered not available */
+        if (conn_info->flags & KDBUS_HELLO_ACTIVATOR)
+                return name[0] == ':' ? -ENXIO : -ENOENT;
+
         c = bus_creds_new();
         if (!c)
                 return -ENOMEM;
@@ -561,7 +565,7 @@ static int bus_get_owner_dbus1(
                 r = sd_bus_call_method(
                                 bus,
                                 "org.freedesktop.DBus",
-                                "/",
+                                "/org/freedesktop/DBus",
                                 "org.freedesktop.DBus",
                                 "GetNameOwner",
                                 NULL,
@@ -599,7 +603,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionUnixProcessID",
                                         NULL,
@@ -628,7 +632,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionUnixUser",
                                         NULL,
@@ -655,7 +659,7 @@ static int bus_get_owner_dbus1(
                         r = sd_bus_call_method(
                                         bus,
                                         "org.freedesktop.DBus",
-                                        "/",
+                                        "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionSELinuxSecurityContext",
                                         NULL,
@@ -702,6 +706,7 @@ _public_ int sd_bus_get_owner(
         assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
         assert_return(!bus_pid_changed(bus), -ECHILD);
         assert_return(service_name_is_valid(name), -EINVAL);
+        assert_return(bus->bus_client, -ENODATA);
 
         if (bus->is_kernel)
                 return bus_get_owner_kdbus(bus, name, mask, creds);
@@ -798,7 +803,7 @@ static int add_name_change_match(sd_bus *bus,
                 item->name_change.new.id = new_owner_id;
 
                 if (name)
-                        strcpy(item->name_change.name, name);
+                        memcpy(item->name_change.name, name, l);
 
                 /* If the old name is unset or empty, then
                  * this can match against added names */
@@ -820,17 +825,16 @@ static int add_name_change_match(sd_bus *bus,
                                 return -errno;
                 }
 
-                /* If the neither name is explicitly set to
-                 * the empty string, then this can match
-                 * against changed names */
-                if (!(old_owner && old_owner[0] == 0) &&
-                    !(new_owner && new_owner[0] == 0)) {
-                        item->type = KDBUS_ITEM_NAME_CHANGE;
-
-                        r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
-                        if (r < 0)
-                                return -errno;
-                }
+                /* The CHANGE match we need in either case, because
+                 * what is reported as a name change by the kernel
+                 * might just be an owner change between starter and
+                 * normal clients. For userspace such a change should
+                 * be considered a removal/addition, hence let's
+                 * subscribe to this unconditionally. */
+                item->type = KDBUS_ITEM_NAME_CHANGE;
+                r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
+                if (r < 0)
+                        return -errno;
         }
 
         if (is_name_id != 0) {
@@ -850,7 +854,9 @@ static int add_name_change_match(sd_bus *bus,
                 m->cookie = cookie;
 
                 item = m->items;
-                item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
+                item->size =
+                        offsetof(struct kdbus_item, id_change) +
+                        sizeof(struct kdbus_notify_id_change);
                 item->id_change.id = name_id;
 
                 /* If the old name is unset or empty, then this can
@@ -1067,7 +1073,7 @@ static int bus_add_match_internal_dbus1(
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "AddMatch",
                         NULL,
@@ -1124,7 +1130,7 @@ static int bus_remove_match_internal_dbus1(
         return sd_bus_call_method(
                         bus,
                         "org.freedesktop.DBus",
-                        "/",
+                        "/org/freedesktop/DBus",
                         "org.freedesktop.DBus",
                         "RemoveMatch",
                         NULL,