diff options
author | Frantisek Sumsal <frantisek@sumsal.cz> | 2022-03-10 15:18:45 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2022-03-10 21:47:30 +0100 |
commit | 217d4a1164bda7f0ec7e47d8d3f59a3345971c90 (patch) | |
tree | 6cb996f9f6594de98e12de72ada32c11bbe66101 /src | |
parent | core: support ExtensionDirectories in user manager (diff) | |
download | systemd-217d4a1164bda7f0ec7e47d8d3f59a3345971c90.tar.xz systemd-217d4a1164bda7f0ec7e47d8d3f59a3345971c90.zip |
cgls: mangle user-provided unit names
so the CLI interface is now similar to `systemctl`, i.e. if no unit name
suffix is provided, assume `.service`.
Fixes: #20492
Before:
```
$ systemd-cgls --unit user@1000
Failed to query unit control group path: Invalid argument
Failed to list cgroup tree: Invalid argument
```
After:
```
$ build/systemd-cgls --unit user@1000
Unit user@1000.service (/user.slice/user-1000.slice/user@1000.service):
├─session.slice (#4939)
│ ├─pipewire-pulse.service (#5203)
│ │ └─7711 /usr/bin/pipewire-pulse
...
```
Diffstat (limited to 'src')
-rw-r--r-- | src/cgls/cgls.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index 775bd84ad2..936ea4d3af 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -208,7 +208,11 @@ static int run(int argc, char *argv[]) { if (arg_show_unit != SHOW_UNIT_NONE) { /* Command line arguments are unit names */ - _cleanup_free_ char *cgroup = NULL; + _cleanup_free_ char *cgroup = NULL, *unit_name = NULL; + + r = unit_name_mangle(*name, UNIT_NAME_MANGLE_WARN, &unit_name); + if (r < 0) + return log_error_errno(r, "Failed to mangle unit name: %m"); if (!bus) { /* Connect to the bus only if necessary */ @@ -219,16 +223,16 @@ static int run(int argc, char *argv[]) { return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL); } - q = show_cgroup_get_unit_path_and_warn(bus, *name, &cgroup); + q = show_cgroup_get_unit_path_and_warn(bus, unit_name, &cgroup); if (q < 0) goto failed; if (isempty(cgroup)) { - q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", *name); + q = log_warning_errno(SYNTHETIC_ERRNO(ENOENT), "Unit %s not found.", unit_name); goto failed; } - printf("Unit %s (%s):\n", *name, cgroup); + printf("Unit %s (%s):\n", unit_name, cgroup); fflush(stdout); q = show_cgroup_by_path(cgroup, NULL, 0, arg_output_flags); |