From fe37a784fc52b73e81006bd9d7fda62b326649cc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Jan 2018 19:01:44 +0100 Subject: [PATCH] cgtop: make sure we can show a tasks number for the root cgroup too Let's also use our new API in cgtop so that we can finally show a usable tasks count for the root cgroup too. Yay! --- src/cgtop/cgtop.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 17facf8..1a73fb0 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -40,6 +40,7 @@ #include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "procfs-util.h" #include "stdio-util.h" #include "strv.h" #include "terminal-util.h" @@ -194,21 +195,28 @@ static int process( g->n_tasks_valid = true; } else if (streq(controller, "pids") && arg_count == COUNT_PIDS) { - _cleanup_free_ char *p = NULL, *v = NULL; - r = cg_get_path(controller, path, "pids.current", &p); - if (r < 0) - return r; + if (isempty(path) || path_equal(path, "/")) { + r = procfs_tasks_get_current(&g->n_tasks); + if (r < 0) + return r; + } else { + _cleanup_free_ char *p = NULL, *v = NULL; - r = read_one_line_file(p, &v); - if (r == -ENOENT) - return 0; - if (r < 0) - return r; + r = cg_get_path(controller, path, "pids.current", &p); + if (r < 0) + return r; - r = safe_atou64(v, &g->n_tasks); - if (r < 0) - return r; + r = read_one_line_file(p, &v); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + + r = safe_atou64(v, &g->n_tasks); + if (r < 0) + return r; + } if (g->n_tasks > 0) g->n_tasks_valid = true; -- 2.7.4