diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index e3f25d52d52..ac0bbb45429 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -318,7 +318,6 @@ int verb_edit(int argc, char *argv[], void *userdata) { .remove_parent = !arg_full, .overwrite_with_origin = true, }; - _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_strv_free_ char **names = NULL; sd_bus *bus; int r; @@ -329,10 +328,6 @@ int verb_edit(int argc, char *argv[], void *userdata) { if (arg_transport != BUS_TRANSPORT_LOCAL) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot edit units remotely."); - r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, arg_root); - if (r < 0) - return r; - r = mac_init(); if (r < 0) return r; @@ -348,7 +343,7 @@ int verb_edit(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "No units matched the specified patterns."); STRV_FOREACH(tmp, names) { - r = unit_is_masked(bus, &lp, *tmp); + r = unit_is_masked(bus, *tmp); if (r < 0) return r; if (r > 0) diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index 074bb8d83be..10df0087b44 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -624,25 +624,31 @@ static int unit_find_template_path( return r; } -int unit_is_masked(sd_bus *bus, LookupPaths *lp, const char *name) { +int unit_is_masked(sd_bus *bus, const char *unit) { _cleanup_free_ char *load_state = NULL; int r; - if (unit_name_is_valid(name, UNIT_NAME_TEMPLATE)) { - _cleanup_free_ char *path = NULL; + assert(bus); + assert(unit); - /* A template cannot be loaded, but it can be still masked, so - * we need to use a different method. */ + if (unit_name_is_valid(unit, UNIT_NAME_TEMPLATE)) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + const char *state; - r = unit_file_find_path(lp, name, &path); + r = bus_call_method(bus, bus_systemd_mgr, "GetUnitFileState", &error, &reply, "s", unit); if (r < 0) - return r; - if (r == 0) - return false; - return null_or_empty_path(path); + return log_debug_errno(r, "Failed to get UnitFileState for '%s': %s", + unit, bus_error_message(&error, r)); + + r = sd_bus_message_read(reply, "s", &state); + if (r < 0) + return bus_log_parse_error_debug(r); + + return STR_IN_SET(state, "masked", "masked-runtime"); } - r = unit_load_state(bus, name, &load_state); + r = unit_load_state(bus, unit, &load_state); if (r < 0) return r; diff --git a/src/systemctl/systemctl-util.h b/src/systemctl/systemctl-util.h index 317bab75b73..344075722ad 100644 --- a/src/systemctl/systemctl-util.h +++ b/src/systemctl/systemctl-util.h @@ -38,7 +38,7 @@ int maybe_extend_with_unit_dependencies(sd_bus *bus, char ***list); int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **ret_unit_path); int unit_find_paths(sd_bus *bus, const char *unit_name, LookupPaths *lp, bool force_client_side, Hashmap **cached_id_map, Hashmap **cached_name_map, char **ret_fragment_path, char ***ret_dropin_paths); -int unit_is_masked(sd_bus *bus, LookupPaths *lp, const char *name); +int unit_is_masked(sd_bus *bus, const char *unit); int unit_exists(LookupPaths *lp, const char *unit); int unit_get_dependencies(sd_bus *bus, const char *name, char ***ret);