summaryrefslogtreecommitdiff
path: root/src/shared/cgroup-show.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-04-16 17:35:58 +0200
committerLennart Poettering <lennart@poettering.net>2012-04-16 18:59:08 +0200
commitc3175a7f40a2d2fabc3a2de63033a6810d45221a (patch)
tree60f589e8b66241145a03b7c65890cec649510f5d /src/shared/cgroup-show.c
parentc7b5eb98e8eeafe63a079ee3c51e9670872437ae (diff)
cgls: don't show empty cgroups by default
Diffstat (limited to 'src/shared/cgroup-show.c')
-rw-r--r--src/shared/cgroup-show.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 550a2f5f31..5b639e06c8 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -160,7 +160,7 @@ finish:
return r;
}
-int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns, bool kernel_threads) {
+int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns, bool kernel_threads, bool all) {
DIR *d;
char *last = NULL;
char *p1 = NULL, *p2 = NULL, *fn = NULL, *gn = NULL;
@@ -173,15 +173,31 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
if (!prefix)
prefix = "";
- if ((r = cg_fix_path(path, &fn)) < 0)
+ r = cg_fix_path(path, &fn);
+ if (r < 0)
return r;
- if (!(d = opendir(fn))) {
+ d = opendir(fn);
+ if (!d) {
free(fn);
return -errno;
}
while ((r = cg_read_subgroup(d, &gn)) > 0) {
+ char *k;
+
+ r = asprintf(&k, "%s/%s", fn, gn);
+ free(gn);
+
+ if (r < 0) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ if (!all && cg_is_empty_recursive(NULL, k, false) > 0) {
+ free(k);
+ continue;
+ }
if (!shown_pids) {
show_cgroup_one_by_path(path, prefix, n_columns, true, kernel_threads);
@@ -191,25 +207,20 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
if (last) {
printf("%s\342\224\234 %s\n", prefix, file_name_from_path(last));
- if (!p1)
- if (!(p1 = strappend(prefix, "\342\224\202 "))) {
+ if (!p1) {
+ p1 = strappend(prefix, "\342\224\202 ");
+ if (!p1) {
+ free(k);
r = -ENOMEM;
goto finish;
}
+ }
- show_cgroup_by_path(last, p1, n_columns-2, kernel_threads);
-
+ show_cgroup_by_path(last, p1, n_columns-2, kernel_threads, all);
free(last);
- last = NULL;
}
- r = asprintf(&last, "%s/%s", fn, gn);
- free(gn);
-
- if (r < 0) {
- r = -ENOMEM;
- goto finish;
- }
+ last = k;
}
if (r < 0)
@@ -221,13 +232,15 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
if (last) {
printf("%s\342\224\224 %s\n", prefix, file_name_from_path(last));
- if (!p2)
- if (!(p2 = strappend(prefix, " "))) {
+ if (!p2) {
+ p2 = strappend(prefix, " ");
+ if (!p2) {
r = -ENOMEM;
goto finish;
}
+ }
- show_cgroup_by_path(last, p2, n_columns-2, kernel_threads);
+ show_cgroup_by_path(last, p2, n_columns-2, kernel_threads, all);
}
r = 0;
@@ -243,7 +256,7 @@ finish:
return r;
}
-int show_cgroup(const char *controller, const char *path, const char *prefix, unsigned n_columns, bool kernel_threads) {
+int show_cgroup(const char *controller, const char *path, const char *prefix, unsigned n_columns, bool kernel_threads, bool all) {
char *p;
int r;
@@ -254,7 +267,7 @@ int show_cgroup(const char *controller, const char *path, const char *prefix, un
if (r < 0)
return r;
- r = show_cgroup_by_path(p, prefix, n_columns, kernel_threads);
+ r = show_cgroup_by_path(p, prefix, n_columns, kernel_threads, all);
free(p);
return r;