daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
572a44
From c46be83563a2d20a480988dab55404f941b9cc35 Mon Sep 17 00:00:00 2001
572a44
From: Lennart Poettering <lennart@poettering.net>
572a44
Date: Tue, 5 Nov 2013 22:14:52 +0100
572a44
Subject: [PATCH] cgroup: run PID 1 in the root cgroup
572a44
572a44
This way cleaning up the cgroup tree on shutdown is a lot easier since
572a44
we are in the root dir. Also PID 1 was previously artificially placed in
572a44
system.slice, even though our rule actually was not to have processes in
572a44
slices. The root slice otoh is magic anyway, so having PID 1 in there
572a44
sounds less surprising.
572a44
572a44
Of course, this means that PID is scheduled against the three top-level
572a44
slices.
572a44
---
572a44
 src/core/cgroup.c | 16 ++++++++--------
572a44
 1 file changed, 8 insertions(+), 8 deletions(-)
572a44
572a44
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
572a44
index b60707c..32e2599 100644
572a44
--- a/src/core/cgroup.c
572a44
+++ b/src/core/cgroup.c
572a44
@@ -591,8 +591,8 @@ pid_t unit_search_main_pid(Unit *u) {
572a44
 
572a44
 int manager_setup_cgroup(Manager *m) {
572a44
         _cleanup_free_ char *path = NULL;
572a44
+        char *e;
572a44
         int r;
572a44
-        char *e, *a;
572a44
 
572a44
         assert(m);
572a44
 
572a44
@@ -612,9 +612,13 @@ int manager_setup_cgroup(Manager *m) {
572a44
                 return r;
572a44
         }
572a44
 
572a44
-        /* Already in /system.slice? If so, let's cut this off again */
572a44
+        /* LEGACY: Already in /system.slice? If so, let's cut this
572a44
+         * off. This is to support live upgrades from older systemd
572a44
+         * versions where PID 1 was moved there. */
572a44
         if (m->running_as == SYSTEMD_SYSTEM) {
572a44
                 e = endswith(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE);
572a44
+                if (!e)
572a44
+                        e = endswith(m->cgroup_root, "/system");
572a44
                 if (e)
572a44
                         *e = 0;
572a44
         }
572a44
@@ -645,12 +649,8 @@ int manager_setup_cgroup(Manager *m) {
572a44
                         log_debug("Release agent already installed.");
572a44
         }
572a44
 
572a44
-        /* 4. Realize the system slice and put us in there */
572a44
-        if (m->running_as == SYSTEMD_SYSTEM) {
572a44
-                a = strappenda(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE);
572a44
-                r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, a, 0);
572a44
-        } else
572a44
-                r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, 0);
572a44
+        /* 4. Make sure we are in the root cgroup */
572a44
+        r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, 0);
572a44
         if (r < 0) {
572a44
                 log_error("Failed to create root cgroup hierarchy: %s", strerror(-r));
572a44
                 return r;