X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd-bus%2Fbus-control.c;h=a8983168abeee595d3b6b5f146f4c86b8392929c;hp=dc7237a532da7766f1810e91c84443a0d13e060f;hb=98531b5762778ed5740e8e7edc4e3790e57e9f37;hpb=ff2ea19264b016bd34232cd9c4820c9547413a9a diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c index dc7237a53..a8983168a 100644 --- a/src/libsystemd-bus/bus-control.c +++ b/src/libsystemd-bus/bus-control.c @@ -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, @@ -230,10 +230,10 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) { KDBUS_ITEM_FOREACH(name, name_list, names) { - if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->id != previous_id) { + if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->owner_id != previous_id) { char *n; - if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0) + if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0) return -ENOMEM; r = strv_push(x, n); @@ -242,7 +242,7 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) { return -ENOMEM; } - previous_id = name->id; + previous_id = name->owner_id; } if (name->size > sizeof(*name) && service_name_is_valid(name->name)) { @@ -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); @@ -715,7 +720,7 @@ static int add_name_change_match(sd_bus *bus, const char *old_owner, const char *new_owner) { - uint64_t name_id = 0, old_owner_id = 0, new_owner_id = 0; + uint64_t name_id = KDBUS_MATCH_ID_ANY, old_owner_id = 0, new_owner_id = 0; int is_name_id = -1, r; struct kdbus_item *item; @@ -723,19 +728,19 @@ static int add_name_change_match(sd_bus *bus, /* If we encounter a match that could match against * NameOwnerChanged messages, then we need to create - * KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE} and - * KDBUS_MATCH_ID_{ADD,REMOVE} matches for it, possibly + * KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE} and + * KDBUS_ITEM_ID_{ADD,REMOVE} matches for it, possibly * multiple if the match is underspecified. * * The NameOwnerChanged signals take three parameters with * unique or well-known names, but only some forms actually * exist: * - * WELLKNOWN, "", UNIQUE → KDBUS_MATCH_NAME_ADD - * WELLKNOWN, UNIQUE, "" → KDBUS_MATCH_NAME_REMOVE - * WELLKNOWN, UNIQUE, UNIQUE → KDBUS_MATCH_NAME_CHANGE - * UNIQUE, "", UNIQUE → KDBUS_MATCH_ID_ADD - * UNIQUE, UNIQUE, "" → KDBUS_MATCH_ID_REMOVE + * WELLKNOWN, "", UNIQUE → KDBUS_ITEM_NAME_ADD + * WELLKNOWN, UNIQUE, "" → KDBUS_ITEM_NAME_REMOVE + * WELLKNOWN, UNIQUE, UNIQUE → KDBUS_ITEM_NAME_CHANGE + * UNIQUE, "", UNIQUE → KDBUS_ITEM_ID_ADD + * UNIQUE, UNIQUE, "" → KDBUS_ITEM_ID_REMOVE * * For the latter two the two unique names must be identical. * @@ -755,7 +760,8 @@ static int add_name_change_match(sd_bus *bus, return 0; if (is_name_id > 0 && old_owner_id != name_id) return 0; - } + } else + old_owner_id = KDBUS_MATCH_ID_ANY; if (!isempty(new_owner)) { r = bus_kernel_parse_unique_name(new_owner, &new_owner_id); @@ -765,14 +771,15 @@ static int add_name_change_match(sd_bus *bus, return 0; if (is_name_id > 0 && new_owner_id != name_id) return 0; - } + } else + new_owner_id = KDBUS_MATCH_ID_ANY; if (is_name_id <= 0) { struct kdbus_cmd_match *m; size_t sz, l; /* If the name argument is missing or is a well-known - * name, then add KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE} + * name, then add KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE} * matches for it */ l = name ? strlen(name) + 1 : 0; @@ -785,7 +792,6 @@ static int add_name_change_match(sd_bus *bus, m = alloca0(sz); m->size = sz; m->cookie = cookie; - m->src_id = KDBUS_SRC_ID_KERNEL; item = m->items; item->size = @@ -797,12 +803,12 @@ 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 */ if (!old_owner || old_owner[0] == 0) { - item->type = KDBUS_MATCH_NAME_ADD; + item->type = KDBUS_ITEM_NAME_ADD; r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); if (r < 0) @@ -812,24 +818,23 @@ static int add_name_change_match(sd_bus *bus, /* If the new name is unset or empty, then * this can match against removed names */ if (!new_owner || new_owner[0] == 0) { - item->type = KDBUS_MATCH_NAME_REMOVE; + item->type = KDBUS_ITEM_NAME_REMOVE; r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); if (r < 0) return -errno; } - /* If the neither name is explicitly set to - * the empty string, then this can match - * agains changed names */ - if (!(old_owner && old_owner[0] == 0) && - !(new_owner && new_owner[0] == 0)) { - item->type = KDBUS_MATCH_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) { @@ -837,7 +842,7 @@ static int add_name_change_match(sd_bus *bus, uint64_t sz; /* If the name argument is missing or is a unique - * name, then add KDBUS_MATCH_ID_{ADD,REMOVE} matches + * name, then add KDBUS_ITEM_ID_{ADD,REMOVE} matches * for it */ sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) + @@ -847,16 +852,17 @@ static int add_name_change_match(sd_bus *bus, m = alloca0(sz); m->size = sz; m->cookie = cookie; - m->src_id = KDBUS_SRC_ID_KERNEL; 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 * match against added ids */ if (!old_owner || old_owner[0] == 0) { - item->type = KDBUS_MATCH_ID_ADD; + item->type = KDBUS_ITEM_ID_ADD; r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); if (r < 0) @@ -864,9 +870,9 @@ static int add_name_change_match(sd_bus *bus, } /* If thew new name is unset or empty, then this can - match against removed ids */ + * match against removed ids */ if (!new_owner || new_owner[0] == 0) { - item->type = KDBUS_MATCH_ID_REMOVE; + item->type = KDBUS_ITEM_ID_REMOVE; r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m); if (r < 0) @@ -890,7 +896,7 @@ int bus_add_match_internal_kernel( size_t sz; const char *sender = NULL; size_t sender_length = 0; - uint64_t src_id = KDBUS_MATCH_SRC_ID_ANY; + uint64_t src_id = KDBUS_MATCH_ID_ANY; bool using_bloom = false; unsigned i; bool matches_name_change = true; @@ -901,7 +907,8 @@ int bus_add_match_internal_kernel( zero(bloom); - sz = offsetof(struct kdbus_cmd_match, items); + sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) + + offsetof(struct kdbus_item, id) + sizeof(uint64_t)); for (i = 0; i < n_components; i++) { struct bus_match_component *c = &components[i]; @@ -1016,22 +1023,24 @@ int bus_add_match_internal_kernel( m = alloca0(sz); m->size = sz; m->cookie = cookie; - m->src_id = src_id; - m->id = id; + m->owner_id = id; item = m->items; + item->size = offsetof(struct kdbus_item, id) + sizeof(uint64_t); + item->type = KDBUS_ITEM_ID; + item->id = src_id; if (using_bloom) { + item = KDBUS_ITEM_NEXT(item); item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE; - item->type = KDBUS_MATCH_BLOOM; + item->type = KDBUS_ITEM_BLOOM; memcpy(item->data64, bloom, BLOOM_SIZE); - - item = KDBUS_ITEM_NEXT(item); } if (sender) { + item = KDBUS_ITEM_NEXT(item); item->size = offsetof(struct kdbus_item, str) + sender_length + 1; - item->type = KDBUS_MATCH_SRC_NAME; + item->type = KDBUS_ITEM_NAME; memcpy(item->str, sender, sender_length + 1); } @@ -1064,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, @@ -1102,7 +1111,7 @@ int bus_remove_match_internal_kernel( zero(m); m.size = offsetof(struct kdbus_cmd_match, items); m.cookie = cookie; - m.id = id; + m.owner_id = id; r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m); if (r < 0) @@ -1121,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,