chiark / gitweb /
core: don't migrate PIDs for units that may contain subcgroups, do this only for...
[elogind.git] / src / core / cgroup.c
index af048354e1fa71d23fde70783150183bf45c69f3..83678e6e03c0cfcb627f9e7b4bdb808bbcf44164 100644 (file)
@@ -606,10 +606,15 @@ static const char *migrate_callback(CGroupControllerMask mask, void *userdata) {
 
 static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
         _cleanup_free_ char *path = NULL;
+        CGroupContext *c;
         int r;
 
         assert(u);
 
+        c = unit_get_cgroup_context(u);
+        if (!c)
+                return 0;
+
         path = unit_default_cgroup_path(u);
         if (!path)
                 return log_oom();
@@ -633,10 +638,15 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
         u->cgroup_realized = true;
         u->cgroup_realized_mask = mask;
 
-        /* Then, possibly move things over */
-        r = cg_migrate_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->cgroup_path, migrate_callback, u);
-        if (r < 0)
-                log_warning_errno(r, "Failed to migrate cgroup from to %s: %m", u->cgroup_path);
+        if (u->type != UNIT_SLICE && !c->delegate) {
+
+                /* Then, possibly move things over, but not if
+                 * subgroups may contain processes, which is the case
+                 * for slice and delegation units. */
+                r = cg_migrate_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->cgroup_path, migrate_callback, u);
+                if (r < 0)
+                        log_warning_errno(r, "Failed to migrate cgroup from to %s: %m", u->cgroup_path);
+        }
 
         return 0;
 }
@@ -782,7 +792,7 @@ int unit_realize_cgroup(Unit *u) {
         return unit_realize_cgroup_now(u, manager_state(u->manager));
 }
 
-void unit_destroy_cgroup(Unit *u) {
+void unit_destroy_cgroup_if_empty(Unit *u) {
         int r;
 
         assert(u);
@@ -802,7 +812,6 @@ void unit_destroy_cgroup(Unit *u) {
         u->cgroup_path = NULL;
         u->cgroup_realized = false;
         u->cgroup_realized_mask = 0;
-
 }
 
 pid_t unit_search_main_pid(Unit *u) {