diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-02-09 16:51:03 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-02-09 16:53:09 +0100 |
commit | 9c6e3e1d3b9da444a16a7b484edf8be227f808e0 (patch) | |
tree | a6446eb9a0df4b816efd032e7c8e54ef01036e0b /src/cgtop | |
parent | Merge pull request #8083 from shawnl/close-ssh (diff) | |
download | systemd-9c6e3e1d3b9da444a16a7b484edf8be227f808e0.tar.xz systemd-9c6e3e1d3b9da444a16a7b484edf8be227f808e0.zip |
cgtop: correctly order root cgroup always to the top
Internally, we encode the root cgroup as empty string. However,
path_compare() is allergic to comparing absolute and relative paths.
Let's clean this up, by always uses "/" as path for the root cgroup when
comparing.
Diffstat (limited to 'src/cgtop')
-rw-r--r-- | src/cgtop/cgtop.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 1a73fb099d..c68b56568b 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -506,6 +506,10 @@ static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) return 0; } +static const char *empty_to_slash(const char *p) { + return isempty(p) ? "/" : p; +} + static int group_compare(const void*a, const void *b) { const Group *x = *(Group**)a, *y = *(Group**)b; @@ -515,9 +519,9 @@ static int group_compare(const void*a, const void *b) { * recursive summing is off, since that is actually * not accumulative for all children. */ - if (path_startswith(y->path, x->path)) + if (path_startswith(empty_to_slash(y->path), empty_to_slash(x->path))) return -1; - if (path_startswith(x->path, y->path)) + if (path_startswith(empty_to_slash(x->path), empty_to_slash(y->path))) return 1; } @@ -666,7 +670,7 @@ static void display(Hashmap *a) { g = array[j]; - path = isempty(g->path) ? "/" : g->path; + path = empty_to_slash(g->path); ellipsized = ellipsize(path, path_columns, 33); printf("%-*s", path_columns, ellipsized ?: path); |