X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fcgroup.c;h=35b862d5c2ff14d7bd6c84d8ecad0531a4ed8c8b;hb=821d4b6e068b2afaad94d43db22171c34a30400e;hp=83678e6e03c0cfcb627f9e7b4bdb808bbcf44164;hpb=0cd385d31814c8c1bc0c81d11ef321036b8b0921;p=elogind.git diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 83678e6e0..35b862d5c 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -605,7 +605,6 @@ 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; @@ -615,18 +614,22 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { if (!c) return 0; - path = unit_default_cgroup_path(u); - if (!path) - return log_oom(); + if (!u->cgroup_path) { + _cleanup_free_ char *path = NULL; - r = hashmap_put(u->manager->cgroup_unit, path, u); - if (r < 0) { - log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r)); - return r; - } - if (r > 0) { - u->cgroup_path = path; - path = NULL; + path = unit_default_cgroup_path(u); + if (!path) + return log_oom(); + + r = hashmap_put(u->manager->cgroup_unit, path, u); + if (r < 0) { + log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r)); + return r; + } + if (r > 0) { + u->cgroup_path = path; + path = NULL; + } } /* First, create our own group */ @@ -651,6 +654,21 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { return 0; } +int unit_attach_pids_to_cgroup(Unit *u) { + int r; + assert(u); + + r = unit_realize_cgroup(u); + if (r < 0) + return r; + + r = cg_attach_many_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->pids, migrate_callback, u); + if (r < 0) + return r; + + return 0; +} + static bool unit_has_mask_realized(Unit *u, CGroupControllerMask mask) { assert(u);