diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-01 17:30:43 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-06-11 12:53:12 +0200 |
commit | e49da001c466d0d70ec5fb727bb6b886ba595c0f (patch) | |
tree | 6dc7c43a7a0a12588d5bdf3a92c5f731bda7d0b2 /src/core/dbus-unit.c | |
parent | c602fd0f194b48ac366010de82d788945aa69856 (diff) | |
download | systemd-e49da001c466d0d70ec5fb727bb6b886ba595c0f.tar.gz |
core: rename (and modernize) bus_unit_check_load_state() → bus_unit_validate_load_state()
Let's use a switch() statement, cover more cases with pretty messages.
Also let's rename it to "validate", as that's more specific that
"check", as it implies checking for a "valid"/"good" state, which is
what this function does.
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r-- | src/core/dbus-unit.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 150ccc024c..84065ac08c 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1712,22 +1712,30 @@ int bus_unit_set_properties( return n; } -int bus_unit_check_load_state(Unit *u, sd_bus_error *error) { +int bus_unit_validate_load_state(Unit *u, sd_bus_error *error) { assert(u); - if (u->load_state == UNIT_LOADED) - return 0; + /* Generates a pretty error if a unit isn't properly loaded. */ - /* 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 %s is masked.", u->id); + switch (u->load_state) { + + case UNIT_LOADED: + return 0; - if (u->load_state == UNIT_NOT_FOUND) + case UNIT_NOT_FOUND: return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not found.", u->id); - return sd_bus_error_set_errnof(error, u->load_error, "Unit %s is not loaded properly: %m.", u->id); + case UNIT_ERROR: /* Only show .load_error in UNIT_ERROR state */ + return sd_bus_error_set_errnof(error, u->load_error, "Unit %s failed to loaded properly: %m.", u->id); + + case UNIT_MASKED: + return sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit %s is masked.", u->id); + + case UNIT_STUB: + case UNIT_MERGED: + default: + return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unexpected load state of unit %s", u->id); + } } static int bus_unit_track_handler(sd_bus_track *t, void *userdata) { |