]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Prevent to add multiple versions of the same controller to mount_table
authorIvana Varekova <varekova@redhat.com>
Thu, 18 Jun 2009 05:50:30 +0000 (07:50 +0200)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Thu, 18 Jun 2009 14:19:38 +0000 (19:49 +0530)
This patche add a test to cgroup_init function, which prevent to add
multiple records for the same controller (this is a problem eg. in
cgroup_get_cgroup function - which looks to mount table and add all
relevant controllers using cgroup_add_controller function and when the
function calls cgroup_add_cgroup function twice on the same controller,
it returns error so the result is cgroup_get_cgroup failed).

Signed-off-by: Ivana Varekova <varekova@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/api.c

index ccea89c0ba63c40ec4926f34d3d3aaa93f33912f..c84675cb8d8c740cf3541d4245d22779e4b79595 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -566,6 +566,8 @@ int cgroup_init()
        char subsys_name[FILENAME_MAX];
        int hierarchy, num_cgroups, enabled;
        int i=0;
+       int j;
+       int duplicate = 0;
        char *mntopt = NULL;
        int err;
        char *buf = NULL;
@@ -644,6 +646,22 @@ int cgroup_init()
                                continue;
 
                        cgroup_dbg("matched %s:%s\n", mntopt, controllers[i]);
+
+                       /* do not have duplicates in mount table */
+                       duplicate = 0;
+                       for  (j = 0; j < found_mnt; j++) {
+                               if (strncmp(mntopt, cg_mount_table[j].name, FILENAME_MAX)
+                                       == 0) {
+                                       duplicate = 1;
+                                       break;
+                               }
+                       }
+                       if (duplicate) {
+                               cgroup_dbg("controller %s is already mounted on %s\n",
+                                       mntopt, cg_mount_table[j].path);
+                               continue;
+                       }
+
                        strcpy(cg_mount_table[found_mnt].name, controllers[i]);
                        strcpy(cg_mount_table[found_mnt].path, ent->mnt_dir);
                        cgroup_dbg("Found cgroup option %s, count %d\n",