diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-02-07 23:42:10 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-02-09 09:18:53 +0100 |
commit | f9c76997db9f13bcae020f899adb81e17b926dc5 (patch) | |
tree | 3d5d0065090ade6ad2dc756d2e6195368e16b28c /src/systemctl/systemctl-enable.c | |
parent | systemctl: support disable/mask --now with unit template (diff) | |
download | systemd-f9c76997db9f13bcae020f899adb81e17b926dc5.tar.xz systemd-f9c76997db9f13bcae020f899adb81e17b926dc5.zip |
systemctl: allow --now only if not install_client_side()
Diffstat (limited to 'src/systemctl/systemctl-enable.c')
-rw-r--r-- | src/systemctl/systemctl-enable.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c index 4f5e1f119e..1904ecf949 100644 --- a/src/systemctl/systemctl-enable.c +++ b/src/systemctl/systemctl-enable.c @@ -66,6 +66,7 @@ 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]) @@ -140,7 +141,6 @@ 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 = {}; @@ -312,13 +312,18 @@ int verb_enable(int argc, char *argv[], void *userdata) { } } - if (arg_now && STR_IN_SET(argv[0], "enable", "disable", "mask")) { + if (arg_now) { _cleanup_strv_free_ char **new_args = NULL; - sd_bus *bus; - 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(); |