[systemd-commits] 2 commits - src/core

Harald Hoyer harald at kemper.freedesktop.org
Wed Aug 28 07:05:56 PDT 2013


 src/core/cgroup.c |   27 ++++++++++++++++-----------
 src/core/unit.c   |    2 +-
 2 files changed, 17 insertions(+), 12 deletions(-)

New commits:
commit b58b8e11c5f769e3c80d5169fdcc4bd04b882b7d
Author: Harald Hoyer <harald at redhat.com>
Date:   Wed Aug 28 15:33:35 2013 +0200

    Do not realloc strings, which are already in the hashmap as keys
    
    This prevents corruption of the hashmap, because we would free() the
    keys in the hashmap, if the unit is already in there, with the same
    cgroup path.

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 5a1c3ad..3eeb475 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -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;
 
diff --git a/src/core/unit.c b/src/core/unit.c
index 27119b0..ab313b9 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2329,7 +2329,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
                         free(u->cgroup_path);
                         u->cgroup_path = s;
 
-                        hashmap_put(u->manager->cgroup_unit, s, u);
+                        assert(hashmap_put(u->manager->cgroup_unit, s, u) == 1);
                         continue;
                 }
 

commit 3d040cf24473f2ed13121d57ed753bad5f8ad09d
Author: Harald Hoyer <harald at redhat.com>
Date:   Wed Aug 28 16:02:39 2013 +0200

    Revert "cgroup.c: check return value of unit_realize_cgroup_now()"
    
    This reverts commit 1f11a0cdfe397cc404d61ee679fc12f58c0a885b.

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 50b17f3..5a1c3ad 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -432,13 +432,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);



More information about the systemd-commits mailing list