summaryrefslogtreecommitdiff
path: root/cgroup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-21 03:18:05 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-21 03:18:05 +0200
commit7ccfb64aa5dce4f71debf9b5c1f29b185f0c6f5e (patch)
treebcf66df960127859513497fcd09a263660045b3b /cgroup.c
parentc9106f61d0755dc6b8aa7c4252baa140c2d473f1 (diff)
cgroup: if we are already in our own cgroup, then reuse it
Diffstat (limited to 'cgroup.c')
-rw-r--r--cgroup.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/cgroup.c b/cgroup.c
index 565ce24ce1..4ceaf38277 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -414,6 +414,7 @@ int manager_setup_cgroup(Manager *m) {
char *mp, *cp;
int r;
pid_t pid;
+ char suffix[32];
assert(m);
@@ -436,12 +437,25 @@ int manager_setup_cgroup(Manager *m) {
return translate_error(r, errno);
}
+ snprintf(suffix, sizeof(suffix), "/systemd-%u", (unsigned) pid);
+ char_array_0(suffix);
+
free(m->cgroup_hierarchy);
- m->cgroup_hierarchy = NULL;
- if (asprintf(&m->cgroup_hierarchy, "%s/systemd-%llu", strcmp(cp, "/") == 0 ? "" : cp, (unsigned long long) pid) < 0) {
+
+ if (endswith(cp, suffix))
+ /* We probably got reexecuted and can continue to use our root cgroup */
+ m->cgroup_hierarchy = cp;
+ else {
+ /* We need a new root cgroup */
+
+ m->cgroup_hierarchy = NULL;
+ r = asprintf(&m->cgroup_hierarchy, "%s%s", streq(cp, "/") ? "" : cp, suffix);
free(cp);
- free(mp);
- return -ENOMEM;
+
+ if (r < 0) {
+ free(mp);
+ return -ENOMEM;
+ }
}
log_info("Using cgroup controller <%s>, hierarchy mounted at <%s>, using root group <%s>.",
@@ -455,7 +469,6 @@ int manager_setup_cgroup(Manager *m) {
log_info("Installed release agent, or already installed.");
free(mp);
- free(cp);
if ((r = create_hierarchy_cgroup(m)) < 0)
log_error("Failed to create root cgroup hierarchy: %s", strerror(-r));