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