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