From 23484e120531c1013009e2b3c29e8a82e6a10f4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 2 Mar 2022 15:29:45 +0100 Subject: [PATCH] systemctl: fix operations on relative paths MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- src/systemctl/systemctl-util.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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++; -- 2.47.3