X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fdbus.c;h=580bdf3f71ca811c8ae0228d138d05822d2ff7ed;hp=d130e0974e92d30a15dc11d5a81defda8b8a9dd6;hb=6d99330e26977a9970e33fd83085c8c8c9de660f;hpb=f00c31213a2e521680c2381ef231f05e30c874a7 diff --git a/src/core/dbus.c b/src/core/dbus.c index d130e0974..580bdf3f7 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -247,9 +247,14 @@ static int selinux_filter(sd_bus *bus, sd_bus_message *message, void *userdata, } if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; pid_t pid; - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); + if (r < 0) + return 0; + + r = sd_bus_creds_get_pid(creds, &pid); if (r < 0) return 0; @@ -300,6 +305,7 @@ static int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_ assert(path); if (streq_ptr(path, "/org/freedesktop/systemd1/unit/self")) { + _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL; sd_bus_message *message; pid_t pid; @@ -307,9 +313,13 @@ static int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_ if (!message) return 0; - r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds); if (r < 0) - return 0; + return r; + + r = sd_bus_creds_get_pid(creds, &pid); + if (r < 0) + return r; u = manager_get_unit_by_pid(m, pid); } else { @@ -732,42 +742,24 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void } static int bus_list_names(Manager *m, sd_bus *bus) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - const char *name; + _cleanup_strv_free_ char **names = NULL; + char **i; int r; assert(m); assert(bus); - r = sd_bus_call_method( - bus, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - "ListNames", - &error, &reply, - NULL); + r = sd_bus_list_names(bus, &names, NULL); if (r < 0) { - log_error("Failed to get initial list of names: %s", bus_error_message(&error, r)); + log_error("Failed to get initial list of names: %s", strerror(-r)); return r; } - r = sd_bus_message_enter_container(reply, 'a', "s"); - if (r < 0) - return bus_log_parse_error(r); - /* This is a bit hacky, we say the owner of the name is the * name itself, because we don't want the extra traffic to * figure out the real owner. */ - while ((r = sd_bus_message_read(reply, "s", &name)) > 0) - manager_dispatch_bus_name_owner_changed(m, name, NULL, name); - if (r < 0) - return bus_log_parse_error(r); - - r = sd_bus_message_exit_container(reply); - if (r < 0) - return bus_log_parse_error(r); + STRV_FOREACH(i, names) + manager_dispatch_bus_name_owner_changed(m, *i, NULL, *i); return 0; } @@ -809,17 +801,12 @@ static int bus_setup_api(Manager *m, sd_bus *bus) { * after the new connection is set up and the name installed * to allow clients to synchronously wait for reexecution to * finish */ - r = sd_bus_request_name(bus,"org.freedesktop.systemd1", SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING); + r = sd_bus_request_name(bus,"org.freedesktop.systemd1", SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_DO_NOT_QUEUE|SD_BUS_NAME_ALLOW_REPLACEMENT); if (r < 0) { log_error("Failed to register name: %s", strerror(-r)); return r; } - if (r != SD_BUS_NAME_PRIMARY_OWNER) { - log_error("Failed to acquire name."); - return -EEXIST; - } - bus_list_names(m, bus); log_debug("Successfully connected to API bus."); @@ -951,6 +938,10 @@ static int bus_init_private(Manager *m) { if (m->private_listen_fd >= 0) return 0; + /* We don't need the private socket if we have kdbus */ + if (m->kdbus_fd >= 0) + return 0; + if (m->running_as == SYSTEMD_SYSTEM) { /* We want the private bus only when running as init */