diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-28 16:44:29 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-10-28 18:53:46 +0200 |
commit | 038cae098b6d85ad9fb06594d36f49915d32f000 (patch) | |
tree | 4caf9533aff0c0a81976d91ed9147591dc02dd3e /src/systemctl | |
parent | 35ac0260db7b896604d156e9638ad15700083508 (diff) | |
download | systemd-038cae098b6d85ad9fb06594d36f49915d32f000.tar.gz |
systemctl: make sure "systemctl -M status" shows cgroup tree of container not host
This shows the cgroup tree of the root slice of the container now, by
querying the cgroup pid tree via the bus instead of going directly to
the cgroupfs.
A fallback is kept for really old systemd versions where querying the
PID tree was not available.
Fixes: #20958
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl-show.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index af2d14d2c9..86803c5fc7 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -29,6 +29,7 @@ #include "process-util.h" #include "signal-util.h" #include "sort-util.h" +#include "special.h" #include "string-table.h" #include "systemctl-list-machines.h" #include "systemctl-list-units.h" @@ -2043,8 +2044,10 @@ static int show_all( static int show_system_status(sd_bus *bus) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(machine_info_clear) struct machine_info mi = {}; + static const char prefix[] = " "; _cleanup_free_ char *hn = NULL; const char *on, *off; + unsigned c; int r; hn = gethostname_malloc(); @@ -2087,16 +2090,15 @@ static int show_system_status(sd_bus *bus) { FORMAT_TIMESTAMP_RELATIVE(mi.timestamp)); printf(" CGroup: %s\n", empty_to_root(mi.control_group)); - if (IN_SET(arg_transport, - BUS_TRANSPORT_LOCAL, - BUS_TRANSPORT_MACHINE)) { - static const char prefix[] = " "; - unsigned c; - c = LESS_BY(columns(), strlen(prefix)); + c = LESS_BY(columns(), strlen(prefix)); + r = unit_show_processes(bus, SPECIAL_ROOT_SLICE, mi.control_group, prefix, c, get_output_flags(), &error); + if (r == -EBADR && arg_transport == BUS_TRANSPORT_LOCAL) /* Compatibility for really old systemd versions */ show_cgroup(SYSTEMD_CGROUP_CONTROLLER, strempty(mi.control_group), prefix, c, get_output_flags()); - } + else if (r < 0) + log_warning_errno(r, "Failed to dump process list for '%s', ignoring: %s", + arg_host ?: hn, bus_error_message(&error, r)); return 0; } |