chiark / gitweb /
Use bus_maybe_send_reply() where applicable
[elogind.git] / src / core / dbus.c
index 9db172b6e692d5b6de52eb1d72bac9bb3530cac9..236ebc99d99804c5f1d7028c6dd31bf49403236d 100644 (file)
@@ -30,6 +30,7 @@
 #include "strv.h"
 #include "cgroup.h"
 #include "mkdir.h"
+#include "missing.h"
 #include "dbus-unit.h"
 #include "dbus-job.h"
 #include "dbus-manager.h"
@@ -405,7 +406,7 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
         dbus_error_free(&error);
 
         if (reply) {
-                if (!dbus_connection_send(connection, reply, NULL))
+                if (!bus_maybe_send_reply(connection, message, reply))
                         goto oom;
 
                 dbus_message_unref(reply);
@@ -444,7 +445,7 @@ static DBusHandlerResult system_bus_message_filter(DBusConnection *connection, D
                 log_debug("System D-Bus connection terminated.");
                 bus_done_system(m);
 
-        } else if (m->running_as != MANAGER_SYSTEM &&
+        } else if (m->running_as != SYSTEMD_SYSTEM &&
                    dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) {
 
                 const char *cgroup;
@@ -480,7 +481,7 @@ static DBusHandlerResult private_bus_message_filter(DBusConnection *connection,
 
         if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected"))
                 shutdown_connection(m, connection);
-        else if (m->running_as == MANAGER_SYSTEM &&
+        else if (m->running_as == SYSTEMD_SYSTEM &&
                  dbus_message_is_signal(message, "org.freedesktop.systemd1.Agent", "Released")) {
 
                 const char *cgroup;
@@ -775,7 +776,7 @@ static int init_registered_system_bus(Manager *m) {
         if (!dbus_connection_add_filter(m->system_bus, system_bus_message_filter, m, NULL))
                 return log_oom();
 
-        if (m->running_as != MANAGER_SYSTEM) {
+        if (m->running_as != SYSTEMD_SYSTEM) {
                 DBusError error;
 
                 dbus_error_init(&error);
@@ -837,7 +838,7 @@ static int init_registered_api_bus(Manager *m) {
         if (r < 0)
                 return r;
 
-        if (m->running_as == MANAGER_USER) {
+        if (m->running_as == SYSTEMD_USER) {
                 char *id;
                 log_debug("Successfully connected to API D-Bus bus %s as %s",
                          strnull((id = dbus_connection_get_server_id(m->api_bus))),
@@ -888,7 +889,7 @@ static void bus_register_cb(DBusPendingCall *pending, void *userdata) {
 
                 if (conn == &m->system_bus) {
                         r = init_registered_system_bus(m);
-                        if (r == 0 && m->running_as == MANAGER_SYSTEM)
+                        if (r == 0 && m->running_as == SYSTEMD_SYSTEM)
                                 r = init_registered_api_bus(m);
                 } else
                         r = init_registered_api_bus(m);
@@ -955,12 +956,12 @@ static DBusConnection* manager_bus_connect_private(Manager *m, DBusBusType type)
 
         switch (type) {
         case DBUS_BUS_SYSTEM:
-                address = getenv("DBUS_SYSTEM_BUS_ADDRESS");
+                address = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS");
                 if (!address || !address[0])
                         address = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS;
                 break;
         case DBUS_BUS_SESSION:
-                address = getenv("DBUS_SESSION_BUS_ADDRESS");
+                address = secure_getenv("DBUS_SESSION_BUS_ADDRESS");
                 if (!address || !address[0])
                         address = DBUS_SESSION_BUS_DEFAULT_ADDRESS;
                 break;
@@ -1018,7 +1019,7 @@ static int bus_init_api(Manager *m) {
         if (m->api_bus)
                 return 0;
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (m->running_as == SYSTEMD_SYSTEM) {
                 m->api_bus = m->system_bus;
                 /* In this mode there is no distinct connection to the API bus,
                  * the API is published on the system bus.
@@ -1065,7 +1066,7 @@ static int bus_init_private(Manager *m) {
         if (m->private_bus)
                 return 0;
 
-        if (m->running_as == MANAGER_SYSTEM) {
+        if (m->running_as == SYSTEMD_SYSTEM) {
 
                 /* We want the private bus only when running as init */
                 if (getpid() != 1)
@@ -1076,18 +1077,33 @@ static int bus_init_private(Manager *m) {
         } else {
                 const char *e;
                 char *p;
+                char *escaped;
 
-                e = getenv("XDG_RUNTIME_DIR");
+                e = secure_getenv("XDG_RUNTIME_DIR");
                 if (!e)
                         return 0;
 
-                if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) {
+                if (asprintf(&p, "%s/systemd/private", e) < 0) {
                         r = log_oom();
                         goto fail;
                 }
 
-                mkdir_parents_label(p+10, 0755);
-                unlink(p+10);
+                mkdir_parents_label(p, 0755);
+                unlink(p);
+                free(p);
+
+                escaped = dbus_address_escape_value(e);
+                if (!escaped) {
+                        r = log_oom();
+                        goto fail;
+                }
+                if (asprintf(&p, "unix:path=%s/systemd/private", escaped) < 0) {
+                        dbus_free(escaped);
+                        r = log_oom();
+                        goto fail;
+                }
+                dbus_free(escaped);
+
                 m->private_bus = dbus_server_listen(p, &error);
                 free(p);
         }
@@ -1189,7 +1205,7 @@ static void shutdown_connection(Manager *m, DBusConnection *c) {
 
         dbus_connection_set_dispatch_status_function(c, NULL, NULL, NULL);
         /* system manager cannot afford to block on DBus */
-        if (m->running_as != MANAGER_SYSTEM)
+        if (m->running_as != SYSTEMD_SYSTEM)
                 dbus_connection_flush(c);
         dbus_connection_close(c);
         dbus_connection_unref(c);
@@ -1199,7 +1215,7 @@ static void bus_done_api(Manager *m) {
         if (!m->api_bus)
                 return;
 
-        if (m->running_as == MANAGER_USER)
+        if (m->running_as == SYSTEMD_USER)
                 shutdown_connection(m, m->api_bus);
 
         m->api_bus = NULL;
@@ -1214,7 +1230,7 @@ static void bus_done_system(Manager *m) {
         if (!m->system_bus)
                 return;
 
-        if (m->running_as == MANAGER_SYSTEM)
+        if (m->running_as == SYSTEMD_SYSTEM)
                 bus_done_api(m);
 
         shutdown_connection(m, m->system_bus);
@@ -1361,11 +1377,11 @@ int bus_broadcast(Manager *m, DBusMessage *message) {
         assert(message);
 
         SET_FOREACH(c, m->bus_connections_for_dispatch, i)
-                if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
+                if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM)
                         oom = !dbus_connection_send(c, message, NULL);
 
         SET_FOREACH(c, m->bus_connections, i)
-                if (c != m->system_bus || m->running_as == MANAGER_SYSTEM)
+                if (c != m->system_bus || m->running_as == SYSTEMD_SYSTEM)
                         oom = !dbus_connection_send(c, message, NULL);
 
         return oom ? -ENOMEM : 0;
@@ -1436,6 +1452,8 @@ int bus_fdset_add_all(Manager *m, FDSet *fds) {
 
 void bus_broadcast_finished(
                 Manager *m,
+                usec_t firmware_usec,
+                usec_t loader_usec,
                 usec_t kernel_usec,
                 usec_t initrd_usec,
                 usec_t userspace_usec,
@@ -1453,6 +1471,8 @@ void bus_broadcast_finished(
 
         assert_cc(sizeof(usec_t) == sizeof(uint64_t));
         if (!dbus_message_append_args(message,
+                                      DBUS_TYPE_UINT64, &firmware_usec,
+                                      DBUS_TYPE_UINT64, &loader_usec,
                                       DBUS_TYPE_UINT64, &kernel_usec,
                                       DBUS_TYPE_UINT64, &initrd_usec,
                                       DBUS_TYPE_UINT64, &userspace_usec,