X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fcgroup.c;h=3eeb47575424f3c853594d122df5e2fe74ee6273;hb=06eb4e3bf87584ea526a90643d49037cf6ffd7ff;hp=50b17f3802d6e453584cca0065ab86a297c39d51;hpb=1f11a0cdfe397cc404d61ee679fc12f58c0a885b;p=elogind.git diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 50b17f380..3eeb47575 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -382,6 +382,7 @@ static CGroupControllerMask unit_get_siblings_mask(Unit *u) { static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { char *path = NULL; int r; + bool is_in_hash = false; assert(u); @@ -390,8 +391,14 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { return -ENOMEM; r = hashmap_put(u->manager->cgroup_unit, path, u); - if (r < 0) + if (r == 0) + is_in_hash = true; + + if (r < 0) { + free(path); + log_error("cgroup %s exists already: %s", path, strerror(-r)); return r; + } /* First, create our own group */ r = cg_create_with_mask(mask, path); @@ -405,9 +412,12 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { log_error("Failed to migrate cgroup %s: %s", path, strerror(-r)); } - /* And remember the new data */ - free(u->cgroup_path); - u->cgroup_path = path; + if (!is_in_hash) { + /* And remember the new data */ + free(u->cgroup_path); + u->cgroup_path = path; + } + u->cgroup_realized = true; u->cgroup_mask = mask; @@ -432,13 +442,8 @@ static int unit_realize_cgroup_now(Unit *u) { return 0; /* First, realize parents */ - if (UNIT_ISSET(u->slice)) { - int r; - - r = unit_realize_cgroup_now(UNIT_DEREF(u->slice)); - if (r < 0) - return r; - } + if (UNIT_ISSET(u->slice)) + unit_realize_cgroup_now(UNIT_DEREF(u->slice)); /* And then do the real work */ return unit_create_cgroups(u, mask);