]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Merge pull request #1828 from fbuihuu/set-property-on-inactive-unit
authorLennart Poettering <lennart@poettering.net>
Fri, 27 Nov 2015 13:00:57 +0000 (14:00 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 27 Nov 2015 13:00:57 +0000 (14:00 +0100)
core: allow 'SetUnitProperties()' to run on inactive units too

man/systemctl.xml
src/core/dbus-manager.c
src/core/dbus-unit.c
src/core/dbus-unit.h

index 755a74f9877b5a7509723d27ec4f77146419770e..1fb056874ce2650e4eaffeaee98b2513176127a5 100644 (file)
@@ -888,6 +888,11 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
 
             <para>Example: <command>systemctl set-property foobar.service CPUShares=777</command></para>
 
+            <para>If the specified unit appears to be inactive, the
+            changes will be only stored on disk as described
+            previously hence they will be effective when the unit will
+            be started.</para>
+
             <para>Note that this command allows changing multiple
             properties at the same time, which is preferable over
             setting them individually. Like unit file configuration
index 4d730290b2fb008885d7c04f31039e9326b73b08..2562396180934b1f6fb5990e631cf9b1de8ca670 100644 (file)
@@ -630,9 +630,13 @@ static int method_set_unit_properties(sd_bus_message *message, void *userdata, s
         if (r < 0)
                 return r;
 
-        u = manager_get_unit(m, name);
-        if (!u)
-                return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
+        r = manager_load_unit(m, name, NULL, error, &u);
+        if (r < 0)
+                return r;
+
+        r = bus_unit_check_load_state(u, error);
+        if (r < 0)
+                return r;
 
         return bus_unit_method_set_properties(message, u, error);
 }
index d9b7382c82b082b1b8913079303a7260477d5072..66b465a0b7a00026bfd843c12e681ba195f93848 100644 (file)
@@ -1251,3 +1251,20 @@ int bus_unit_set_properties(
 
         return n;
 }
+
+int bus_unit_check_load_state(Unit *u, sd_bus_error *error) {
+
+        if (u->load_state == UNIT_LOADED)
+                return 0;
+
+        /* Give a better description of the unit error when
+         * possible. Note that in the case of UNIT_MASKED, load_error
+         * is not set. */
+        if (u->load_state == UNIT_MASKED)
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit is masked.");
+
+        if (u->load_state == UNIT_NOT_FOUND)
+                return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit not found.");
+
+        return sd_bus_error_set_errnof(error, u->load_error, "Unit is not loaded properly: %m.");
+}
index b8c6ec398aee7bf9960aecba9f0e1e1cbfcdeb2c..ac9ee2d6b870e18bbc5641ce84a9bdd8013b30d6 100644 (file)
@@ -38,3 +38,5 @@ int bus_unit_method_reset_failed(sd_bus_message *message, void *userdata, sd_bus
 int bus_unit_queue_job(sd_bus_message *message, Unit *u, JobType type, JobMode mode, bool reload_if_possible, sd_bus_error *error);
 int bus_unit_set_properties(Unit *u, sd_bus_message *message, UnitSetPropertiesMode mode, bool commit, sd_bus_error *error);
 int bus_unit_method_set_properties(sd_bus_message *message, void *userdata, sd_bus_error *error);
+
+int bus_unit_check_load_state(Unit *u, sd_bus_error *error);