systemctl: make unit_is_masked always query manager
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user