Impact: Fix the parsing issue when two or more values are specified

From: Balbir Singh <[email protected]>

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.

Please review closely and test.

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 <[email protected]>
---

 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);
        }
        |

-- 
        Balbir

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to