a52f674
From f7feb791d476d2248c3f8df089092996262e9a23 Mon Sep 17 00:00:00 2001
930e1b8
From: Lennart Poettering <lennart@poettering.net>
930e1b8
Date: Tue, 5 Nov 2013 22:17:03 +0100
930e1b8
Subject: [PATCH] shutdown: trim the cgroup tree on loop iteration
930e1b8
930e1b8
This way we leave the cgroup empty before exiting in a container which
930e1b8
makes sure the container manager will get cgroup notification event
930e1b8
930e1b8
https://bugs.freedesktop.org/show_bug.cgi?id=68370
930e1b8
https://bugzilla.redhat.com/show_bug.cgi?id=988883
930e1b8
---
930e1b8
 src/core/shutdown.c | 16 +++++++++++++---
930e1b8
 1 file changed, 13 insertions(+), 3 deletions(-)
930e1b8
930e1b8
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
930e1b8
index 4709746..ea02b60 100644
930e1b8
--- a/src/core/shutdown.c
930e1b8
+++ b/src/core/shutdown.c
930e1b8
@@ -46,6 +46,7 @@
930e1b8
 #include "virt.h"
930e1b8
 #include "watchdog.h"
930e1b8
 #include "killall.h"
930e1b8
+#include "cgroup-util.h"
930e1b8
 
930e1b8
 #define FINALIZE_ATTEMPTS 50
930e1b8
 
930e1b8
@@ -131,12 +132,12 @@ static int pivot_to_new_root(void) {
930e1b8
 }
930e1b8
 
930e1b8
 int main(int argc, char *argv[]) {
930e1b8
-        _cleanup_free_ char *line = NULL;
930e1b8
-        int cmd, r;
930e1b8
-        unsigned retries;
930e1b8
         bool need_umount = true, need_swapoff = true, need_loop_detach = true, need_dm_detach = true;
930e1b8
         bool in_container, use_watchdog = false;
930e1b8
+        _cleanup_free_ char *line = NULL, *cgroup = NULL;
930e1b8
         char *arguments[3];
930e1b8
+        unsigned retries;
930e1b8
+        int cmd, r;
930e1b8
 
930e1b8
         /* suppress shutdown status output if 'quiet' is used  */
930e1b8
         r = read_one_line_file("/proc/cmdline", &line);
930e1b8
@@ -186,6 +187,8 @@ int main(int argc, char *argv[]) {
930e1b8
                 goto error;
930e1b8
         }
930e1b8
 
930e1b8
+        cg_get_root_path(&cgroup);
930e1b8
+
930e1b8
         use_watchdog = !!getenv("WATCHDOG_USEC");
930e1b8
 
930e1b8
         /* lock us into memory */
930e1b8
@@ -210,6 +213,13 @@ int main(int argc, char *argv[]) {
930e1b8
                 if (use_watchdog)
930e1b8
                         watchdog_ping();
930e1b8
 
930e1b8
+                /* Let's trim the cgroup tree on each iteration so
930e1b8
+                   that we leave an empty cgroup tree around, so that
930e1b8
+                   container managers get a nice notify event when we
930e1b8
+                   are down */
930e1b8
+                if (cgroup)
930e1b8
+                        cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, false);
930e1b8
+
930e1b8
                 if (need_umount) {
930e1b8
                         log_info("Unmounting file systems.");
930e1b8
                         r = umount_all(&changed);