summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-enable.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:45 +0000
commitefeb864cb547a2cbf96dc0053a8bdb4d9190b364 (patch)
treec0b83368f18be983fcc763200c4c24d633244588 /src/systemctl/systemctl-enable.c
parentReleasing progress-linux version 255.5-1~progress7.99u1. (diff)
downloadsystemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.tar.xz
systemd-efeb864cb547a2cbf96dc0053a8bdb4d9190b364.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/systemctl/systemctl-enable.c')
-rw-r--r--src/systemctl/systemctl-enable.c61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c
index 7d9b7c7..496a817 100644
--- a/src/systemctl/systemctl-enable.c
+++ b/src/systemctl/systemctl-enable.c
@@ -66,12 +66,14 @@ int verb_enable(int argc, char *argv[], void *userdata) {
const char *verb = argv[0];
int carries_install_info = -1;
bool ignore_carries_install_info = arg_quiet || arg_no_warn;
+ sd_bus *bus = NULL;
int r;
if (!argv[1])
return 0;
- r = mangle_names("to enable", strv_skip(argv, 1), &names);
+ const char *operation = strjoina("to ", verb);
+ r = mangle_names(operation, strv_skip(argv, 1), &names);
if (r < 0)
return r;
@@ -140,10 +142,9 @@ int verb_enable(int argc, char *argv[], void *userdata) {
bool send_runtime = true, send_force = true, send_preset_mode = false;
const char *method, *warn_trigger_operation = NULL;
bool warn_trigger_ignore_masked = true; /* suppress "used uninitialized" warning */
- sd_bus *bus;
if (STR_IN_SET(verb, "mask", "unmask")) {
- _cleanup_(lookup_paths_free) LookupPaths lp = {};
+ _cleanup_(lookup_paths_done) LookupPaths lp = {};
r = lookup_paths_init_or_warn(&lp, arg_runtime_scope, 0, arg_root);
if (r < 0)
@@ -312,25 +313,51 @@ int verb_enable(int argc, char *argv[], void *userdata) {
}
}
- if (arg_now && STR_IN_SET(argv[0], "enable", "disable", "mask")) {
- sd_bus *bus;
- size_t len, i;
+ if (arg_now) {
+ _cleanup_strv_free_ char **new_args = NULL;
- r = acquire_bus(BUS_MANAGER, &bus);
- if (r < 0)
- return r;
+ if (!STR_IN_SET(verb, "enable", "disable", "mask"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "--now can only be used with verb enable, disable, or mask.");
+
+ if (install_client_side())
+ return log_error_errno(SYNTHETIC_ERRNO(EREMOTE),
+ "--now cannot be used when systemd is not running or in conjunction with --root=/--global, refusing.");
+
+ assert(bus);
+
+ if (strv_extend(&new_args, streq(verb, "enable") ? "start" : "stop") < 0)
+ return log_oom();
+
+ STRV_FOREACH(name, names) {
+ if (streq(verb, "enable")) {
+ char *fn;
- len = strv_length(names);
- {
- char *new_args[len + 2];
+ /* 'enable' accept path to unit files, so extract it first. Don't try to
+ * glob them though, as starting globbed unit seldom makes sense and
+ * actually changes the semantic (we're operating on DefaultInstance=
+ * when enabling). */
- new_args[0] = (char*) (streq(argv[0], "enable") ? "start" : "stop");
- for (i = 0; i < len; i++)
- new_args[i + 1] = basename(names[i]);
- new_args[i + 1] = NULL;
+ r = path_extract_filename(*name, &fn);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract filename of '%s': %m", *name);
+
+ r = strv_consume(&new_args, fn);
+ } else if (unit_name_is_valid(*name, UNIT_NAME_TEMPLATE)) {
+ char *globbed;
+
+ r = unit_name_replace_instance_full(*name, "*", /* accept_glob = */ true, &globbed);
+ if (r < 0)
+ return log_error_errno(r, "Failed to glob unit name '%s': %m", *name);
- r = verb_start(len + 1, new_args, userdata);
+ r = strv_consume(&new_args, globbed);
+ } else
+ r = strv_extend(&new_args, *name);
+ if (r < 0)
+ return log_oom();
}
+
+ return verb_start(strv_length(new_args), new_args, userdata);
}
return 0;