]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Impact: Fix the parsing issue when two or more values are specified
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 21 Feb 2009 15:34:24 +0000 (15:34 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 21 Feb 2009 15:34:24 +0000 (15:34 +0000)
This patch fixes an issue where when two or more values are specified for
the controllers, only the last one is applied. This patch fixes that issue.
The parser is modified to collate all the name value pairs, seperated by
":". The reason for implementing it this way is because we need to pass
the controller name and splitting the rules would make it very hard to pass
the controller name to each rule, irrespective of where the controller name
was parsed.

Tested with the following config file

group default {
perm {
task {
uid = root;
gid = root;
}
admin {
uid = root;
gid = root;
}
}

cpu {
cpu.shares = 2048;
}

cpuset {
cpuset.mems=0;
cpuset.cpus=0-1;
}
}

mount {
cpu = /cgroup/cpu;
cpuacct = /cgroup/cpu;
cpuset = /cgroup/cpu;
}

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@336 4f4bb910-9a46-0410-90c8-c897d4f1cd53

config.c
parse.y

index 95782f6b4db374049ada7f83d351cbeabe9f82b1..e60a36f0d28ebac7bcab631ab7f2b3e34bf1ea50 100644 (file)
--- a/config.c
+++ b/config.c
@@ -107,7 +107,9 @@ int cgroup_config_parse_controller_options(char *controller, char *name_value)
        int error;
        struct cgroup *config_cgroup =
                &config_cgroup_table[cgroup_table_index];
+       char *nm_pairs, *nv_buf;
 
+       dbg("Adding controller %s, value %s\n", controller, name_value);
        cgc = cgroup_add_controller(config_cgroup, controller);
 
        if (!cgc)
@@ -120,7 +122,9 @@ int cgroup_config_parse_controller_options(char *controller, char *name_value)
        if (!name_value)
                goto done;
 
-       name = strtok_r(name_value, " ", &buffer);
+       nm_pairs = strtok_r(name_value, ":", &nv_buf);
+       dbg("[1] name value pair being processed is %s\n", nm_pairs);
+       name = strtok_r(nm_pairs, " ", &buffer);
 
        if (!name)
                goto parse_error;
@@ -130,12 +134,31 @@ int cgroup_config_parse_controller_options(char *controller, char *name_value)
        if (!value)
                goto parse_error;
 
-
+       dbg("name is %s, value is %s\n", name, value);
        error = cgroup_add_value_string(cgc, name, value);
 
        if (error)
                goto parse_error;
 
+       while ((nm_pairs = strtok_r(NULL, ":", &nv_buf))) {
+               dbg("[2] name value pair being processed is %s\n", nm_pairs);
+               name = strtok_r(nm_pairs, " ", &buffer);
+
+               if (!name)
+                       goto parse_error;
+
+               value = strtok_r(NULL, " ", &buffer);
+
+               if (!value)
+                       goto parse_error;
+
+               dbg("name is %s, value is %s\n", name, value);
+               error = cgroup_add_value_string(cgc, name, value);
+
+               if (error)
+                       goto parse_error;
+       }
+
 done:
        free(controller);
        free(name_value);
diff --git a/parse.y b/parse.y
index 53141e9d83d7eb390cc07076e699e7843c65cdb5..8c7ae2424f6a041cfa12df08183dd9099315fd50 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -121,9 +121,16 @@ namevalue_conf
        }
         |       namevalue_conf ID '=' ID ';'
        {
-               $2 = realloc($2, strlen($2) + strlen($4) + 2);
+               int len = 0;
+               if ($1)
+                       len = strlen($1);
+               $2 = realloc($2, len + strlen($2) + strlen($4) + 3);
                $2 = strncat($2, " ", strlen(" "));
                $$ = strncat($2, $4, strlen($4));
+               if ($1) {
+                       $2 = strncat($2, ":", strlen(":"));
+                       $$ = strncat($2, $1, strlen($1));
+               }
                free($4);
        }
        |