chiark / gitweb /
bus: StartTransientUnit can have aux unit
authorWaLyong Cho <walyong.cho@samsung.com>
Mon, 8 Dec 2014 15:03:52 +0000 (00:03 +0900)
committerLennart Poettering <lennart@poettering.net>
Mon, 8 Dec 2014 15:28:54 +0000 (16:28 +0100)
src/core/dbus-manager.c

index 0994d7b..5fe06f9 100644 (file)
@@ -615,6 +615,90 @@ static int method_set_unit_properties(sd_bus *bus, sd_bus_message *message, void
         return bus_unit_method_set_properties(bus, message, u, error);
 }
 
+static int transient_unit_from_message(
+                Manager *m,
+                sd_bus_message *message,
+                const char *name,
+                Unit **unit,
+                sd_bus_error *error) {
+
+        Unit *u;
+        int r;
+
+        assert(m);
+        assert(message);
+        assert(name);
+
+        r = manager_load_unit(m, name, NULL, error, &u);
+        if (r < 0)
+                return r;
+
+        if (u->load_state != UNIT_NOT_FOUND ||
+            set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
+
+        /* OK, the unit failed to load and is unreferenced, now let's
+         * fill in the transient data instead */
+        r = unit_make_transient(u);
+        if (r < 0)
+                return r;
+
+        /* Set our properties */
+        r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
+        if (r < 0)
+                return r;
+
+        *unit = u;
+
+        return 0;
+}
+
+static int transient_aux_units_from_message(
+                Manager *m,
+                sd_bus_message *message,
+                sd_bus_error *error) {
+
+        Unit *u;
+        char *name = NULL;
+        int r;
+
+        assert(m);
+        assert(message);
+
+        r = sd_bus_message_enter_container(message, 'a', "(sa(sv))");
+        if (r < 0)
+                return r;
+
+        while ((r = sd_bus_message_enter_container(message, 'r', "sa(sv)")) > 0) {
+                if (r <= 0)
+                        return r;
+
+                r = sd_bus_message_read(message, "s", &name);
+                if (r < 0)
+                        return r;
+
+                r = transient_unit_from_message(m, message, name, &u, error);
+                if (r < 0 && r != -EEXIST)
+                        return r;
+
+                r = unit_load(u);
+                if (r < 0)
+                        return r;
+
+                r = sd_bus_message_exit_container(message);
+                if (r < 0)
+                        return r;
+        }
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_exit_container(message);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
         const char *name, *smode;
         Manager *m = userdata;
@@ -652,21 +736,11 @@ static int method_start_transient_unit(sd_bus *bus, sd_bus_message *message, voi
         if (r < 0)
                 return r;
 
-        r = manager_load_unit(m, name, NULL, error, &u);
-        if (r < 0)
-                return r;
-
-        if (u->load_state != UNIT_NOT_FOUND || set_size(u->dependencies[UNIT_REFERENCED_BY]) > 0)
-                return sd_bus_error_setf(error, BUS_ERROR_UNIT_EXISTS, "Unit %s already exists.", name);
-
-        /* OK, the unit failed to load and is unreferenced, now let's
-         * fill in the transient data instead */
-        r = unit_make_transient(u);
+        r = transient_unit_from_message(m, message, name, &u, error);
         if (r < 0)
                 return r;
 
-        /* Set our properties */
-        r = bus_unit_set_properties(u, message, UNIT_RUNTIME, false, error);
+        r = transient_aux_units_from_message(m, message, error);
         if (r < 0)
                 return r;