chiark / gitweb /
core: priorize notification fd processing over notification fd process via sd-event...
[elogind.git] / src / core / dbus.c
index 7d7c6cbddc8cf96e6101d7df11f16be8119c325a..ccbbc3474d4d716bd6394682bdbbe5f71c52ff6a 100644 (file)
@@ -211,6 +211,7 @@ failed:
         return 0;
 }
 
+#ifdef HAVE_SELINUX
 static int selinux_filter(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
         Manager *m = userdata;
         const char *verb, *path;
@@ -276,6 +277,7 @@ static int selinux_filter(sd_bus *bus, sd_bus_message *message, void *userdata,
 
         return 0;
 }
+#endif
 
 static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
@@ -534,11 +536,13 @@ static int bus_setup_api_vtables(Manager *m, sd_bus *bus) {
         assert(m);
         assert(bus);
 
+#ifdef HAVE_SELINUX
         r = sd_bus_add_filter(bus, selinux_filter, m);
         if (r < 0) {
                 log_error("Failed to add SELinux access filter: %s", strerror(-r));
                 return r;
         }
+#endif
 
         r = sd_bus_add_object_vtable(bus, "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", bus_manager_vtable, m);
         if (r < 0) {
@@ -742,42 +746,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;
 }
@@ -819,17 +805,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_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.");
@@ -961,6 +942,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 */