diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-02-24 17:52:58 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-02-24 17:52:58 +0100 |
commit | b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c (patch) | |
tree | 14313f0bd5cd2dad79fda852663d9038f81a35ad /src/cgtop | |
parent | cgroup-util: check unified_cache before invoking streq() (diff) | |
download | systemd-b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c.tar.xz systemd-b4cccbc13ad6f98bd8e816ce5fffb99f5be74c8c.zip |
cgroup: change cg_unified() to possibly return errors again
We use our cgroup APIs in various contexts, including from our libraries
sd-login, sd-bus. As we don#t control those environments we can't rely
that the unified cgroup setup logic succeeds, and hence really shouldn't
assert on it.
This more or less reverts 415fc41ceaeada2e32639f24f134b1c248b9e43f.
Diffstat (limited to 'src/cgtop')
-rw-r--r-- | src/cgtop/cgtop.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 45c050c9c3..a1c0f48c89 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -133,12 +133,16 @@ static int process( Group **ret) { Group *g; - int r; + int r, all_unified; assert(controller); assert(path); assert(a); + all_unified = cg_all_unified(); + if (all_unified < 0) + return all_unified; + g = hashmap_get(a, path); if (!g) { g = hashmap_get(b, path); @@ -214,7 +218,7 @@ static int process( uint64_t new_usage; nsec_t timestamp; - if (cg_all_unified()) { + if (all_unified) { const char *keys[] = { "usage_usec", NULL }; _cleanup_free_ char *val = NULL; @@ -274,10 +278,10 @@ static int process( } else if (streq(controller, "memory")) { _cleanup_free_ char *p = NULL, *v = NULL; - if (!cg_all_unified()) - r = cg_get_path(controller, path, "memory.usage_in_bytes", &p); - else + if (all_unified) r = cg_get_path(controller, path, "memory.current", &p); + else + r = cg_get_path(controller, path, "memory.usage_in_bytes", &p); if (r < 0) return r; @@ -294,14 +298,14 @@ static int process( if (g->memory > 0) g->memory_valid = true; - } else if ((streq(controller, "io") && cg_all_unified()) || - (streq(controller, "blkio") && !cg_all_unified())) { + } else if ((streq(controller, "io") && all_unified) || + (streq(controller, "blkio") && !all_unified)) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; uint64_t wr = 0, rd = 0; nsec_t timestamp; - r = cg_get_path(controller, path, cg_all_unified() ? "io.stat" : "blkio.io_service_bytes", &p); + r = cg_get_path(controller, path, all_unified ? "io.stat" : "blkio.io_service_bytes", &p); if (r < 0) return r; @@ -324,7 +328,7 @@ static int process( l += strcspn(l, WHITESPACE); l += strspn(l, WHITESPACE); - if (cg_all_unified()) { + if (all_unified) { while (!isempty(l)) { if (sscanf(l, "rbytes=%" SCNu64, &k)) rd += k; |