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