basic: add RuntimeScope enum
In various tools and services we have a per-system and per-user concept. So far we sometimes used a boolean indicating whether we are in system mode, or a reversed boolean indicating whether we are in user mode, or the LookupScope enum used by the lookup path logic. Let's address that, in introduce a common enum for this, we can use all across the board. This is mostly just search/replace, no actual code changes.
This commit is contained in:
@@ -37,7 +37,7 @@ int verb_add_dependency(int argc, char *argv[], void *userdata) {
|
||||
assert_not_reached();
|
||||
|
||||
if (install_client_side()) {
|
||||
r = unit_file_add_dependency(arg_scope, unit_file_flags_from_args(), arg_root, names, target, dep, &changes, &n_changes);
|
||||
r = unit_file_add_dependency(arg_runtime_scope, unit_file_flags_from_args(), arg_root, names, target, dep, &changes, &n_changes);
|
||||
install_changes_dump(r, "add dependency on", changes, n_changes, arg_quiet);
|
||||
|
||||
if (r > 0)
|
||||
|
||||
@@ -37,7 +37,7 @@ int verb_cat(int argc, char *argv[], void *userdata) {
|
||||
if (arg_transport != BUS_TRANSPORT_LOCAL)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot remotely cat units.");
|
||||
|
||||
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
|
||||
r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -99,7 +99,7 @@ int verb_cat(int argc, char *argv[], void *userdata) {
|
||||
ansi_highlight_red(),
|
||||
ansi_highlight_red(),
|
||||
ansi_highlight_red(),
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user",
|
||||
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user",
|
||||
ansi_normal());
|
||||
|
||||
r = cat_files(fragment_path, dropin_paths, 0);
|
||||
@@ -452,7 +452,7 @@ static int find_paths_to_edit(
|
||||
if (!suffix)
|
||||
return log_oom();
|
||||
|
||||
r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
|
||||
r = lookup_paths_init(&lp, arg_runtime_scope, 0, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -478,8 +478,8 @@ static int find_paths_to_edit(
|
||||
if (!path) {
|
||||
if (!arg_force) {
|
||||
log_info("Run 'systemctl edit%s --force --full %s' to create a new unit.",
|
||||
arg_scope == LOOKUP_SCOPE_GLOBAL ? " --global" :
|
||||
arg_scope == LOOKUP_SCOPE_USER ? " --user" : "",
|
||||
arg_runtime_scope == RUNTIME_SCOPE_GLOBAL ? " --global" :
|
||||
arg_runtime_scope == RUNTIME_SCOPE_USER ? " --user" : "",
|
||||
*name);
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -595,7 +595,7 @@ 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_scope, 0, arg_root);
|
||||
r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -107,24 +107,24 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
|
||||
flags = unit_file_flags_from_args();
|
||||
if (streq(verb, "enable")) {
|
||||
r = unit_file_enable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_enable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "disable")) {
|
||||
r = unit_file_disable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_disable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "reenable")) {
|
||||
r = unit_file_reenable(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_reenable(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
carries_install_info = r;
|
||||
} else if (streq(verb, "link"))
|
||||
r = unit_file_link(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_link(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
else if (streq(verb, "preset"))
|
||||
r = unit_file_preset(arg_scope, flags, arg_root, names, arg_preset_mode, &changes, &n_changes);
|
||||
r = unit_file_preset(arg_runtime_scope, flags, arg_root, names, arg_preset_mode, &changes, &n_changes);
|
||||
else if (streq(verb, "mask"))
|
||||
r = unit_file_mask(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_mask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
else if (streq(verb, "unmask"))
|
||||
r = unit_file_unmask(arg_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_unmask(arg_runtime_scope, flags, arg_root, names, &changes, &n_changes);
|
||||
else if (streq(verb, "revert"))
|
||||
r = unit_file_revert(arg_scope, arg_root, names, &changes, &n_changes);
|
||||
r = unit_file_revert(arg_runtime_scope, arg_root, names, &changes, &n_changes);
|
||||
else
|
||||
assert_not_reached();
|
||||
|
||||
@@ -143,7 +143,7 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
if (STR_IN_SET(verb, "mask", "unmask")) {
|
||||
_cleanup_(lookup_paths_free) LookupPaths lp = {};
|
||||
|
||||
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
|
||||
r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -263,7 +263,7 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
" instance name specified.",
|
||||
special_glyph(SPECIAL_GLYPH_BULLET));
|
||||
|
||||
if (streq(verb, "disable") && arg_scope == LOOKUP_SCOPE_USER && !arg_quiet && !arg_no_warn) {
|
||||
if (streq(verb, "disable") && arg_runtime_scope == RUNTIME_SCOPE_USER && !arg_quiet && !arg_no_warn) {
|
||||
/* If some of the units are disabled in user scope but still enabled in global scope,
|
||||
* we emit a warning for that. */
|
||||
|
||||
@@ -272,7 +272,7 @@ int verb_enable(int argc, char *argv[], void *userdata) {
|
||||
STRV_FOREACH(name, names) {
|
||||
UnitFileState state;
|
||||
|
||||
r = unit_file_get_state(LOOKUP_SCOPE_GLOBAL, arg_root, *name, &state);
|
||||
r = unit_file_get_state(RUNTIME_SCOPE_GLOBAL, arg_root, *name, &state);
|
||||
if (r == -ENOENT)
|
||||
continue;
|
||||
if (r < 0)
|
||||
|
||||
@@ -18,7 +18,7 @@ static int show_installation_targets_client_side(const char *name) {
|
||||
flags = UNIT_FILE_DRY_RUN |
|
||||
(arg_runtime ? UNIT_FILE_RUNTIME : 0);
|
||||
|
||||
r = unit_file_disable(LOOKUP_SCOPE_SYSTEM, flags, NULL, p, &changes, &n_changes);
|
||||
r = unit_file_disable(RUNTIME_SCOPE_SYSTEM, flags, NULL, p, &changes, &n_changes);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get file links for %s: %m", name);
|
||||
|
||||
@@ -76,7 +76,7 @@ int verb_is_enabled(int argc, char *argv[], void *userdata) {
|
||||
STRV_FOREACH(name, names) {
|
||||
UnitFileState state;
|
||||
|
||||
r = unit_file_get_state(arg_scope, arg_root, *name, &state);
|
||||
r = unit_file_get_state(arg_runtime_scope, arg_root, *name, &state);
|
||||
if (r == -ENOENT) {
|
||||
if (!arg_quiet)
|
||||
puts("not-found");
|
||||
|
||||
@@ -100,7 +100,7 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) {
|
||||
if (show_preset_for_state(u->state)) {
|
||||
const char *unit_preset_str, *on_preset_color;
|
||||
|
||||
r = unit_file_query_preset(arg_scope, arg_root, id, &presets);
|
||||
r = unit_file_query_preset(arg_runtime_scope, arg_root, id, &presets);
|
||||
if (r < 0) {
|
||||
unit_preset_str = "n/a";
|
||||
on_preset_color = underline ? on_underline : ansi_normal();
|
||||
@@ -151,7 +151,7 @@ int verb_list_unit_files(int argc, char *argv[], void *userdata) {
|
||||
if (!h)
|
||||
return log_oom();
|
||||
|
||||
r = unit_file_get_list(arg_scope, arg_root, h, arg_states, strv_skip(argv, 1));
|
||||
r = unit_file_get_list(arg_runtime_scope, arg_root, h, arg_states, strv_skip(argv, 1));
|
||||
if (r < 0) {
|
||||
unit_file_list_free(h);
|
||||
return log_error_errno(r, "Failed to get unit file list: %m");
|
||||
|
||||
@@ -13,7 +13,7 @@ int verb_preset_all(int argc, char *argv[], void *userdata) {
|
||||
int r;
|
||||
|
||||
if (install_client_side()) {
|
||||
r = unit_file_preset_all(arg_scope, unit_file_flags_from_args(), arg_root, arg_preset_mode, &changes, &n_changes);
|
||||
r = unit_file_preset_all(arg_runtime_scope, unit_file_flags_from_args(), arg_root, arg_preset_mode, &changes, &n_changes);
|
||||
install_changes_dump(r, "preset", changes, n_changes, arg_quiet);
|
||||
|
||||
if (r > 0)
|
||||
|
||||
@@ -49,7 +49,7 @@ static int determine_default(char **ret_name) {
|
||||
int r;
|
||||
|
||||
if (install_client_side()) {
|
||||
r = unit_file_get_default(arg_scope, arg_root, ret_name);
|
||||
r = unit_file_get_default(arg_runtime_scope, arg_root, ret_name);
|
||||
if (r == -ERFKILL)
|
||||
return log_error_errno(r, "Failed to get default target: Unit file is masked.");
|
||||
if (r < 0)
|
||||
@@ -109,7 +109,7 @@ int verb_set_default(int argc, char *argv[], void *userdata) {
|
||||
return log_error_errno(r, "Failed to mangle unit name: %m");
|
||||
|
||||
if (install_client_side()) {
|
||||
r = unit_file_set_default(arg_scope, UNIT_FILE_FORCE, arg_root, unit, &changes, &n_changes);
|
||||
r = unit_file_set_default(arg_runtime_scope, UNIT_FILE_FORCE, arg_root, unit, &changes, &n_changes);
|
||||
install_changes_dump(r, "set default", changes, n_changes, arg_quiet);
|
||||
if (r < 0)
|
||||
goto finish;
|
||||
|
||||
@@ -817,7 +817,7 @@ static void print_status_info(
|
||||
getuid(),
|
||||
get_output_flags() | OUTPUT_BEGIN_NEWLINE,
|
||||
SD_JOURNAL_LOCAL_ONLY,
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM,
|
||||
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM,
|
||||
ellipsized);
|
||||
|
||||
if (i->need_daemon_reload)
|
||||
|
||||
@@ -235,10 +235,10 @@ int verb_start_special(int argc, char *argv[], void *userdata) {
|
||||
int verb_start_system_special(int argc, char *argv[], void *userdata) {
|
||||
/* Like start_special above, but raises an error when running in user mode */
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Bad action for %s mode.",
|
||||
arg_scope == LOOKUP_SCOPE_GLOBAL ? "--global" : "--user");
|
||||
arg_runtime_scope == RUNTIME_SCOPE_GLOBAL ? "--global" : "--user");
|
||||
|
||||
return verb_start_special(argc, argv, userdata);
|
||||
}
|
||||
|
||||
@@ -168,8 +168,8 @@ fail:
|
||||
BUS_ERROR_UNIT_MASKED,
|
||||
BUS_ERROR_JOB_TYPE_NOT_APPLICABLE))
|
||||
log_error("See %s logs and 'systemctl%s status%s %s' for details.",
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM ? "system" : "user",
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user",
|
||||
runtime_scope_to_string(arg_runtime_scope),
|
||||
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user",
|
||||
name[0] == '-' ? " --" : "",
|
||||
name);
|
||||
|
||||
@@ -242,7 +242,7 @@ static const char** make_extra_args(const char *extra_args[static 4]) {
|
||||
|
||||
assert(extra_args);
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
extra_args[n++] = "--user";
|
||||
|
||||
if (arg_transport == BUS_TRANSPORT_REMOTE) {
|
||||
|
||||
@@ -117,7 +117,7 @@ int enable_sysv_units(const char *verb, char **args) {
|
||||
|
||||
/* Processes all SysV units, and reshuffles the array so that afterwards only the native units remain */
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return 0;
|
||||
|
||||
if (getenv_bool("SYSTEMCTL_SKIP_SYSV") > 0)
|
||||
@@ -129,7 +129,7 @@ int enable_sysv_units(const char *verb, char **args) {
|
||||
"is-enabled"))
|
||||
return 0;
|
||||
|
||||
r = lookup_paths_init_or_warn(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
|
||||
r = lookup_paths_init_or_warn(&paths, arg_runtime_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -159,7 +159,7 @@ int enable_sysv_units(const char *verb, char **args) {
|
||||
if (path_is_absolute(name))
|
||||
continue;
|
||||
|
||||
j = unit_file_exists(arg_scope, &paths, name);
|
||||
j = unit_file_exists(arg_runtime_scope, &paths, name);
|
||||
if (j < 0 && !IN_SET(j, -ELOOP, -ERFKILL, -EADDRNOTAVAIL))
|
||||
return log_error_errno(j, "Failed to look up unit file state: %m");
|
||||
found_native = j != 0;
|
||||
|
||||
@@ -44,14 +44,10 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
|
||||
focus = BUS_FULL;
|
||||
|
||||
if (!buses[focus]) {
|
||||
bool user;
|
||||
|
||||
user = arg_scope != LOOKUP_SCOPE_SYSTEM;
|
||||
|
||||
if (focus == BUS_MANAGER)
|
||||
r = bus_connect_transport_systemd(arg_transport, arg_host, user, &buses[focus]);
|
||||
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_runtime_scope, &buses[focus]);
|
||||
else
|
||||
r = bus_connect_transport(arg_transport, arg_host, user, &buses[focus]);
|
||||
r = bus_connect_transport(arg_transport, arg_host, arg_runtime_scope, &buses[focus]);
|
||||
if (r < 0)
|
||||
return bus_log_connect_error(r, arg_transport);
|
||||
|
||||
@@ -73,7 +69,7 @@ void ask_password_agent_open_maybe(void) {
|
||||
if (arg_dry_run)
|
||||
return;
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return;
|
||||
|
||||
ask_password_agent_open_if_enabled(arg_transport, arg_ask_password);
|
||||
@@ -82,7 +78,7 @@ void ask_password_agent_open_maybe(void) {
|
||||
void polkit_agent_open_maybe(void) {
|
||||
/* Open the polkit agent as a child process if necessary */
|
||||
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return;
|
||||
|
||||
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
|
||||
@@ -408,7 +404,7 @@ void warn_unit_file_changed(const char *unit) {
|
||||
|
||||
log_warning("Warning: The unit file, source configuration file or drop-ins of %s changed on disk. Run 'systemctl%s daemon-reload' to reload units.",
|
||||
unit,
|
||||
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user");
|
||||
arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "" : " --user");
|
||||
}
|
||||
|
||||
int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **ret_unit_path) {
|
||||
@@ -844,7 +840,7 @@ bool install_client_side(void) {
|
||||
if (!isempty(arg_root))
|
||||
return true;
|
||||
|
||||
if (arg_scope == LOOKUP_SCOPE_GLOBAL)
|
||||
if (arg_runtime_scope == RUNTIME_SCOPE_GLOBAL)
|
||||
return true;
|
||||
|
||||
/* Unsupported environment variable, mostly for debugging purposes */
|
||||
|
||||
@@ -71,7 +71,7 @@ char **arg_properties = NULL;
|
||||
bool arg_all = false;
|
||||
enum dependency arg_dependency = DEPENDENCY_FORWARD;
|
||||
const char *_arg_job_mode = NULL;
|
||||
LookupScope arg_scope = LOOKUP_SCOPE_SYSTEM;
|
||||
RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
bool arg_wait = false;
|
||||
bool arg_no_block = false;
|
||||
int arg_legend = -1; /* -1: true, unless --quiet is passed, 1: true */
|
||||
@@ -646,15 +646,15 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_USER:
|
||||
arg_scope = LOOKUP_SCOPE_USER;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_USER;
|
||||
break;
|
||||
|
||||
case ARG_SYSTEM:
|
||||
arg_scope = LOOKUP_SCOPE_SYSTEM;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
|
||||
break;
|
||||
|
||||
case ARG_GLOBAL:
|
||||
arg_scope = LOOKUP_SCOPE_GLOBAL;
|
||||
arg_runtime_scope = RUNTIME_SCOPE_GLOBAL;
|
||||
break;
|
||||
|
||||
case ARG_WAIT:
|
||||
@@ -992,10 +992,10 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
|
||||
|
||||
/* If we are in --user mode, there's no point in talking to PolicyKit or the infra to query system
|
||||
* passwords */
|
||||
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
arg_ask_password = false;
|
||||
|
||||
if (arg_transport == BUS_TRANSPORT_REMOTE && arg_scope != LOOKUP_SCOPE_SYSTEM)
|
||||
if (arg_transport == BUS_TRANSPORT_REMOTE && arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Cannot access user instance remotely.");
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ extern char **arg_properties;
|
||||
extern bool arg_all;
|
||||
extern enum dependency arg_dependency;
|
||||
extern const char *_arg_job_mode;
|
||||
extern LookupScope arg_scope;
|
||||
extern RuntimeScope arg_runtime_scope;
|
||||
extern bool arg_wait;
|
||||
extern bool arg_no_block;
|
||||
extern int arg_legend;
|
||||
|
||||
Reference in New Issue
Block a user