diff options
author | Franck Bui <fbui@suse.com> | 2015-11-13 14:12:19 +0100 |
---|---|---|
committer | Franck Bui <fbui@suse.com> | 2015-11-22 15:05:40 +0100 |
commit | 000a996dc46c187f803b67b0b0d51ad4d0bc1658 (patch) | |
tree | a3a91019b3ae6fa4926d92c9974add295c86039c /src/core/dbus-unit.c | |
parent | cf0f970fe1c6101b45cae8277c221c10398b8e1e (diff) |
Introduce bus_unit_check_load_state() helper
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.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r-- | src/core/dbus-unit.c | 17 |
1 files changed, 17 insertions, 0 deletions
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."); +} |