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