ryantimwilson / rpms / systemd

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