Merge pull request #22649 from keszybz/symlink-enablement-yet-again-punish-me-harder

Fixups to the unit enablement logic
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-03-29 21:10:03 +02:00
committed by GitHub
78 changed files with 2503 additions and 1372 deletions
+7 -7
View File
@@ -37,9 +37,9 @@ 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(&lp, arg_scope, 0, arg_root);
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
if (r < 0)
return log_error_errno(r, "Failed to determine unit paths: %m");
return r;
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
@@ -99,7 +99,7 @@ int verb_cat(int argc, char *argv[], void *userdata) {
ansi_highlight_red(),
ansi_highlight_red(),
ansi_highlight_red(),
arg_scope == UNIT_FILE_SYSTEM ? "" : " --user",
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user",
ansi_normal());
r = cat_files(fragment_path, dropin_paths, 0);
@@ -406,8 +406,8 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
if (!path) {
if (!arg_force) {
log_info("Run 'systemctl edit%s --force --full %s' to create a new unit.",
arg_scope == UNIT_FILE_GLOBAL ? " --global" :
arg_scope == UNIT_FILE_USER ? " --user" : "",
arg_scope == LOOKUP_SCOPE_GLOBAL ? " --global" :
arg_scope == LOOKUP_SCOPE_USER ? " --user" : "",
*name);
return -ENOENT;
}
@@ -507,9 +507,9 @@ 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(&lp, arg_scope, 0, arg_root);
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
if (r < 0)
return log_error_errno(r, "Failed to determine unit paths: %m");
return r;
r = mac_selinux_init();
if (r < 0)
+1 -1
View File
@@ -141,7 +141,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(&lp, arg_scope, 0, arg_root);
r = lookup_paths_init_or_warn(&lp, arg_scope, 0, arg_root);
if (r < 0)
return r;
+1 -1
View File
@@ -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(UNIT_FILE_SYSTEM, flags, NULL, p, &changes, &n_changes);
r = unit_file_disable(LOOKUP_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);
+1 -1
View File
@@ -762,7 +762,7 @@ static void print_status_info(
getuid(),
get_output_flags() | OUTPUT_BEGIN_NEWLINE,
SD_JOURNAL_LOCAL_ONLY,
arg_scope == UNIT_FILE_SYSTEM,
arg_scope == LOOKUP_SCOPE_SYSTEM,
ellipsized);
if (i->need_daemon_reload)
+2 -2
View File
@@ -246,10 +246,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 != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Bad action for %s mode.",
arg_scope == UNIT_FILE_GLOBAL ? "--global" : "--user");
arg_scope == LOOKUP_SCOPE_GLOBAL ? "--global" : "--user");
return verb_start_special(argc, argv, userdata);
}
+3 -3
View File
@@ -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 == UNIT_FILE_SYSTEM ? "system" : "user",
arg_scope == UNIT_FILE_SYSTEM ? "" : " --user",
arg_scope == LOOKUP_SCOPE_SYSTEM ? "system" : "user",
arg_scope == LOOKUP_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 != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
extra_args[n++] = "--user";
if (arg_transport == BUS_TRANSPORT_REMOTE) {
+2 -2
View File
@@ -116,7 +116,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 != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
return 0;
if (getenv_bool("SYSTEMCTL_SKIP_SYSV") > 0)
@@ -128,7 +128,7 @@ int enable_sysv_units(const char *verb, char **args) {
"is-enabled"))
return 0;
r = lookup_paths_init(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
r = lookup_paths_init_or_warn(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
if (r < 0)
return r;
+5 -5
View File
@@ -46,7 +46,7 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
if (!buses[focus]) {
bool user;
user = arg_scope != UNIT_FILE_SYSTEM;
user = arg_scope != LOOKUP_SCOPE_SYSTEM;
if (focus == BUS_MANAGER)
r = bus_connect_transport_systemd(arg_transport, arg_host, user, &buses[focus]);
@@ -73,7 +73,7 @@ void ask_password_agent_open_maybe(void) {
if (arg_dry_run)
return;
if (arg_scope != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
return;
ask_password_agent_open_if_enabled(arg_transport, arg_ask_password);
@@ -82,7 +82,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 != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
return;
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
@@ -380,7 +380,7 @@ void warn_unit_file_changed(const char *unit) {
ansi_highlight_red(),
ansi_normal(),
unit,
arg_scope == UNIT_FILE_SYSTEM ? "" : " --user");
arg_scope == LOOKUP_SCOPE_SYSTEM ? "" : " --user");
}
int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **ret_unit_path) {
@@ -814,7 +814,7 @@ bool install_client_side(void) {
if (!isempty(arg_root))
return true;
if (arg_scope == UNIT_FILE_GLOBAL)
if (arg_scope == LOOKUP_SCOPE_GLOBAL)
return true;
/* Unsupported environment variable, mostly for debugging purposes */
+6 -6
View File
@@ -66,7 +66,7 @@ char **arg_properties = NULL;
bool arg_all = false;
enum dependency arg_dependency = DEPENDENCY_FORWARD;
const char *_arg_job_mode = NULL;
UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
LookupScope arg_scope = LOOKUP_SCOPE_SYSTEM;
bool arg_wait = false;
bool arg_no_block = false;
int arg_legend = -1; /* -1: true, unless --quiet is passed, 1: true */
@@ -616,15 +616,15 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
break;
case ARG_USER:
arg_scope = UNIT_FILE_USER;
arg_scope = LOOKUP_SCOPE_USER;
break;
case ARG_SYSTEM:
arg_scope = UNIT_FILE_SYSTEM;
arg_scope = LOOKUP_SCOPE_SYSTEM;
break;
case ARG_GLOBAL:
arg_scope = UNIT_FILE_GLOBAL;
arg_scope = LOOKUP_SCOPE_GLOBAL;
break;
case ARG_WAIT:
@@ -924,10 +924,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 != UNIT_FILE_SYSTEM)
if (arg_scope != LOOKUP_SCOPE_SYSTEM)
arg_ask_password = false;
if (arg_transport == BUS_TRANSPORT_REMOTE && arg_scope != UNIT_FILE_SYSTEM)
if (arg_transport == BUS_TRANSPORT_REMOTE && arg_scope != LOOKUP_SCOPE_SYSTEM)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Cannot access user instance remotely.");
+1 -1
View File
@@ -51,7 +51,7 @@ extern char **arg_properties;
extern bool arg_all;
extern enum dependency arg_dependency;
extern const char *_arg_job_mode;
extern UnitFileScope arg_scope;
extern LookupScope arg_scope;
extern bool arg_wait;
extern bool arg_no_block;
extern int arg_legend;