.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;
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;
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)
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;
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);