]> err.no Git - systemd/commitdiff
dbus: to make sure that systemd stays controllable during early bootup, register...
authorLennart Poettering <lennart@poettering.net>
Sat, 19 Jun 2010 01:04:04 +0000 (03:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 19 Jun 2010 01:04:04 +0000 (03:04 +0200)
31 files changed:
fixme
src/dbus-automount.c
src/dbus-automount.h
src/dbus-device.c
src/dbus-device.h
src/dbus-job.c
src/dbus-manager.c
src/dbus-mount.c
src/dbus-mount.h
src/dbus-path.c
src/dbus-path.h
src/dbus-service.c
src/dbus-service.h
src/dbus-snapshot.c
src/dbus-snapshot.h
src/dbus-socket.c
src/dbus-socket.h
src/dbus-swap.c
src/dbus-swap.h
src/dbus-target.c
src/dbus-target.h
src/dbus-timer.c
src/dbus-timer.h
src/dbus-unit.c
src/dbus.c
src/dbus.h
src/manager.c
src/manager.h
src/systemctl.c
src/unit.c
src/unit.h

diff --git a/fixme b/fixme
index b5b8e632f79c41c5c3cb9a09e1562326f8b9c2c4..15e3ef6b26879003dfcd018c135361275d7aae5b 100644 (file)
--- a/fixme
+++ b/fixme
 
 * systemd-sysvinit as package
 
-* abstract namespace dbus socket
-
 * patch /etc/init.d/functions with:
 
   if [ $PPID -ne 1 && mountpoint /cgroup/systemd ] ; then echo "You suck!" ; fi
 
+* remove MANAGER_SYSTEM
+
 Regularly:
 
 * look for close() vs. close_nointr() vs. close_nointr_nofail()
index 285f666da91b2cda1113a07f42278d9ebd6e4216..61732f989fedceeb818174d5f21a19cfaf63f5cf 100644 (file)
 
 const char bus_automount_interface[] = BUS_AUTOMOUNT_INTERFACE;
 
-DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Automount", "Where", bus_property_append_string, "s", u->automount.where },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index 5e0ee5107b69b992ac8686fe740e8055f32ca4fe..77c887e89c306e39ef5484a23b37eb9ce2cc810b 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_automount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_automount_interface[];
 
index 0610ab873ff931b5aeb62c777bb147cf9f6bac97..168c8c8c722e126256da87808dd6e57ec04bd1f8 100644 (file)
 
 const char bus_device_interface[] = BUS_DEVICE_INTERFACE;
 
-DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_device_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Device", "SysFSPath", bus_property_append_string, "s", u->device.sysfs },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index 55bb8f55f3e312a58de82f06c9259b346a6966df..dc717f17c2b4240b671c3a7ae1747d76396d679c 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_device_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_device_interface[];
 
index 7346252a18a965168c8e660565d25af9dfb6c8e2..48b1588deea8b133c8343f9ef25187cbd643941a 100644 (file)
@@ -78,7 +78,7 @@ static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *prope
         return 0;
 }
 
-static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message) {
+static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connection, DBusMessage *message) {
         const BusProperty properties[] = {
                 { "org.freedesktop.systemd1.Job", "Id",      bus_property_append_uint32, "u",    &j->id    },
                 { "org.freedesktop.systemd1.Job", "State",   bus_job_append_state,       "s",    &j->state },
@@ -88,7 +88,6 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message)
         };
 
         DBusMessage *reply = NULL;
-        Manager *m = j->manager;
 
         if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Job", "Cancel")) {
                 if (!(reply = dbus_message_new_method_return(message)))
@@ -97,10 +96,10 @@ static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusMessage *message)
                 job_free(j);
 
         } else
-                return bus_default_message_handler(j->manager, message, INTROSPECTION, properties);
+                return bus_default_message_handler(j->manager, connection, message, INTROSPECTION, properties);
 
         if (reply) {
-                if (!dbus_connection_send(m->api_bus, reply, NULL))
+                if (!dbus_connection_send(connection, reply, NULL))
                         goto oom;
 
                 dbus_message_unref(reply);
@@ -115,7 +114,7 @@ oom:
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
 }
 
-static DBusHandlerResult bus_job_message_handler(DBusConnection  *connection, DBusMessage  *message, void *data) {
+static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage  *message, void *data) {
         Manager *m = data;
         Job *j;
         int r;
@@ -137,10 +136,10 @@ static DBusHandlerResult bus_job_message_handler(DBusConnection  *connection, DB
                 if (r == -ENOENT)
                         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-                return bus_send_error_reply(m, message, NULL, r);
+                return bus_send_error_reply(m, connection, message, NULL, r);
         }
 
-        return bus_job_message_dispatch(j, message);
+        return bus_job_message_dispatch(j, connection, message);
 }
 
 const DBusObjectPathVTable bus_job_vtable = {
@@ -183,7 +182,7 @@ void bus_job_send_change_signal(Job *j) {
                         goto oom;
         }
 
-        if (!dbus_connection_send(j->manager->api_bus, m, NULL))
+        if (bus_broadcast(j->manager, m) < 0)
                 goto oom;
 
         free(p);
@@ -228,7 +227,7 @@ void bus_job_send_removed_signal(Job *j, bool success) {
                                       DBUS_TYPE_INVALID))
                 goto oom;
 
