if (r < 0)
return r;
- r = bus_unit_check_load_state(u, error);
+ r = bus_unit_validate_load_state(u, error);
if (r < 0)
return r;
if (r < 0)
return r;
- r = bus_unit_check_load_state(u, error);
+ r = bus_unit_validate_load_state(u, error);
if (r < 0)
return r;
if (r < 0)
return r;
- r = bus_unit_check_load_state(u, error);
+ r = bus_unit_validate_load_state(u, error);
if (r < 0)
return r;
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) {
int bus_unit_method_unref(sd_bus_message *message, void *userdata, sd_bus_error *error);
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_check_load_state(Unit *u, sd_bus_error *error);
+int bus_unit_validate_load_state(Unit *u, sd_bus_error *error);
int bus_unit_track_add_name(Unit *u, const char *name);
int bus_unit_track_add_sender(Unit *u, sd_bus_message *m);
return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->id);
if (type != JOB_STOP) {
- r = bus_unit_check_load_state(unit, e);
+ r = bus_unit_validate_load_state(unit, e);
if (r < 0)
return r;
}