]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Introduce bus_unit_check_load_state() helper
authorFranck Bui <fbui@suse.com>
Fri, 13 Nov 2015 13:12:19 +0000 (14:12 +0100)
committerFranck Bui <fbui@suse.com>
Sun, 22 Nov 2015 14:05:40 +0000 (15:05 +0100)
This function is used to check that a previous unit load succeed and
returns 0 in this case.

In the case the load failed, the function setup a bus error
accordingly and returns -errno.

src/core/dbus-unit.c
src/core/dbus-unit.h

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 b622e0ae8d02de9bfcbd1fc6e2810decda07c897..0d7e5f8d834cd9d45d89c8ac94d6f79216bb3b8e 100644 (file)
@@ -37,3 +37,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);