* entry in the cgroup_table. The index is incremented in
* cgroup_config_insert_cgroup
*/
-int cgroup_config_parse_controller_options(char *controller, char *name_value)
+int cgroup_config_parse_controller_options(char *controller,
+ struct cgroup_dictionary *values)
{
- char *buffer = NULL;
- char *name, *value;
+ const char *name, *value;
struct cgroup_controller *cgc;
int error;
struct cgroup *config_cgroup =
&config_cgroup_table[cgroup_table_index];
- char *nm_pairs, *nv_buf;
+ void *iter = NULL;
cgroup_dbg("Adding controller %s, value %s\n", controller, name_value);
cgc = cgroup_add_controller(config_cgroup, controller);
* Did we just specify the controller to create the correct
* set of directories, without setting any values?
*/
- if (!name_value)
+ if (!values)
goto done;
- nm_pairs = strtok_r(name_value, ":", &nv_buf);
- cgroup_dbg("[1] 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;
-
- cgroup_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))) {
- cgroup_dbg("[2] name value pair being processed is %s\n",
- nm_pairs);
- name = strtok_r(nm_pairs, " ", &buffer);
-
+ error = cgroup_dictionary_iterator_begin(values, &iter, &name, &value);
+ while (error == 0) {
+ cgroup_dbg("[1] name value pair being processed is %s=%s\n",
+ name, value);
if (!name)
goto parse_error;
-
- value = strtok_r(NULL, " ", &buffer);
-
- if (!value)
- goto parse_error;
-
- cgroup_dbg("name is %s, value is %s\n", name, value);
error = cgroup_add_value_string(cgc, name, value);
-
if (error)
goto parse_error;
+ error = cgroup_dictionary_iterator_next(&iter, &name, &value);
}
+ cgroup_dictionary_iterator_end(&iter);
+ iter = NULL;
+
+ if (error != ECGEOF)
+ goto parse_error;
done:
free(controller);
- free(name_value);
return 1;
parse_error:
free(controller);
- free(name_value);
+ cgroup_dictionary_iterator_end(&iter);
cgroup_delete_cgroup(config_cgroup, 1);
cgroup_table_index--;
return 0;
* config related API
*/
int cgroup_config_insert_cgroup(char *cg_name);
-int cgroup_config_parse_controller_options(char *controller, char *name_value);
+int cgroup_config_parse_controller_options(char *controller,
+ struct cgroup_dictionary *values);
int cgroup_config_group_task_perm(char *perm_type, char *value);
int cgroup_config_group_admin_perm(char *perm_type, char *value);
int cgroup_config_insert_into_mount_table(char *name, char *mount_point);
char *name;
char chr;
int val;
+ struct cgroup_dictionary *values;
}
-%type <name> ID namevalue_conf
+%type <name> ID
%type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
%type <val> admin_conf task_conf task_or_admin group_conf group start
%type <val> namespace namespace_conf
+%type <values> namevalue_conf
%start start
%%
: ID '{' namevalue_conf '}'
{
$$ = cgroup_config_parse_controller_options($1, $3);
+ cgroup_dictionary_free($3);
if (!$$) {
fprintf(stderr, "parsing failed at line number %d\n",
line_no);
| group_conf ID '{' namevalue_conf '}'
{
$$ = cgroup_config_parse_controller_options($2, $4);
+ cgroup_dictionary_free($4);
if (!$$) {
fprintf(stderr, "parsing failed at line number %d\n",
line_no);
namevalue_conf
: ID '=' ID ';'
{
- $1 = realloc($1, strlen($1) + strlen($3) + 2);
- $1 = strncat($1, " ", strlen(" "));
- $$ = strncat($1, $3, strlen($3));
- free($3);
+ struct cgroup_dictionary *dict;
+ int ret;
+ ret = cgroup_dictionary_create(&dict, 0);
+ if (ret == 0)
+ ret = cgroup_dictionary_add(dict, $1, $3);
+ if (ret) {
+ fprintf(stderr, "parsing failed at line number %d:%s\n",
+ line_no, cgroup_strerror(ret));
+ $$ = NULL;
+ return ECGCONFIGPARSEFAIL;
+ }
+ $$ = dict;
}
| namevalue_conf ID '=' ID ';'
{
- 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($1);
+ int ret = 0;
+ ret = cgroup_dictionary_add($1, $2, $4);
+ if (ret != 0) {
+ fprintf(stderr, "parsing failed at line number %d: %s\n",
+ line_no, cgroup_strerror(ret));
+ $$ = NULL;
+ return ECGCONFIGPARSEFAIL;
}
- free($4);
+ $$ = $1;
}
|
{