-        if (!dbus_connection_send(j->manager->api_bus, m, NULL))
+        if (bus_broadcast(j->manager, m) < 0)
                 goto oom;
 
         free(p);
index d4c9e8f0e2cfa91863f98cf1b1d6297fd9efae49..781825782beb6e74afed483a2c767dcd430987ac 100644 (file)
@@ -185,7 +185,7 @@ static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char
         return 0;
 }
 
-static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
         Manager *m = data;
 
         const BusProperty properties[] = {
@@ -226,10 +226,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     &error,
                                     DBUS_TYPE_STRING, &name,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if (!(u = manager_get_unit(m, name)))
-                        return bus_send_error_reply(m, message, NULL, -ENOENT);
+                        return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -252,10 +252,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     &error,
                                     DBUS_TYPE_STRING, &name,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -286,10 +286,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     &error,
                                     DBUS_TYPE_UINT32, &id,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if (!(j = manager_get_job(m, id)))
-                        return bus_send_error_reply(m, message, NULL, -ENOENT);
+                        return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -449,7 +449,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 r = set_put(m->subscribed, client);
 
                 if (r < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -458,7 +458,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 char *client;
 
                 if (!(client = set_remove(m->subscribed, (char*) dbus_message_get_sender(message))))
-                        return bus_send_error_reply(m, message, NULL, -ENOENT);
+                        return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
 
                 free(client);
 
@@ -504,13 +504,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     DBUS_TYPE_STRING, &name,
                                     DBUS_TYPE_BOOLEAN, &cleanup,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if (name && name[0] == 0)
                         name = NULL;
 
                 if ((r = snapshot_create(m, name, cleanup, &s)) < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -609,7 +609,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
 
                 if (m->running_as == MANAGER_INIT)
-                        return bus_send_error_reply(m, message, NULL, -ENOTSUP);
+                        return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -623,7 +623,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                         if (r == -ENOMEM)
                                 goto oom;
 
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
                 }
 
                 e = strv_env_merge(2, m->environment, l);
@@ -647,7 +647,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                         if (r == -ENOMEM)
                                 goto oom;
 
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
                 }
 
                 e = strv_env_delete(m->environment, 1, l);
@@ -663,7 +663,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                 m->environment = e;
 
         } else
-                return bus_default_message_handler(m, message, NULL, properties);
+                return bus_default_message_handler(m, connection, message, NULL, properties);
 
 
         if (job_type != _JOB_TYPE_INVALID) {
@@ -678,19 +678,19 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection  *connection
                                     DBUS_TYPE_STRING, &name,
                                     DBUS_TYPE_STRING, &smode,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
-                        return bus_send_error_reply(m, message, NULL, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
 
                 if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (job_type == JOB_START && u->meta.only_by_dependency)
-                        return bus_send_error_reply(m, message, NULL, -EPERM);
+                        return bus_send_error_reply(m, connection, message, NULL, -EPERM);
 
                 if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
index cccfa60e1092132745973993222593a2e93c001c..0f417e76db40c5fb9c84bdc0b2e95a0b9d9a1def 100644 (file)
@@ -120,7 +120,7 @@ static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *pro
         return 0;
 }
 
-DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Mount", "Where",       bus_property_append_string, "s", u->mount.where         },
@@ -135,5 +135,5 @@ DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) {
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index 6d8d1a9685aba2beff0264dcb1230e6944a6b32b..53522f7062f2821b6825abef0561e93780b47f93 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_mount_interface[];
 
index ed1dc265fc67271abc76c99e754a7ffaee81bd35..7589f5bc5be06e99876d3fecf5be02cf2a8c2954 100644 (file)
 
 const char bus_path_interface[] = BUS_PATH_INTERFACE;
 
-DBusHandlerResult bus_path_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Path", "Unit", bus_property_append_string, "s", &u->path.unit->meta.id },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index 15f5869894b101702ca6c7502a6a8900ee679faf..261d8451b4530512e67fffab1ee76fe3e92afc25 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_path_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_path_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_path_interface[];
 
index f70a77212c8b9028d525bbfe22ae050ed2a56db9..283932c5052e8dfbce086e7eb1cf21b65346acde 100644 (file)
@@ -58,7 +58,7 @@ const char bus_service_interface[] = BUS_SERVICE_INTERFACE;
 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
 
-DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Service", "Type",                   bus_service_append_type,    "s", &u->service.type },
@@ -81,5 +81,5 @@ DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message) {
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, properties);
 }
index ab1e02f35207994ca0cc710f5fca9b75dda9fd46..cfbdab388a4d83638f7ae18e4dc723d6540b4f9c 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_service_interface[];
 
index 15e51f032e63fbc11391ddfd6a4a721191fdfd94..5ba5d7c8d89c429fe182ec4ee0cab6e453e466ea 100644 (file)
@@ -39,7 +39,7 @@
 
 const char bus_snapshot_interface[] = BUS_SNAPSHOT_INTERFACE;
 
-DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Snapshot", "Cleanup", bus_property_append_bool, "b", &u->snapshot.cleanup },
@@ -59,10 +59,10 @@ DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message) {
                         goto oom;
 
         } else
-                return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+                return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 
         if (reply) {
-                if (!dbus_connection_send(u->meta.manager->api_bus, reply, NULL))
+                if (!dbus_connection_send(c, reply, NULL))
                         goto oom;
 
                 dbus_message_unref(reply);
index bf5a4d4bc534290043cc94aae9a4dfb3f9e5ee4a..60b3720d357ea137e95657d4b88fb8c1a10514f5 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_snapshot_interface[];
 
index 426af2b4cf77f161da4d4efd0d23c2a54b13420d..a5474c9f35b34c9286c25b3d22e1c5df716ef9ca 100644 (file)
@@ -52,7 +52,7 @@ const char bus_socket_interface[] = BUS_SOCKET_INTERFACE;
 
 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
 
-DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Socket", "BindIPv6Only",  bus_socket_append_bind_ipv6_only, "s", &u->socket.bind_ipv6_only },
@@ -69,5 +69,5 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message) {
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index ab0632204225e47fc2e2cf1d81d8e8f71454ecfb..79a1546dffc46e0b53e637e61c5c7ed60c69fbf0 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_socket_interface[];
 
index f6f8685dafe57c0f24a7ddc0dcd19a197bd17ac4..676ec5cc79aa32b93065e2efa730f0a7195757a5 100644 (file)
@@ -66,7 +66,7 @@ static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *
         return 0;
 }
 
-DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Swap", "What",     bus_property_append_string, "s", u->swap.what },
@@ -74,5 +74,5 @@ DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message) {
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index cbd15919db51ea473a3505b39ec847808539989e..a3d418c21bd7cbb76dfe29f47d138a7f9153ddbf 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_swap_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_swap_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_swap_interface[];
 
index 45f0d31f05de9efe4a4ec13cb32d35a1b67fb2cc..fb84430b21445a6f996ecbb268cd7392bffedf99 100644 (file)
 
 const char bus_target_interface[] = BUS_TARGET_INTERFACE;
 
-DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_target_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index d118441a676c290a3b3ae1423625b092781cc9db..af2dc62bcf5007fcde60c0f2cf4d9cff1a226272 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_target_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_target_interface[];
 
index d572907819998bfaa447a6cd1236dd70092e2338..68bd8a44899cec4ac0033f97f35fbb55b891d96b 100644 (file)
 
 const char bus_timer_interface[] = BUS_TIMER_INTERFACE;
 
-DBusHandlerResult bus_timer_message_handler(Unit *u, DBusMessage *message) {
+DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         const BusProperty properties[] = {
                 BUS_UNIT_PROPERTIES,
                 { "org.freedesktop.systemd1.Timer", "Unit", bus_property_append_string, "s", &u->timer.unit->meta.id },
                 { NULL, NULL, NULL, NULL, NULL }
         };
 
-        return bus_default_message_handler(u->meta.manager, message, INTROSPECTION, properties);
+        return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, properties);
 }
index 250e8186ed05d48c4b0ae534774c9ca54bea0506..562d44981e3b4da21c715da6c9da79b6f333144f 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "unit.h"
 
-DBusHandlerResult bus_timer_message_handler(Unit *u, DBusMessage *message);
+DBusHandlerResult bus_timer_message_handler(Unit *u, DBusConnection *c, DBusMessage *message);
 
 extern const char bus_timer_interface[];
 
index 8e35377dc56370103424ac96cf05e10cbd52af06..17ca7bdd8965bc51dd5da46fc5e60496c9457195 100644 (file)
@@ -255,7 +255,7 @@ int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property
 
 DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_kill_mode, kill_mode, KillMode);
 
