chiark / gitweb /
device: allow easy identification of network interfaces without their full sysfs...
[elogind.git] / cgroup.c
index 565ce24ce18725159b9763d2e15f558cdbfb6f49..70b56a3aad57ad1e45f4371789dcc4e64105cfea 100644 (file)
--- a/cgroup.c
+++ b/cgroup.c
@@ -183,8 +183,6 @@ int cgroup_bonding_kill(CGroupBonding *b, int sig) {
         if (!(s = set_new(trivial_hash_func, trivial_compare_func)))
                 return -ENOMEM;
 
-        log_debug("Killing processes from process group %s:%s", b->controller, b->path);
-
         do {
                 void *iterator;
                 pid_t pid;
@@ -414,6 +412,7 @@ int manager_setup_cgroup(Manager *m) {
         char *mp, *cp;
         int r;
         pid_t pid;
+        char suffix[32];
 
         assert(m);
 
@@ -436,12 +435,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 +467,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));
@@ -465,7 +476,7 @@ int manager_setup_cgroup(Manager *m) {
         return r;
 }
 
-int manager_shutdown_cgroup(Manager *m) {
+int manager_shutdown_cgroup(Manager *m, bool delete) {
         struct cgroup *cg;
         int r;
 
@@ -482,11 +493,10 @@ int manager_shutdown_cgroup(Manager *m) {
                 goto finish;
         }
 
-        if ((r = cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION|CGFLAG_DELETE_RECURSIVE)) != 0) {
-                log_error("Failed to delete cgroup hierarchy group: %s", cgroup_strerror(r));
-                r = translate_error(r, errno);
-                goto finish;
-        }
+        /* Often enough we won't be able to delete the cgroup we
+         * ourselves are in, hence ignore all errors here */
+        if (delete)
+                cgroup_delete_cgroup_ext(cg, CGFLAG_DELETE_IGNORE_MIGRATION|CGFLAG_DELETE_RECURSIVE);
         r = 0;
 
 finish: