chiark / gitweb /
loginctl: suppress cgroup tree output if cgroup is empty
authorLennart Poettering <lennart@poettering.net>
Thu, 11 Jul 2013 17:14:38 +0000 (19:14 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 11 Jul 2013 17:14:38 +0000 (19:14 +0200)
same for machinectl

src/login/loginctl.c
src/machine/machinectl.c

index 93f4beed37da90f9e7be051fdea897d50ed82bd4..736db6a11b6d1919a6b4a0b4fd2207206afdf2d0 100644 (file)
@@ -35,8 +35,9 @@
 #include "build.h"
 #include "strv.h"
 #include "unit-name.h"
-#include "cgroup-show.h"
 #include "sysfs-show.h"
+#include "cgroup-show.h"
+#include "cgroup-util.h"
 #include "spawn-polkit-agent.h"
 
 static char **arg_property = NULL;
@@ -262,7 +263,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
         return 0;
 }
 
-static int show_unit_cgroup(DBusConnection *bus, const char *interface, const char *unit) {
+static int show_unit_cgroup(DBusConnection *bus, const char *interface, const char *unit, pid_t leader) {
         const char *property = "ControlGroup";
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         _cleanup_free_ char *path = NULL;
@@ -313,6 +314,12 @@ static int show_unit_cgroup(DBusConnection *bus, const char *interface, const ch
 
         dbus_message_iter_get_basic(&sub, &cgroup);
 
+        if (isempty(cgroup))
+                return 0;
+
+        if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup, false) != 0 && leader <= 0)
+                return 0;
+
         output_flags =
                 arg_all * OUTPUT_SHOW_ALL |
                 arg_full * OUTPUT_FULL_WIDTH;
@@ -323,7 +330,7 @@ static int show_unit_cgroup(DBusConnection *bus, const char *interface, const ch
         else
                 c = 0;
 
-        show_cgroup_by_path(cgroup, "\t\t  ", c, false, output_flags);
+        show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t  ", c, false, &leader, leader > 0, output_flags);
         return 0;
 }
 
@@ -441,7 +448,7 @@ static void print_session_status_info(DBusConnection *bus, SessionStatusInfo *i)
 
         if (i->scope) {
                 printf("\t    Unit: %s\n", i->scope);
-                show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i->scope);
+                show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i->scope, i->leader);
         }
 }
 
@@ -483,7 +490,7 @@ static void print_user_status_info(DBusConnection *bus, UserStatusInfo *i) {
 
         if (i->slice) {
                 printf("\t    Unit: %s\n", i->slice);
-                show_unit_cgroup(bus, "org.freedesktop.systemd1.Slice", i->slice);
+                show_unit_cgroup(bus, "org.freedesktop.systemd1.Slice", i->slice, 0);
         }
 }
 
index cd640e76aee59f1c0ceef60d0add77ee8e1715c1..97c2193551e65a05948e1e74a2e5f8d8ae91aad2 100644 (file)
@@ -36,6 +36,7 @@
 #include "strv.h"
 #include "unit-name.h"
 #include "cgroup-show.h"
+#include "cgroup-util.h"
 #include "spawn-polkit-agent.h"
 
 static char **arg_property = NULL;
@@ -125,7 +126,7 @@ static int list_machines(DBusConnection *bus, char **args, unsigned n) {
         return 0;
 }
 
-static int show_scope_cgroup(DBusConnection *bus, const char *unit) {
+static int show_scope_cgroup(DBusConnection *bus, const char *unit, pid_t leader) {
         const char *interface = "org.freedesktop.systemd1.Scope";
         const char *property = "ControlGroup";
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
@@ -177,6 +178,12 @@ static int show_scope_cgroup(DBusConnection *bus, const char *unit) {
 
         dbus_message_iter_get_basic(&sub, &cgroup);
 
+        if (isempty(cgroup))
+                return 0;
+
+        if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup, false) != 0 && leader <= 0)
+                return 0;
+
         output_flags =
                 arg_all * OUTPUT_SHOW_ALL |
                 arg_full * OUTPUT_FULL_WIDTH;
@@ -187,7 +194,7 @@ static int show_scope_cgroup(DBusConnection *bus, const char *unit) {
         else
                 c = 0;
 
-        show_cgroup_by_path(cgroup, "\t\t  ", c, false, output_flags);
+        show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t  ", c, false, &leader, leader > 0, output_flags);
         return 0;
 }
 
@@ -249,7 +256,7 @@ static void print_machine_status_info(DBusConnection *bus, MachineStatusInfo *i)
 
         if (i->scope) {
                 printf("\t    Unit: %s\n", i->scope);
-                show_scope_cgroup(bus, i->scope);
+                show_scope_cgroup(bus, i->scope, i->leader);
         }
 }