-static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message) {
+static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) {
         DBusMessage *reply = NULL;
         Manager *m = u->meta.manager;
         DBusError error;
@@ -273,7 +273,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart"))
                 job_type = JOB_RESTART;
         else if (UNIT_VTABLE(u)->bus_message_handler)
-                return UNIT_VTABLE(u)->bus_message_handler(u, message);
+                return UNIT_VTABLE(u)->bus_message_handler(u, connection, message);
         else
                 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
@@ -284,20 +284,20 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
                 int r;
 
                 if (job_type == JOB_START && u->meta.only_by_dependency)
-                        return bus_send_error_reply(m, message, NULL, -EPERM);
+                        return bus_send_error_reply(m, connection, message, NULL, -EPERM);
 
                 if (!dbus_message_get_args(
                                     message,
                                     &error,
                                     DBUS_TYPE_STRING, &smode,
                                     DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, &error, -EINVAL);
 
                 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
-                        return bus_send_error_reply(m, message, NULL, -EINVAL);
+                        return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
 
                 if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
-                        return bus_send_error_reply(m, message, NULL, r);
+                        return bus_send_error_reply(m, connection, message, NULL, r);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -315,7 +315,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message
         free(path);
 
         if (reply) {
-                if (!dbus_connection_send(m->api_bus, reply, NULL))
+                if (!dbus_connection_send(connection, reply, NULL))
                         goto oom;
 
                 dbus_message_unref(reply);
@@ -334,7 +334,7 @@ oom:
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
 }
 
-static DBusHandlerResult bus_unit_message_handler(DBusConnection  *connection, DBusMessage  *message, void *data) {
+static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage  *message, void *data) {
         Manager *m = data;
         Unit *u;
         int r;
@@ -356,10 +356,10 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection  *connection, D
                 if (r == -ENOENT)
                         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
-                return bus_send_error_reply(m, message, NULL, r);
+                return bus_send_error_reply(m, connection, message, NULL, r);
         }
 
-        return bus_unit_message_dispatch(u, message);
+        return bus_unit_message_dispatch(u, connection, message);
 }
 
 const DBusObjectPathVTable bus_unit_vtable = {
@@ -402,7 +402,7 @@ void bus_unit_send_change_signal(Unit *u) {
                         goto oom;
         }
 
-        if (!dbus_connection_send(u->meta.manager->api_bus, m, NULL))
+        if (bus_broadcast(u->meta.manager, m) < 0)
                 goto oom;
 
         free(p);
@@ -445,7 +445,7 @@ void bus_unit_send_removed_signal(Unit *u) {
                                       DBUS_TYPE_INVALID))
                 goto oom;
 
-        if (!dbus_connection_send(u->meta.manager->api_bus, m, NULL))
+        if (bus_broadcast(u->meta.manager, m) < 0)
                 goto oom;
 
         free(p);
index a4e350c33b75cbec45a49fd6e008381674e5a528..a34c7dc17bdabecc45c8195cfb199991026bb7be 100644 (file)
@@ -43,6 +43,8 @@
 #include "dbus-timer.h"
 #include "dbus-path.h"
 
+#define CONNECTIONS_MAX 52
+
 static const char bus_properties_interface[] = BUS_PROPERTIES_INTERFACE;
 static const char bus_introspectable_interface[] = BUS_INTROSPECTABLE_INTERFACE;
 
@@ -66,33 +68,24 @@ const char *const bus_interface_table[] = {
 };
 
 static const char *error_to_dbus(int error);
+static void bus_done_api(Manager *m);
+static void bus_done_system(Manager *m);
+static void bus_done_private(Manager *m);
 
-static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data)  {
-        Manager *m = data;
-
-        assert(bus);
-        assert(m);
-
-        if (!m->api_bus)
-                return;
-
-        assert(m->api_bus == bus);
-
-        m->request_api_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
-}
-
-static void system_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data)  {
+static void bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data)  {
         Manager *m = data;
 
         assert(bus);
         assert(m);
 
-        if (!m->system_bus)
-                return;
-
-        assert(m->system_bus == bus);
+        /* We maintain two sets, one for those connections where we
+         * requested a dispatch, and another where we didn't. And then,
+         * we move the connections between the two sets. */
 
-        m->request_system_bus_dispatch = status != DBUS_DISPATCH_COMPLETE;
+        if (status == DBUS_DISPATCH_COMPLETE)
+                set_move_one(m->bus_connections, m->bus_connections_for_dispatch, bus);
+        else
+                set_move_one(m->bus_connections_for_dispatch, m->bus_connections, bus);
 }
 
 static uint32_t bus_flags_to_events(DBusWatch *bus_watch) {
@@ -472,7 +465,30 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, D
         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
+static DBusHandlerResult private_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
+        Manager *m = data;
+
+        assert(connection);
+        assert(message);
+        assert(m);
+
+        /* log_debug("Got D-Bus request: %s.%s() on %s", */
+        /*           dbus_message_get_interface(message), */
+        /*           dbus_message_get_member(message), */
+        /*           dbus_message_get_path(message)); */
+
+        if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
+                set_remove(m->bus_connections, connection);
+                set_remove(m->bus_connections_for_dispatch, connection);
+                dbus_connection_unref(connection);
+        }
+
+        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
 unsigned bus_dispatch(Manager *m) {
+        DBusConnection *c;
+
         assert(m);
 
         if (m->queued_message) {
@@ -480,23 +496,17 @@ unsigned bus_dispatch(Manager *m) {
                  * dispatch any D-Bus messages, so that we won't end
                  * up wanting to queue another message. */
 
-                if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
-                        return 0;
+                if (m->api_bus)
+                        if (!dbus_connection_send(m->api_bus, m->queued_message, NULL))
+                                return 0;
 
                 dbus_message_unref(m->queued_message);
                 m->queued_message = NULL;
         }
 
-        if (m->request_api_bus_dispatch) {
-                if (dbus_connection_dispatch(m->api_bus) == DBUS_DISPATCH_COMPLETE)
-                        m->request_api_bus_dispatch = false;
-
-                return 1;
-        }
-
-        if (m->request_system_bus_dispatch) {
-                if (dbus_connection_dispatch(m->system_bus) == DBUS_DISPATCH_COMPLETE)
-                        m->request_system_bus_dispatch = false;
+        if ((c = set_first(m->bus_connections_for_dispatch))) {
+                if (dbus_connection_dispatch(c) == DBUS_DISPATCH_COMPLETE)
+                        set_move_one(m->bus_connections, m->bus_connections_for_dispatch, c);
 
                 return 1;
         }
@@ -689,13 +699,57 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) {
         dbus_connection_set_exit_on_disconnect(bus, FALSE);
 
         if (!dbus_connection_set_watch_functions(bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
-            !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL))
+            !dbus_connection_set_timeout_functions(bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
+                log_error("Not enough memory");
                 return -ENOMEM;
+        }
 
+        if (set_put(m->bus_connections_for_dispatch, bus) < 0) {
+                log_error("Not enough memory");
+                return -ENOMEM;
+        }
+
+        dbus_connection_set_dispatch_status_function(bus, bus_dispatch_status, m, NULL);
         return 0;
 }
 
-int bus_init_system(Manager *m) {
+static dbus_bool_t allow_only_root(DBusConnection *connection, unsigned long uid, void *data) {
+        return uid == 0;
+}
+
+static void bus_new_connection(
+                DBusServer *server,
+                DBusConnection *new_connection,
+                void *data) {
+
+        Manager *m = data;
+
+        assert(m);
+
+        if (set_size(m->bus_connections) >= CONNECTIONS_MAX) {
+                log_error("Too many concurrent connections.");
+                return;
+        }
+
+        dbus_connection_set_unix_user_function(new_connection, allow_only_root, NULL, NULL);
+
+        if (bus_setup_loop(m, new_connection) < 0)
+                return;
+
+        if (!dbus_connection_register_object_path(new_connection, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
+            !dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
+            !dbus_connection_register_fallback(new_connection, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
+            !dbus_connection_add_filter(new_connection, private_bus_message_filter, m, NULL)) {
+                log_error("Not enough memory.");
+                return;
+        }
+
+        log_debug("Accepted connection on private bus.");
+
+        dbus_connection_ref(new_connection);
+}
+
+static int bus_init_system(Manager *m) {
         DBusError error;
         char *id;
         int r;
@@ -712,22 +766,18 @@ int bus_init_system(Manager *m) {
         else {
                 if (!(m->system_bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) {
                         log_debug("Failed to get system D-Bus connection, retrying later: %s", error.message);
-                        dbus_error_free(&error);
-                        return 0;
+                        r = 0;
+                        goto fail;
                 }
 
-                dbus_connection_set_dispatch_status_function(m->system_bus, system_bus_dispatch_status, m, NULL);
-                m->request_system_bus_dispatch = true;
-
-                if ((r = bus_setup_loop(m, m->system_bus)) < 0) {
-                        bus_done_system(m);
-                        return r;
-                }
+                if ((r = bus_setup_loop(m, m->system_bus)) < 0)
+                        goto fail;
         }
 
         if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL)) {
-                bus_done_system(m);
-                return -ENOMEM;
+                log_error("Not enough memory");
+                r = -EIO;
+                goto fail;
         }
 
         dbus_bus_add_match(m->system_bus,
@@ -739,9 +789,8 @@ int bus_init_system(Manager *m) {
 
         if (dbus_error_is_set(&error)) {
                 log_error("Failed to register match: %s", error.message);
-                dbus_error_free(&error);
-                bus_done_system(m);
-                return -ENOMEM;
+                r = -EIO;
+                goto fail;
         }
 
         log_debug("Successfully connected to system D-Bus bus %s as %s",
@@ -750,9 +799,15 @@ int bus_init_system(Manager *m) {
         dbus_free(id);
 
         return 0;
+
+fail:
+        bus_done_system(m);
+        dbus_error_free(&error);
+
+        return r;
 }
 
-int bus_init_api(Manager *m) {
+static int bus_init_api(Manager *m) {
         DBusError error;
         char *id;
         int r;
@@ -764,34 +819,26 @@ int bus_init_api(Manager *m) {
         if (m->api_bus)
                 return 0;
 
-        if (m->name_data_slot < 0)
-                if (!dbus_pending_call_allocate_data_slot(&m->name_data_slot))
-                        return -ENOMEM;
-
         if (m->running_as != MANAGER_SESSION && m->system_bus)
                 m->api_bus = m->system_bus;
         else {
                 if (!(m->api_bus = dbus_bus_get_private(m->running_as == MANAGER_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error))) {
                         log_debug("Failed to get API D-Bus connection, retrying later: %s", error.message);
-                        dbus_error_free(&error);
-                        return 0;
+                        r = 0;
+                        goto fail;
                 }
 
-                dbus_connection_set_dispatch_status_function(m->api_bus, api_bus_dispatch_status, m, NULL);
-                m->request_api_bus_dispatch = true;
-
-                if ((r = bus_setup_loop(m, m->api_bus)) < 0) {
-                        bus_done_api(m);
-                        return r;
-                }
+                if ((r = bus_setup_loop(m, m->api_bus)) < 0)
+                        goto fail;
         }
 
         if (!dbus_connection_register_object_path(m->api_bus, "/org/freedesktop/systemd1", &bus_manager_vtable, m) ||
             !dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/unit", &bus_unit_vtable, m) ||
             !dbus_connection_register_fallback(m->api_bus, "/org/freedesktop/systemd1/job", &bus_job_vtable, m) ||
             !dbus_connection_add_filter(m->api_bus, api_bus_message_filter, m, NULL)) {
-                bus_done_api(m);
-                return -ENOMEM;
+                log_error("Not enough memory");
+                r = -ENOMEM;
+                goto fail;
         }
 
         /* Get NameOwnerChange messages */
@@ -805,9 +852,8 @@ int bus_init_api(Manager *m) {
 
         if (dbus_error_is_set(&error)) {
                 log_error("Failed to register match: %s", error.message);
-                dbus_error_free(&error);
-                bus_done_api(m);
-                return -ENOMEM;
+                r = -EIO;
+                goto fail;
         }
 
         /* Get activation requests */
@@ -821,20 +867,15 @@ int bus_init_api(Manager *m) {
 
         if (dbus_error_is_set(&error)) {
                 log_error("Failed to register match: %s", error.message);
-                dbus_error_free(&error);
-                bus_done_api(m);
-                return -ENOMEM;
+                r = -EIO;
+                goto fail;
         }
 
-        if ((r = request_name(m)) < 0) {
-                bus_done_api(m);
-                return r;
-        }
+        if ((r = request_name(m)) < 0)
+                goto fail;
 
-        if ((r = query_name_list(m)) < 0) {
-                bus_done_api(m);
-                return r;
-        }
+        if ((r = query_name_list(m)) < 0)
+                goto fail;
 
         log_debug("Successfully connected to API D-Bus bus %s as %s",
                   strnull((id = dbus_connection_get_server_id(m->api_bus))),
@@ -842,23 +883,106 @@ int bus_init_api(Manager *m) {
         dbus_free(id);
 
         if (!m->subscribed)
-                if (!(m->subscribed = set_new(string_hash_func, string_compare_func)))
+                if (!(m->subscribed = set_new(string_hash_func, string_compare_func))) {
+                        log_error("Not enough memory");
+                        r = -ENOMEM;
+                        goto fail;
+                }
+
+        return 0;
+
+fail:
+        bus_done_api(m);
+        dbus_error_free(&error);
+
+        return r;
+}
+
+static int bus_init_private(Manager *m) {
+        DBusError error;
+        int r;
+        const char *const external_only[] = {
+                "EXTERNAL",
+                NULL
+        };
+
+        assert(m);
+
+        dbus_error_init(&error);
+
+        if (m->private_bus)
+                return 0;
+
+        /* We want the private bus only when running as init */
+        if (m->running_as != MANAGER_INIT)
+                return 0;
+
+        if (!(m->private_bus = dbus_server_listen("unix:abstract=/org/freedesktop/systemd1/private", &error))) {
+                log_error("Failed to create private D-Bus server: %s", error.message);
+                r = -EIO;
+                goto fail;
+        }
+
+        if (!dbus_server_set_auth_mechanisms(m->private_bus, (const char**) external_only) ||
+            !dbus_server_set_watch_functions(m->private_bus, bus_add_watch, bus_remove_watch, bus_toggle_watch, m, NULL) ||
+            !dbus_server_set_timeout_functions(m->private_bus, bus_add_timeout, bus_remove_timeout, bus_toggle_timeout, m, NULL)) {
+                log_error("Not enough memory");
+                r = -ENOMEM;
+                goto fail;
+        }
+
+        dbus_server_set_new_connection_function(m->private_bus, bus_new_connection, m, NULL);
+
+        log_debug("Successfully create private D-Bus server.");
+
+        return 0;
+
+fail:
+        bus_done_private(m);
+        dbus_error_free(&error);
+
+        return r;
+}
+
+int bus_init(Manager *m) {
+        int r;
+
+        if (set_ensure_allocated(&m->bus_connections, trivial_hash_func, trivial_compare_func) < 0 ||
+            set_ensure_allocated(&m->bus_connections_for_dispatch, trivial_hash_func, trivial_compare_func) < 0) {
+                log_error("Not enough memory");
+                return -ENOMEM;
+        }
+
+        if (m->name_data_slot < 0)
+                if (!dbus_pending_call_allocate_data_slot(&m->name_data_slot)) {
+                        log_error("Not enough memory");
                         return -ENOMEM;
+                }
+
+        if ((r = bus_init_system(m)) < 0 ||
+            (r = bus_init_api(m)) < 0 ||
+            (r = bus_init_private(m)) < 0)
+                return r;
 
         return 0;
 }
 
-void bus_done_api(Manager *m) {
+static void shutdown_connection(DBusConnection *c) {
+        dbus_connection_set_dispatch_status_function(c, NULL, NULL, NULL);
+        dbus_connection_flush(c);
+        dbus_connection_close(c);
+        dbus_connection_unref(c);
+}
+
+static void bus_done_api(Manager *m) {
         assert(m);
 
         if (m->api_bus) {
                 if (m->system_bus == m->api_bus)
                         m->system_bus = NULL;
 
-                dbus_connection_set_dispatch_status_function(m->api_bus, NULL, NULL, NULL);
-                dbus_connection_flush(m->api_bus);
-                dbus_connection_close(m->api_bus);
-                dbus_connection_unref(m->api_bus);
+                set_remove(m->bus_connections, m->api_bus);
+                shutdown_connection(m->api_bus);
                 m->api_bus = NULL;
         }
 
@@ -872,30 +996,54 @@ void bus_done_api(Manager *m) {
                 m->subscribed = NULL;
         }
 
-       if (m->name_data_slot >= 0)
-               dbus_pending_call_free_data_slot(&m->name_data_slot);
-
        if (m->queued_message) {
                dbus_message_unref(m->queued_message);
                m->queued_message = NULL;
        }
 }
 
-void bus_done_system(Manager *m) {
+static void bus_done_system(Manager *m) {
         assert(m);
 
         if (m->system_bus == m->api_bus)
                 bus_done_api(m);
 
         if (m->system_bus) {
-                dbus_connection_set_dispatch_status_function(m->system_bus, NULL, NULL, NULL);
-                dbus_connection_flush(m->system_bus);
-                dbus_connection_close(m->system_bus);
-                dbus_connection_unref(m->system_bus);
+                set_remove(m->bus_connections, m->system_bus);
+                shutdown_connection(m->system_bus);
                 m->system_bus = NULL;
         }
 }
 
+static void bus_done_private(Manager *m) {
+
+        if (m->private_bus) {
+                dbus_server_disconnect(m->private_bus);
+                dbus_server_unref(m->private_bus);
+                m->private_bus = NULL;
+        }
+}
+
+void bus_done(Manager *m) {
+        DBusConnection *c;
+
+        bus_done_api(m);
+        bus_done_system(m);
+        bus_done_private(m);
+
+        while ((c = set_steal_first(m->bus_connections)))
+                shutdown_connection(c);
+
+        while ((c = set_steal_first(m->bus_connections_for_dispatch)))
+                shutdown_connection(c);
+
+        set_free(m->bus_connections);
+        set_free(m->bus_connections_for_dispatch);
+
+        if (m->name_data_slot >= 0)
+               dbus_pending_call_free_data_slot(&m->name_data_slot);
+}
+
 static void query_pid_pending_cb(DBusPendingCall *pending, void *userdata) {
         Manager *m = userdata;
         DBusMessage *reply;
@@ -992,7 +1140,7 @@ oom:
         return -ENOMEM;
 }
 
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char*introspection, const BusProperty *properties) {
+DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char*introspection, const BusProperty *properties) {
         DBusError error;
         DBusMessage *reply = NULL;
         int r;
@@ -1020,7 +1168,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
                             DBUS_TYPE_STRING, &interface,
                             DBUS_TYPE_STRING, &property,
                             DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, c, message, &error, -EINVAL);
 
                 for (p = properties; p->property; p++)
                         if (streq(p->interface, interface) && streq(p->property, property))
@@ -1043,7 +1191,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
                                         goto oom;
 
                                 dbus_message_unref(reply);
-                                return bus_send_error_reply(m, message, NULL, r);
+                                return bus_send_error_reply(m, c, message, NULL, r);
                         }
 
                         if (!dbus_message_iter_close_container(&iter, &sub))
@@ -1060,7 +1208,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
                             &error,
                             DBUS_TYPE_STRING, &interface,
                             DBUS_TYPE_INVALID))
-                        return bus_send_error_reply(m, message, &error, -EINVAL);
+                        return bus_send_error_reply(m, c, message, &error, -EINVAL);
 
                 if (!(reply = dbus_message_new_method_return(message)))
                         goto oom;
@@ -1085,7 +1233,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
                                         goto oom;
 
                                 dbus_message_unref(reply);
-                                return bus_send_error_reply(m, message, NULL, r);
+                                return bus_send_error_reply(m, c, message, NULL, r);
                         }
 
                         if (!dbus_message_iter_close_container(&sub2, &sub3) ||
@@ -1100,7 +1248,7 @@ DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message,
         }
 
         if (reply) {
-                if (!dbus_connection_send(m->api_bus, reply, NULL))
+                if (!dbus_connection_send(c, reply, NULL))
                         goto oom;
 
                 dbus_message_unref(reply);
@@ -1156,7 +1304,7 @@ static const char *error_to_dbus(int error) {
         return DBUS_ERROR_FAILED;
 }
 
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error) {
+DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error) {
         DBusMessage *reply = NULL;
         const char *name, *text;
 
@@ -1171,7 +1319,7 @@ DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusErr
         if (!(reply = dbus_message_new_error(message, name, text)))
                 goto oom;
 
-        if (!dbus_connection_send(m->api_bus, reply, NULL))
+        if (!dbus_connection_send(c, reply, NULL))
                 goto oom;
 
         dbus_message_unref(reply);
@@ -1191,6 +1339,25 @@ oom:
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
 }
 
+int bus_broadcast(Manager *m, DBusMessage *message) {
+        bool oom = false;
+        Iterator i;
+        DBusConnection *c;
+
+        assert(m);
+        assert(message);
+
+        SET_FOREACH(c, m->bus_connections_for_dispatch, i)
+                if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+                        oom = !dbus_connection_send(c, message, NULL);
+
+        SET_FOREACH(c, m->bus_connections, i)
+                if (c != m->system_bus || m->running_as != MANAGER_SESSION)
+                        oom = !dbus_connection_send(c, message, NULL);
+
+        return oom ? -ENOMEM : 0;
+}
+
 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data) {
         const char *t = data;
 
index 264bdff6258dec8c9eb65904e17dde892248779c..af837f283f8f86a3cb582237c123ce52c4a67e33 100644 (file)
@@ -56,10 +56,8 @@ typedef struct BusProperty {
         "  </method>\n"                                                 \
         " </interface>\n"
 
-int bus_init_system(Manager *m);
-int bus_init_api(Manager *m);
-void bus_done_system(Manager *m);
-void bus_done_api(Manager *m);
+int bus_init(Manager *m);
+void bus_done(Manager *m);
 
 unsigned bus_dispatch(Manager *m);
 
@@ -68,9 +66,10 @@ void bus_timeout_event(Manager *m, Watch *w, int events);
 
 int bus_query_pid(Manager *m, const char *name);
 
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char* introspection, const BusProperty *properties);
+DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const BusProperty *properties);
+DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
 
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error);
+int bus_broadcast(Manager *m, DBusMessage *message);
 
 int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
 int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
index dee6109c005d35319a731dc3f530388ba1c25274..456241f6d22753890ea28f32b765691ab5df8518 100644 (file)
@@ -243,8 +243,7 @@ int manager_new(ManagerRunningAs running_as, bool confirm_spawn, Manager **_m) {
                 goto fail;
 
         /* Try to connect to the busses, if possible. */
-        if ((r = bus_init_system(m)) < 0 ||
-            (r = bus_init_api(m)) < 0)
+        if ((r = bus_init(m)) < 0)
                 goto fail;
 
         if (asprintf(&p, "%s/%s", m->cgroup_mount_point, m->cgroup_hierarchy) < 0) {
@@ -424,8 +423,7 @@ void manager_free(Manager *m) {
          * around */
         manager_shutdown_cgroup(m, m->exit_code != MANAGER_REEXECUTE);
 
-        bus_done_api(m);
-        bus_done_system(m);
+        bus_done(m);
 
         hashmap_free(m->units);
         hashmap_free(m->jobs);
@@ -1826,8 +1824,7 @@ static int manager_process_signal_fd(Manager *m) {
 
                         if (!u || UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u))) {
                                 log_info("Trying to reconnect to bus...");
-                                bus_init_system(m);
-                                bus_init_api(m);
+                                bus_init(m);
                         }
 
                         if (!u || !UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u))) {
index 6c3434e5a049d760f7087221dc7492b24897703c..2a04bc7ddd1096987f98cf12789d7d38ebf173b4 100644 (file)
@@ -154,6 +154,9 @@ struct Manager {
 
         /* Data specific to the D-Bus subsystem */
         DBusConnection *api_bus, *system_bus;
+        DBusServer *private_bus;
+        Set *bus_connections, *bus_connections_for_dispatch;
+
         Set *subscribed;
         DBusMessage *queued_message; /* This is used during reloading:
                                       * before the reload we queue the
@@ -188,9 +191,6 @@ struct Manager {
         bool dispatching_run_queue:1;
         bool dispatching_dbus_queue:1;
 
-        bool request_api_bus_dispatch:1;
-        bool request_system_bus_dispatch:1;
-
         bool utmp_reboot_written:1;
 
         bool confirm_spawn:1;
index 444ddf370c4ead051985dfab198f7b9ae5675ed9..429d6a7a21440cf5bb13c55f0140428da36ef32c 100644 (file)
@@ -1751,7 +1751,6 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
         optind = argc;
 
         return 1;
-
 }
 
 static int telinit_parse_argv(int argc, char *argv[]) {
@@ -2262,7 +2261,13 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
-        if ((bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error)))
+        /* If we are root, then let's not go via the bus */
+        if (geteuid() == 0 && !arg_session)
+                bus = dbus_connection_open("unix:abstract=/org/freedesktop/systemd1/private", &error);
+        else
+                bus = dbus_bus_get(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error);
+
+        if (bus)
                 dbus_connection_set_exit_on_disconnect(bus, FALSE);
 
         switch (arg_action) {
index 327444bba4d087f7b76b154506b498061111a4c5..c12c2a7deb3fa02b7f297e8d91137ce655401287 100644 (file)
@@ -1030,8 +1030,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) {
                         /* The bus just might have become available,
                          * hence try to connect to it, if we aren't
                          * yet connected. */
-                        bus_init_system(u->meta.manager);
-                        bus_init_api(u->meta.manager);
+                        bus_init(u->meta.manager);
                 }
 
                 if (unit_has_name(u, SPECIAL_SYSLOG_SERVICE))
index 3397d472cbf8b6cf873983b5fc1a741acc77a1ff..c5be858923ceaa3f90b84da19ddfdb2ee5ff6d60 100644 (file)
@@ -296,7 +296,7 @@ struct UnitVTable {
         void (*bus_query_pid_done)(Unit *u, const char *name, pid_t pid);
 
         /* Called for each message received on the bus */
-        DBusHandlerResult (*bus_message_handler)(Unit *u, DBusMessage *message);
+        DBusHandlerResult (*bus_message_handler)(Unit *u, DBusConnection *c, DBusMessage *message);
 
         /* This is called for each unit type and should be used to
          * enumerate existing devices and load them. However,