summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-27 14:00:57 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-27 14:00:57 +0100
commit2281b56044ac36c1eec0bfc61cf3b172bc9d52b9 (patch)
tree4e6dd3dfa69989bbee54699aea9c31daedf2fee9 /src
parenta8273d12532450cf1c7120e650e3df58f60dd704 (diff)
parente9fd88f2e9a2effb7bcc1541a66263a5f97ce0a6 (diff)
Merge pull request #1828 from fbuihuu/set-property-on-inactive-unit
core: allow 'SetUnitProperties()' to run on inactive units too
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-manager.c10
-rw-r--r--src/core/dbus-unit.c17
-rw-r--r--src/core/dbus-unit.h2
3 files changed, 26 insertions, 3 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 4d730290b2..2562396180 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -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);
}
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index d9b7382c82..66b465a0b7 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -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.");
+}
diff --git a/src/core/dbus-unit.h b/src/core/dbus-unit.h
index b8c6ec398a..ac9ee2d6b8 100644
--- a/src/core/dbus-unit.h
+++ b/src/core/dbus-unit.h
@@ -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);