chiark / gitweb /
bus: add new sd_bus_creds object to encapsulate process credentials
[elogind.git] / src / core / dbus-manager.c
index 6002d02..8f63721 100644 (file)
@@ -338,7 +338,13 @@ static int method_get_unit_by_pid(sd_bus *bus, sd_bus_message *message, void *us
                 return r;
 
         if (pid == 0) {
                 return r;
 
         if (pid == 0) {
-                r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+                _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+
+                r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
+                if (r < 0)
+                        return r;
+
+                r = sd_bus_creds_get_pid(creds, &pid);
                 if (r < 0)
                         return r;
         }
                 if (r < 0)
                         return r;
         }
@@ -1121,7 +1127,7 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
         if (!isempty(init)) {
                 ri = strdup(init);
                 if (!ri) {
         if (!isempty(init)) {
                 ri = strdup(init);
                 if (!ri) {
-                        free(ri);
+                        free(rt);
                         return -ENOMEM;
                 }
         }
                         return -ENOMEM;
                 }
         }
@@ -1132,6 +1138,8 @@ static int method_switch_root(sd_bus *bus, sd_bus_message *message, void *userda
         free(m->switch_root_init);
         m->switch_root_init = ri;
 
         free(m->switch_root_init);
         m->switch_root_init = ri;
 
+        m->exit_code = MANAGER_SWITCH_ROOT;
+
         return sd_bus_reply_method_return(message, NULL);
 }
 
         return sd_bus_reply_method_return(message, NULL);
 }
 
@@ -1532,7 +1540,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
         SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, firmware_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, loader_timestamp), 0),
         SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, firmware_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("LoaderTimestamp", offsetof(Manager, loader_timestamp), 0),
-        BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, firmware_timestamp), 0),
+        BUS_PROPERTY_DUAL_TIMESTAMP("KernelTimestamp", offsetof(Manager, kernel_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, initrd_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, userspace_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, finish_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("InitRDTimestamp", offsetof(Manager, initrd_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("UserspaceTimestamp", offsetof(Manager, userspace_timestamp), 0),
         BUS_PROPERTY_DUAL_TIMESTAMP("FinishTimestamp", offsetof(Manager, finish_timestamp), 0),
@@ -1622,7 +1630,7 @@ int bus_manager_foreach_client(Manager *m, int (*send_message)(sd_bus *bus, cons
         Iterator i;
         sd_bus *b;
         unsigned n;
         Iterator i;
         sd_bus *b;
         unsigned n;
-        int r;
+        int r, ret;
 
         n = set_size(m->subscribed);
         if (n <= 0)
 
         n = set_size(m->subscribed);
         if (n <= 0)
@@ -1634,17 +1642,22 @@ int bus_manager_foreach_client(Manager *m, int (*send_message)(sd_bus *bus, cons
                 return send_message(d->bus, isempty(d->name) ? NULL : d->name, userdata);
         }
 
                 return send_message(d->bus, isempty(d->name) ? NULL : d->name, userdata);
         }
 
+        ret = 0;
+
         /* Send to everybody */
         SET_FOREACH(b, m->private_buses, i) {
                 r = send_message(b, NULL, userdata);
                 if (r < 0)
         /* Send to everybody */
         SET_FOREACH(b, m->private_buses, i) {
                 r = send_message(b, NULL, userdata);
                 if (r < 0)
-                        return r;
+                        ret = r;
         }
 
         }
 
-        if (m->api_bus)
-                return send_message(m->api_bus, NULL, userdata);
+        if (m->api_bus) {
+                r = send_message(m->api_bus, NULL, userdata);
+                if (r < 0)
+                        ret = r;
+        }
 
 
-        return 0;
+        return ret;
 }
 
 static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
 }
 
 static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
@@ -1666,7 +1679,7 @@ static int send_finished(sd_bus *bus, const char *destination, void *userdata) {
         return sd_bus_send_to(bus, message, destination, NULL);
 }
 
         return sd_bus_send_to(bus, message, destination, NULL);
 }
 
-int bus_manager_send_finished(
+void bus_manager_send_finished(
                 Manager *m,
                 usec_t firmware_usec,
                 usec_t loader_usec,
                 Manager *m,
                 usec_t firmware_usec,
                 usec_t loader_usec,
@@ -1675,10 +1688,14 @@ int bus_manager_send_finished(
                 usec_t userspace_usec,
                 usec_t total_usec) {
 
                 usec_t userspace_usec,
                 usec_t total_usec) {
 
+        int r;
+
         assert(m);
 
         assert(m);
 
-        return bus_manager_foreach_client(m, send_finished,
-                        (usec_t[6]) { firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec });
+        r = bus_manager_foreach_client(m, send_finished,
+                                   (usec_t[6]) { firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec });
+        if (r < 0)
+                log_debug("Failed to send finished signal: %s", strerror(-r));
 }
 
 static int send_reloading(sd_bus *bus, const char *destination, void *userdata) {
 }
 
 static int send_reloading(sd_bus *bus, const char *destination, void *userdata) {
@@ -1698,8 +1715,13 @@ static int send_reloading(sd_bus *bus, const char *destination, void *userdata)
         return sd_bus_send_to(bus, message, destination, NULL);
 }
 
         return sd_bus_send_to(bus, message, destination, NULL);
 }
 
-int bus_manager_send_reloading(Manager *m, bool active) {
+void bus_manager_send_reloading(Manager *m, bool active) {
+        int r;
+
         assert(m);
 
         assert(m);
 
-        return bus_manager_foreach_client(m, send_reloading, INT_TO_PTR(active));
+        r = bus_manager_foreach_client(m, send_reloading, INT_TO_PTR(active));
+        if (r < 0)
+                log_debug("Failed to send reloading signal: %s", strerror(-r));
+
 }
 }