diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-03-02 15:29:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-03-18 10:22:20 +0100 |
commit | 23484e120531c1013009e2b3c29e8a82e6a10f4c (patch) | |
tree | a91bf9ce4ba2e853177cf26db5924d876e66d466 /src/systemctl/systemctl-util.c | |
parent | 2cdd6bef9c940774d40046db9be41ea73cdb5d8e (diff) | |
download | systemd-23484e120531c1013009e2b3c29e8a82e6a10f4c.tar.gz |
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.
Diffstat (limited to 'src/systemctl/systemctl-util.c')
-rw-r--r-- | src/systemctl/systemctl-util.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c index acf2e477d3..8afd4b222a 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++; |