]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/dbus-unit.c
Introduce bus_unit_check_load_state() helper
[thirdparty/systemd.git] / src / core / dbus-unit.c
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.");
+}