X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbus-driverd%2Fbus-driverd.c;h=acb5e6ba00d574f9a07f49cbd998602c5c89da83;hp=eee3ffebcb2527857cac87d54fd5d93d87c9ef16;hb=af08d2f9cde8f46d9d3e731dbd1f06ffb3b08942;hpb=dd965d7a588f16403483fb32824e2fd6877b0318 diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c index eee3ffebc..acb5e6ba0 100644 --- a/src/bus-driverd/bus-driverd.c +++ b/src/bus-driverd/bus-driverd.c @@ -93,7 +93,7 @@ static void match_free(Match *m) { first = hashmap_get(m->client->matches, m->match); LIST_REMOVE(matches, first, m); if (first) - assert_se(hashmap_replace(m->client->matches, m->match, first) >= 0); + assert_se(hashmap_replace(m->client->matches, first->match, first) >= 0); else hashmap_remove(m->client->matches, m->match); @@ -767,7 +767,11 @@ static int driver_update_environment(sd_bus*bus, sd_bus_message *m, void *userda if (r < 0) return r; - return sd_bus_call(bus, msg, 0, NULL, NULL); + r = sd_bus_call(bus, msg, 0, NULL, NULL); + if (r < 0) + return r; + + return sd_bus_reply_method_return(m, NULL); } static int driver_unsupported(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) { @@ -799,16 +803,51 @@ static const sd_bus_vtable driver_vtable[] = { SD_BUS_VTABLE_END }; +static int find_object( + sd_bus *bus, + const char *path, + const char *interface, + void *userdata, + void **ret_found, + sd_bus_error *ret_error) { + + /* We support the driver interface on exactly two different + * paths: the root and the entry point object. This is a bit + * different from the original dbus-daemon which supported it + * on any path. */ + + if (streq_ptr(path, "/")) + return 1; + + if (streq_ptr(path, "/org/freedesktop/DBus")) + return 1; + + return 0; +} + +static int node_enumerator( + sd_bus *bus, + const char *path, + void *userdata, + char ***ret_nodes, + sd_bus_error *ret_error) { + + char **l; + + l = strv_new("/", "/org/freedesktop/DBus", NULL); + if (!l) + return -ENOMEM; + + *ret_nodes = l; + return 0; +} + static int connect_bus(Context *c) { int r; assert(c); - r = cg_pid_get_owner_uid(0, NULL); - if (r < 0) - r = sd_bus_default_system(&c->bus); - else - r = sd_bus_default_user(&c->bus); + r = sd_bus_default(&c->bus); if (r < 0) { log_error("Failed to create bus: %s", strerror(-r)); return r; @@ -819,12 +858,18 @@ static int connect_bus(Context *c) { return -EPERM; } - r = sd_bus_add_object_vtable(c->bus, "/org/freedesktop/DBus", "org.freedesktop.DBus", driver_vtable, c); + r = sd_bus_add_fallback_vtable(c->bus, "/", "org.freedesktop.DBus", driver_vtable, find_object, c); if (r < 0) { log_error("Failed to add manager object vtable: %s", strerror(-r)); return r; } + r = sd_bus_add_node_enumerator(c->bus, "/", node_enumerator, c); + if (r < 0) { + log_error("Failed to add node enumerator: %s", strerror(-r)); + return r; + } + r = sd_bus_request_name(c->bus, "org.freedesktop.DBus", 0); if (r < 0) { log_error("Unable to request name: %s", strerror(-r));