cgroup.c revision 91901329245f070b621a24577393fb8f4ce9bffc
d24f45d9257685c7b1ad34a2a675b7ff35fb9398cmaeder/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
af313f59287bea73d6e453a1bdb397c3f68c3160Jonathan von Schroeder This file is part of systemd.
167d70cbaefa2fcc045ffde6fb4b826524c1c7a9Christian Maeder Copyright 2010 Lennart Poettering
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner systemd is free software; you can redistribute it and/or modify it
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner under the terms of the GNU General Public License as published by
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner the Free Software Foundation; either version 2 of the License, or
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner (at your option) any later version.
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner systemd is distributed in the hope that it will be useful, but
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner WITHOUT ANY WARRANTY; without even the implied warranty of
4c7cb5671b356d873d67829ec8062a5083c1ee0eEugen Kuksa MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6a6306c583c71d23b47101b59d7c9348d181ba57Eugen Kuksa General Public License for more details.
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner You should have received a copy of the GNU General Public License
a84a8d508a0778b13a4d097a6dd34b95feae78acJens Elkner along with systemd; If not, see <http://www.gnu.org/licenses/>.
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((r = cg_create(b->controller, b->path)) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder cg_trim(b->controller, b->path, false);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederint cgroup_bonding_realize_list(CGroupBonding *first) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((r = cgroup_bonding_realize(b)) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroedervoid cgroup_bonding_free(CGroupBonding *b) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder LIST_REMOVE(CGroupBonding, by_unit, b->unit->meta.cgroup_bondings, b);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder assert_se(f = hashmap_get(b->unit->meta.manager->cgroup_bondings, b->path));
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder LIST_REMOVE(CGroupBonding, by_path, f, b);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder hashmap_replace(b->unit->meta.manager->cgroup_bondings, b->path, f);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder hashmap_remove(b->unit->meta.manager->cgroup_bondings, b->path);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if (b->realized && b->only_us && b->clean_up) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder cg_trim(b->controller, b->path, false);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroedervoid cgroup_bonding_free_list(CGroupBonding *first) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder LIST_FOREACH_SAFE(by_unit, b, n, first)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroedervoid cgroup_bonding_trim(CGroupBonding *b, bool delete_root) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if (b->realized && b->only_us && b->clean_up)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder cg_trim(b->controller, b->path, delete_root);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroedervoid cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederint cgroup_bonding_install(CGroupBonding *b, pid_t pid) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((r = cg_create_and_attach(b->controller, b->path, pid)) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederint cgroup_bonding_install_list(CGroupBonding *first, pid_t pid) {
8d632882ae6a59db929b7f87816da6c4d795594eJonathan von Schroeder if ((r = cgroup_bonding_install(b, pid)) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederint cgroup_bonding_kill(CGroupBonding *b, int sig, Set *s) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((r = cgroup_bonding_realize(b)) < 0)
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder return cg_kill_recursive(b->controller, b->path, sig, true, false, s);
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroederint cgroup_bonding_kill_list(CGroupBonding *first, int sig, Set *s) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if (!(s = allocated_set = set_new(trivial_hash_func, trivial_compare_func)))
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if ((r = cgroup_bonding_kill(b, sig, s)) < 0) {
5d3daa829555d76ff7cf45e71adf661e0819a12bJonathan von Schroeder if (ret < 0 || r > 0)
5d8372f2459037830704c3f48d2b566ee1f35e31cmaeder/* Returns 1 if the group is empty, 0 if it is not, -EAGAIN if we
5d8372f2459037830704c3f48d2b566ee1f35e31cmaeder * cannot know */
a389e88e0acb83d8489bdc5e55bc5522b152bbecEugen Kuksa if ((r = cg_is_empty_recursive(b->controller, b->path, true)) < 0)
CGroupBonding *b;
if ((r = cgroup_bonding_is_empty(b)) < 0) {
if (r != -EAGAIN)
return -EAGAIN;
assert(m);
goto finish;
r = -ENOMEM;
goto finish;
goto finish;
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path);
goto finish;
if (m->pin_cgroupfs_fd >= 0)
r = -errno;
goto finish;
assert(m);
if (m->pin_cgroupfs_fd >= 0) {
CGroupBonding *l, *b;
assert(m);
if (!b->unit)
if ((t = cgroup_bonding_is_empty_list(b)) < 0) {
if (t != -EAGAIN)
CGroupBonding *l, *b;
assert(m);
return NULL;
return NULL;
char *slash;
*slash = 0;
if (!b->unit)
if (b->only_us)
return b->unit;
return NULL;
CGroupBonding *b;
return NULL;
assert(b);
return NULL;
FILE *f;
assert(b);
if (!b->only_us)
if (pid != 0) {
pid = 0;
fclose(f);
return pid;
CGroupBonding *b;
return pid;