anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0372-Introduce-bus_unit_check_load_state-helper.patch

803fb7
From c55a7f9448378c10a7e8074db908502ae5ff60aa Mon Sep 17 00:00:00 2001
803fb7
From: Franck Bui <fbui@suse.com>
803fb7
Date: Fri, 13 Nov 2015 14:12:19 +0100
803fb7
Subject: [PATCH] Introduce bus_unit_check_load_state() helper
803fb7
803fb7
This function is used to check that a previous unit load succeed and
803fb7
returns 0 in this case.
803fb7
803fb7
In the case the load failed, the function setup a bus error
803fb7
accordingly and returns -errno.
803fb7
803fb7
(cherry picked from commit 000a996dc46c187f803b67b0b0d51ad4d0bc1658)
803fb7
Related: #1256858
803fb7
---
803fb7
 src/core/dbus-unit.c | 17 +++++++++++++++++
803fb7
 src/core/dbus-unit.h |  2 ++
803fb7
 2 files changed, 19 insertions(+)
803fb7
803fb7
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
803fb7
index 49770bfda..c3654db9e 100644
803fb7
--- a/src/core/dbus-unit.c
803fb7
+++ b/src/core/dbus-unit.c
803fb7
@@ -1083,3 +1083,20 @@ int bus_unit_set_properties(
803fb7
 
803fb7
         return n;
803fb7
 }
803fb7
+
803fb7
+int bus_unit_check_load_state(Unit *u, sd_bus_error *error) {
803fb7
+
803fb7
+        if (u->load_state == UNIT_LOADED)
803fb7
+                return 0;
803fb7
+
803fb7
+        /* Give a better description of the unit error when
803fb7
+         * possible. Note that in the case of UNIT_MASKED, load_error
803fb7
+         * is not set. */
803fb7
+        if (u->load_state == UNIT_MASKED)
803fb7
+                return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit is masked.");
803fb7
+
803fb7
+        if (u->load_state == UNIT_NOT_FOUND)
803fb7
+                return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit not found.");
803fb7
+
803fb7
+        return sd_bus_error_set_errnof(error, u->load_error, "Unit is not loaded properly: %m.");
803fb7
+}
803fb7
diff --git a/src/core/dbus-unit.h b/src/core/dbus-unit.h
803fb7
index 57a5e1974..433849641 100644
803fb7
--- a/src/core/dbus-unit.h
803fb7
+++ b/src/core/dbus-unit.h
803fb7
@@ -37,3 +37,5 @@ int bus_unit_method_reset_failed(sd_bus *bus, sd_bus_message *message, void *use
803fb7
 int bus_unit_queue_job(sd_bus *bus, sd_bus_message *message, Unit *u, JobType type, JobMode mode, bool reload_if_possible, sd_bus_error *error);
803fb7
 int bus_unit_set_properties(Unit *u, sd_bus_message *message, UnitSetPropertiesMode mode, bool commit, sd_bus_error *error);
803fb7
 int bus_unit_method_set_properties(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
803fb7
+
803fb7
+int bus_unit_check_load_state(Unit *u, sd_bus_error *error);