X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fcgroup.c;h=83678e6e03c0cfcb627f9e7b4bdb808bbcf44164;hb=0cd385d31814c8c1bc0c81d11ef321036b8b0921;hp=70fc925b4dfedde9bcfde694acf600f545af1b76;hpb=4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4f;p=elogind.git diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 70fc925b4..83678e6e0 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -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); @@ -791,8 +801,10 @@ void unit_destroy_cgroup(Unit *u) { return; r = cg_trim_everywhere(u->manager->cgroup_supported, u->cgroup_path, !unit_has_name(u, SPECIAL_ROOT_SLICE)); - if (r < 0) + if (r < 0) { log_debug_errno(r, "Failed to destroy cgroup %s: %m", u->cgroup_path); + return; + } hashmap_remove(u->manager->cgroup_unit, u->cgroup_path); @@ -800,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) {