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