chiark / gitweb /
core: require cgroups filesystem to be available
[elogind.git] / src / core / dbus-unit.c
index 4d3e3cc9ec643e8a1c4b4e262f929e88398d99c2..07e7f20e6b185a7f92e8d45b779a3e6d565eb412 100644 (file)
 #include "strv.h"
 #include "path-util.h"
 #include "fileio.h"
-#include "dbus-unit.h"
-#include "dbus-manager.h"
 #include "bus-errors.h"
-#include "dbus-client-track.h"
+#include "dbus.h"
+#include "dbus-manager.h"
+#include "dbus-unit.h"
 
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_load_state, unit_load_state, UnitLoadState);
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_job_mode, job_mode, JobMode);
@@ -589,7 +589,7 @@ const sd_bus_vtable bus_unit_cgroup_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
-static int send_new_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_new_signal(sd_bus *bus, void *userdata) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_free_ char *p = NULL;
         Unit *u = userdata;
@@ -604,10 +604,10 @@ static int send_new_signal(sd_bus *bus, const char *destination, void *userdata)
 
         r = sd_bus_message_new_signal(
                         bus,
+                        &m,
                         "/org/freedesktop/systemd1",
                         "org.freedesktop.systemd1.Manager",
-                        "UnitNew",
-                        &m);
+                        "UnitNew");
         if (r < 0)
                 return r;
 
@@ -615,10 +615,10 @@ static int send_new_signal(sd_bus *bus, const char *destination, void *userdata)
         if (r < 0)
                 return r;
 
-        return sd_bus_send_to(bus, m, destination, NULL);
+        return sd_bus_send(bus, m, NULL);
 }
 
-static int send_changed_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_changed_signal(sd_bus *bus, void *userdata) {
         _cleanup_free_ char *p = NULL;
         Unit *u = userdata;
         int r;
@@ -627,7 +627,7 @@ static int send_changed_signal(sd_bus *bus, const char *destination, void *userd
         assert(u);
 
         p = unit_dbus_path(u);
-        if (!u)
+        if (!p)
                 return -ENOMEM;
 
         /* Send a properties changed signal. First for the specific
@@ -638,21 +638,13 @@ static int send_changed_signal(sd_bus *bus, const char *destination, void *userd
                         bus, p,
                         UNIT_VTABLE(u)->bus_interface,
                         NULL);
-        if (r < 0) {
-                log_warning("Failed to send out specific PropertiesChanged signal for %s: %s", u->id, strerror(-r));
+        if (r < 0)
                 return r;
-        }
 
-        r = sd_bus_emit_properties_changed_strv(
+        return sd_bus_emit_properties_changed_strv(
                         bus, p,
                         "org.freedesktop.systemd1.Unit",
                         NULL);
-        if (r < 0) {
-                log_warning("Failed to send out generic PropertiesChanged signal for %s: %s", u->id, strerror(-r));
-                return r;
-        }
-
-        return 0;
 }
 
 void bus_unit_send_change_signal(Unit *u) {
@@ -667,14 +659,14 @@ void bus_unit_send_change_signal(Unit *u) {
         if (!u->id)
                 return;
 
-        r = bus_manager_foreach_client(u->manager, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
+        r = bus_foreach_bus(u->manager, NULL, u->sent_dbus_new_signal ? send_changed_signal : send_new_signal, u);
         if (r < 0)
                 log_debug("Failed to send unit change signal for %s: %s", u->id, strerror(-r));
 
         u->sent_dbus_new_signal = true;
 }
 
-static int send_removed_signal(sd_bus *bus, const char *destination, void *userdata) {
+static int send_removed_signal(sd_bus *bus, void *userdata) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         _cleanup_free_ char *p = NULL;
         Unit *u = userdata;
@@ -689,10 +681,10 @@ static int send_removed_signal(sd_bus *bus, const char *destination, void *userd
 
         r = sd_bus_message_new_signal(
                         bus,
+                        &m,
                         "/org/freedesktop/systemd1",
                         "org.freedesktop.systemd1.Manager",
-                        "UnitRemoved",
-                        &m);
+                        "UnitRemoved");
         if (r < 0)
                 return r;
 
@@ -700,7 +692,7 @@ static int send_removed_signal(sd_bus *bus, const char *destination, void *userd
         if (r < 0)
                 return r;
 
-        return sd_bus_send_to(bus, m, destination, NULL);
+        return sd_bus_send(bus, m, NULL);
 }
 
 void bus_unit_send_removed_signal(Unit *u) {
@@ -713,7 +705,7 @@ void bus_unit_send_removed_signal(Unit *u) {
         if (!u->id)
                 return;
 
-        r = bus_manager_foreach_client(u->manager, send_removed_signal, u);
+        r = bus_foreach_bus(u->manager, NULL, send_removed_signal, u);
         if (r < 0)
                 log_debug("Failed to send unit remove signal for %s: %s", u->id, strerror(-r));
 }
@@ -765,9 +757,17 @@ int bus_unit_queue_job(
         if (r < 0)
                 return r;
 
-        r = bus_client_track(&j->subscribed, bus, sd_bus_message_get_sender(message));
-        if (r < 0)
-                return r;
+        if (bus == u->manager->api_bus) {
+                if (!j->subscribed) {
+                        r = sd_bus_track_new(bus, &j->subscribed, NULL, NULL);
+                        if (r < 0)
+                                return r;
+                }
+
+                r = sd_bus_track_add_sender(j->subscribed, message);
+                if (r < 0)
+                        return r;
+        }
 
         path = job_dbus_path(j);
         if (!path)
@@ -813,7 +813,7 @@ static int bus_unit_set_transient_property(
                 if (r < 0)
                         return r;
 
-                if (!unit_name_is_valid(s, false) || !endswith(s, ".slice"))
+                if (!unit_name_is_valid(s, TEMPLATE_INVALID) || !endswith(s, ".slice"))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid slice name %s", s);
 
                 if (isempty(s)) {
@@ -865,7 +865,7 @@ static int bus_unit_set_transient_property(
                         return r;
 
                 while ((r = sd_bus_message_read(message, "s", &other)) > 0) {
-                        if (!unit_name_is_valid(other, false))
+                        if (!unit_name_is_valid(other, TEMPLATE_INVALID))
                                 return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid unit name %s", other);
 
                         if (mode != UNIT_CHECK) {
@@ -910,9 +910,6 @@ int bus_unit_set_properties(
         assert(u);
         assert(message);
 
-        if (u->transient)
-                mode &= UNIT_RUNTIME;
-
         /* We iterate through the array twice. First run we just check
          * if all passed data is valid, second run actually applies
          * it. This is to implement transaction-like behaviour without