summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-12-23 11:56:13 +0100
committerLennart Poettering <lennart@poettering.net>2012-12-24 00:29:39 +0100
commitb08121d00467874ac9aa0dc6f59787877f1bb427 (patch)
tree02ec43591a75af54925396411ada914dabe01e22 /src
parent81dc4bde12acd0a59ad96a505dbb109a9e4f320e (diff)
systemctl: don't show cgroup field for a unit if cgroup is empty
Diffstat (limited to 'src')
-rw-r--r--src/shared/cgroup-show.c8
-rw-r--r--src/shared/cgroup-util.c14
-rw-r--r--src/shared/cgroup-util.h1
-rw-r--r--src/systemctl/systemctl.c3
4 files changed, 19 insertions, 7 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 437d09711b..2b79f370f9 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -335,7 +335,7 @@ int show_cgroup_and_extra(const char *controller, const char *path, const char *
int show_cgroup_and_extra_by_spec(const char *spec, const char *prefix, unsigned n_columns, bool kernel_threads, bool all, const pid_t extra_pids[], unsigned n_extra_pids) {
int r;
- char *controller, *path;
+ _cleanup_free_ char *controller = NULL, *path = NULL;
assert(spec);
@@ -343,9 +343,5 @@ int show_cgroup_and_extra_by_spec(const char *spec, const char *prefix, unsigned
if (r < 0)
return r;
- r = show_cgroup_and_extra(controller, path, prefix, n_columns, kernel_threads, all, extra_pids, n_extra_pids);
- free(controller);
- free(path);
-
- return r;
+ return show_cgroup_and_extra(controller, path, prefix, n_columns, kernel_threads, all, extra_pids, n_extra_pids);
}
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index b0d378de5a..18cbf0412a 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -934,6 +934,20 @@ int cg_is_empty(const char *controller, const char *path, bool ignore_self) {
return !found;
}
+int cg_is_empty_by_spec(const char *spec, bool ignore_self) {
+ int r;
+ _cleanup_free_ char *controller = NULL, *path = NULL;
+
+ assert(spec);
+
+ r = cg_split_spec(spec, &controller, &path);
+ if (r < 0)
+ return r;
+
+ return cg_is_empty(controller, path, ignore_self);
+}
+
+
int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self) {
int r;
DIR *d = NULL;
diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h
index 697669deba..af2efc39b4 100644
--- a/src/shared/cgroup-util.h
+++ b/src/shared/cgroup-util.h
@@ -65,6 +65,7 @@ int cg_set_task_access(const char *controller, const char *path, mode_t mode, ui
int cg_install_release_agent(const char *controller, const char *agent);
int cg_is_empty(const char *controller, const char *path, bool ignore_self);
+int cg_is_empty_by_spec(const char *spec, bool ignore_self);
int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self);
int cg_get_user_path(char **path);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3abd7dc2e1..876e782e7d 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2265,7 +2265,8 @@ static void print_status_info(UnitStatusInfo *i) {
if (i->status_text)
printf("\t Status: \"%s\"\n", i->status_text);
- if (i->default_control_group) {
+ if (i->default_control_group &&
+ (i->main_pid > 0 || i->control_pid > 0 || cg_is_empty_by_spec(i->default_control_group, false) == 0)) {
unsigned c;
printf("\t CGroup: %s\n", i->default_control_group);