anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0088-shutdown-trim-the-cgroup-tree-on-loop-iteration.patch

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