From: Zbigniew Jędrzejewski-Szmek Date: Wed, 2 Mar 2022 14:29:45 +0000 (+0100) Subject: systemctl: fix operations on relative paths X-Git-Tag: v251-rc1~104 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23484e120531c1013009e2b3c29e8a82e6a10f4c;p=thirdparty%2Fsystemd.git systemctl: fix operations on relative paths We should treat ./some.service and $PWD/some.service as equivalent. But we'd try to send the relative paths over dbus, which can't work well: $ sudo systemctl enable ./test2.service Failed to look up unit file state: Invalid argument $ sudo systemctl enable $PWD/test2.service Created symlink /etc/systemd/system/multi-user.target.wants/test2.service → /home/zbyszek/src/systemd/test2.service. Created symlink /etc/systemd/system/test2.service → /home/zbyszek/src/systemd/test2.service. Now both are equivalent. --- diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index acf2e477d3a..8afd4b222ac 100644 --- a/src/systemctl/systemctl-util.c +++ b/src/systemctl/systemctl-util.c @@ -873,18 +873,15 @@ int mangle_names(const char *operation, char **original_names, char ***ret_mangl /* When enabling units qualified path names are OK, too, hence allow them explicitly. */ - if (is_path(*name)) { - *i = strdup(*name); - if (!*i) - return log_oom(); - } else { + if (is_path(*name)) + r = path_make_absolute_cwd(*name, i); + else r = unit_name_mangle_with_suffix(*name, operation, arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN, ".service", i); - if (r < 0) { - *i = NULL; - return log_error_errno(r, "Failed to mangle unit name: %m"); - } + if (r < 0) { + *i = NULL; + return log_error_errno(r, "Failed to mangle unit name or path '%s': %m", *name); } i++;