From 74f9a91b6bccc558ed90d02ae15cd2c9d49267cb Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Sat, 21 Feb 2009 15:34:24 +0000 Subject: Impact: Fix the parsing issue when two or more values are specified 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 git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@336 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- config.c | 27 +++++++++++++++++++++++++-- parse.y | 9 ++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index 95782f6..e60a36f 100644 --- 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 53141e9..8c7ae24 100644 --- 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); } | -- cgit