diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-29 09:17:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-29 09:17:43 +0200 |
commit | a27c229c15830895d712ab338a22ef0ec4564ce2 (patch) | |
tree | 059e4d0707a8200f679190f9c9a96de4ba3068c8 /src/systemctl | |
parent | 30f194001ff647280ad49b68597c223e57ad7f6e (diff) | |
parent | 22d0f9a7d8e631cf0ed8f90bc2c45e4b04c4d2cb (diff) | |
download | systemd-a27c229c15830895d712ab338a22ef0ec4564ce2.tar.gz |
Merge pull request #21172 from poettering/fix-systemctl-cgroup-tree
fix "sytemctl status" cgroup tree output
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl-show.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 1c49158d83..6166260d10 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" @@ -710,14 +711,10 @@ static void print_status_info( printf(" CGroup: %s\n", i->control_group); - c = columns(); - if (c > sizeof(prefix) - 1) - c -= sizeof(prefix) - 1; - else - c = 0; + c = LESS_BY(columns(), strlen(prefix)); r = unit_show_processes(bus, i->id, i->control_group, prefix, c, get_output_flags(), &error); - if (r == -EBADR) { + if (r == -EBADR && arg_transport == BUS_TRANSPORT_LOCAL) { unsigned k = 0; pid_t extra[2]; @@ -2065,8 +2062,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(); @@ -2096,7 +2095,7 @@ static int show_system_status(sd_bus *bus) { off = ansi_normal(); } - printf("%s%s%s %s\n", on, special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE), off, arg_host ? arg_host : hn); + printf("%s%s%s %s\n", on, special_glyph(SPECIAL_GLYPH_BLACK_CIRCLE), off, arg_host ?: hn); printf(" State: %s%s%s\n", on, strna(mi.state), off); @@ -2108,21 +2107,16 @@ static int show_system_status(sd_bus *bus) { FORMAT_TIMESTAMP_STYLE(mi.timestamp, arg_timestamp_style), FORMAT_TIMESTAMP_RELATIVE(mi.timestamp)); - printf(" CGroup: %s\n", mi.control_group ?: "/"); - if (IN_SET(arg_transport, - BUS_TRANSPORT_LOCAL, - BUS_TRANSPORT_MACHINE)) { - static const char prefix[] = " "; - unsigned c; + printf(" CGroup: %s\n", empty_to_root(mi.control_group)); - c = columns(); - if (c > sizeof(prefix) - 1) - c -= sizeof(prefix) - 1; - else - c = 0; + 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; } |