naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Blob Blame History Raw
From ca891be92be9f82078bd88d041098c34ae35334f Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 10 Dec 2014 20:38:24 +0100
Subject: [PATCH] core: don't migrate PIDs for units that may contain
 subcgroups, do this only for leaf units

Otherwise a slice or delegation unit might move PIDs around ignoring the
fact that it is attached to a subcgroup.

(cherry picked from commit 0cd385d31814c8c1bc0c81d11ef321036b8b0921)

Resolves: #1179715
---
 src/core/cgroup.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 764311f..5558b6d 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -392,11 +392,16 @@ static CGroupControllerMask unit_get_siblings_mask(Unit *u) {
 
 static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
         _cleanup_free_ char *path;
+        CGroupContext *c;
         int r;
         bool was_in_hash = false;
 
         assert(u);
 
+        c = unit_get_cgroup_context(u);
+        if (!c)
+                return 0;
+
         path = unit_default_cgroup_path(u);
         if (!path)
                 return log_oom();
@@ -416,8 +421,10 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
         if (r < 0)
                 log_error("Failed to create cgroup %s: %s", path, strerror(-r));
 
-        /* Then, possibly move things over */
-        if (u->cgroup_path) {
+        /* Then, possibly move things over, but not if
+         * subgroups may contain processes, which is the case
+         * for slice and delegation units. */
+        if (u->cgroup_path && u->type != UNIT_SLICE && !c->delegate) {
                 r = cg_migrate_everywhere(u->manager->cgroup_supported, u->cgroup_path, path);
                 if (r < 0)
                         log_error("Failed to migrate cgroup from %s to %s: %s",