chiark / gitweb /
cgroup: correct the log information
[elogind.git] / src / core / cgroup.c
index 50b17f3802d6e453584cca0065ab86a297c39d51..aee93ba0a8b214ef750359a660a5cbe6ecfd706b 100644 (file)
@@ -264,9 +264,9 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
                         log_error("Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
 
                 sprintf(buf, "%" PRIu64 "\n", c->memory_soft_limit);
-                cg_set_attribute("memory", path, "memory.soft_limit_in_bytes", buf);
+                r = cg_set_attribute("memory", path, "memory.soft_limit_in_bytes", buf);
                 if (r < 0)
-                        log_error("Failed to set memory.limit_in_bytes on %s: %s", path, strerror(-r));
+                        log_error("Failed to set memory.soft_limit_in_bytes on %s: %s", path, strerror(-r));
         }
 
         if (mask & CGROUP_DEVICE) {
@@ -382,6 +382,7 @@ static CGroupControllerMask unit_get_siblings_mask(Unit *u) {
 static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
         char *path = NULL;
         int r;
+        bool is_in_hash = false;
 
         assert(u);
 
@@ -390,8 +391,14 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
                 return -ENOMEM;
 
         r = hashmap_put(u->manager->cgroup_unit, path, u);
-        if (r < 0)
+        if (r == 0)
+                is_in_hash = true;
+
+        if (r < 0) {
+                free(path);
+                log_error("cgroup %s exists already: %s", path, strerror(-r));
                 return r;
+        }
 
         /* First, create our own group */
         r = cg_create_with_mask(mask, path);
@@ -405,9 +412,12 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
                         log_error("Failed to migrate cgroup %s: %s", path, strerror(-r));
         }
 
-        /* And remember the new data */
-        free(u->cgroup_path);
-        u->cgroup_path = path;
+        if (!is_in_hash) {
+                /* And remember the new data */
+                free(u->cgroup_path);
+                u->cgroup_path = path;
+        }
+
         u->cgroup_realized = true;
         u->cgroup_mask = mask;
 
@@ -432,13 +442,8 @@ static int unit_realize_cgroup_now(Unit *u) {
                 return 0;
 
         /* First, realize parents */
-        if (UNIT_ISSET(u->slice)) {
-                int r;
-
-                r = unit_realize_cgroup_now(UNIT_DEREF(u->slice));
-                if (r < 0)
-                        return r;
-        }
+        if (UNIT_ISSET(u->slice))
+                unit_realize_cgroup_now(UNIT_DEREF(u->slice));
 
         /* And then do the real work */
         return unit_create_cgroups(u, mask);