summaryrefslogtreecommitdiff
path: root/src/unit.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-11-18 00:42:35 +0100
committerLennart Poettering <lennart@poettering.net>2010-11-18 00:42:35 +0100
commit06d4c99ab3d479c1a7c087a87e82fe01626128f6 (patch)
treea0216fb2aaf68604a1c8198d0fdee742f43abaff /src/unit.c
parent7838dc3ae1297d37c2a75a48f429bb415c1eed22 (diff)
manager: make list of default controllers configurable
Diffstat (limited to 'src/unit.c')
-rw-r--r--src/unit.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/src/unit.c b/src/unit.c
index bfb1dd644e..7d673e138d 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1785,55 +1785,61 @@ fail:
return r;
}
-int unit_add_default_cgroups(Unit *u) {
+static int unit_add_one_default_cgroup(Unit *u, const char *controller) {
CGroupBonding *b = NULL;
int r = -ENOMEM;
- const char * const default_controllers[] = {
- SYSTEMD_CGROUP_CONTROLLER,
- "cpu",
- NULL
- };
- const char * const*c;
assert(u);
- /* Adds in the default cgroups, if it wasn't specified yet */
-
- STRV_FOREACH(c, default_controllers) {
-
- if (cgroup_bonding_find_list(u->meta.cgroup_bondings, *c))
- continue;
+ if (!controller)
+ controller = SYSTEMD_CGROUP_CONTROLLER;
- if (!(b = new0(CGroupBonding, 1)))
- return -ENOMEM;
+ if (cgroup_bonding_find_list(u->meta.cgroup_bondings, controller))
+ return 0;
- if (!(b->path = default_cgroup_path(u)))
- goto fail;
+ if (!(b = new0(CGroupBonding, 1)))
+ return -ENOMEM;
- if (!(b->controller = strdup(*c)))
- goto fail;
+ if (!(b->controller = strdup(controller)))
+ goto fail;
- b->ours = true;
- b->essential = c == default_controllers; /* the first one is essential */
+ if (!(b->path = default_cgroup_path(u)))
+ goto fail;
- if ((r = unit_add_cgroup(u, b)) < 0)
- goto fail;
+ b->ours = true;
+ b->essential = streq(controller, SYSTEMD_CGROUP_CONTROLLER);
- b = NULL;
- }
+ if ((r = unit_add_cgroup(u, b)) < 0)
+ goto fail;
return 0;
fail:
- if (b) {
- free(b->path);
- free(b->controller);
- free(b);
- }
+ free(b->path);
+ free(b->controller);
+ free(b);
return r;
}
+int unit_add_default_cgroups(Unit *u) {
+ char **c;
+ int r;
+ assert(u);
+
+ /* Adds in the default cgroups, if they weren't specified
+ * otherwise. */
+
+ if ((r = unit_add_one_default_cgroup(u, NULL)) < 0)
+ return r;
+
+ STRV_FOREACH(c, u->meta.manager->default_controllers)
+ if ((r = unit_add_one_default_cgroup(u, *c)) < 0)
+ return r;
+
+ return 0;
+}
+
CGroupBonding* unit_get_default_cgroup(Unit *u) {
assert(u);