~ubuntu-branches/ubuntu/maverick/libcgroup/maverick-proposed

« back to all changes in this revision

Viewing changes to src/parse.y

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-08-26 11:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20090826112917-402ews2uj6v350d2
Tags: upstream-0.34
ImportĀ upstreamĀ versionĀ 0.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright IBM Corporation. 2007
 
3
 *
 
4
 * Authors:     Balbir Singh <balbir@linux.vnet.ibm.com>
 
5
 * This program is free software; you can redistribute it and/or modify it
 
6
 * under the terms of version 2.1 of the GNU Lesser General Public License
 
7
 * as published by the Free Software Foundation.
 
8
 *
 
9
 * This program is distributed in the hope that it would be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
12
 *
 
13
 * NOTE: The grammar has been modified, not to be the most efficient, but
 
14
 * to allow easy updation of internal data structures.
 
15
 */
 
16
%{
 
17
#include <stdlib.h>
 
18
#include <stdio.h>
 
19
#include <string.h>
 
20
#include <libcgroup.h>
 
21
#include <libcgroup-internal.h>
 
22
 
 
23
int yylex(void);
 
24
extern int line_no;
 
25
extern char *yytext;
 
26
 
 
27
void yyerror(char *s)
 
28
{
 
29
        fprintf(stderr, "error at line number %d at %c:%s", line_no, *yytext,
 
30
                s);
 
31
}
 
32
 
 
33
int yywrap(void)
 
34
{
 
35
        return 1;
 
36
}
 
37
 
 
38
%}
 
39
 
 
40
%token ID MOUNT GROUP PERM TASK ADMIN
 
41
 
 
42
%union {
 
43
        char *name;
 
44
        char chr;
 
45
        int val;
 
46
}
 
47
%type <name> ID namevalue_conf
 
48
%type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
 
49
%type <val> admin_conf task_conf task_or_admin group_conf group start
 
50
%start start
 
51
%%
 
52
 
 
53
start   : start group
 
54
        {
 
55
                $$ = $1;
 
56
        }
 
57
        | start mount
 
58
        {
 
59
                $$ = $1;
 
60
        }
 
61
        |
 
62
        {
 
63
                $$ = 1;
 
64
        }
 
65
        ;
 
66
 
 
67
group   :       GROUP ID '{' group_conf '}'
 
68
        {
 
69
                $$ = $4;
 
70
                if ($$)
 
71
                        cgroup_config_insert_cgroup($2);
 
72
                else {
 
73
                        fprintf(stderr, "parsing failed at line number %d\n",
 
74
                                line_no);
 
75
                        $$ = 0;
 
76
                        return $$;
 
77
                }
 
78
        }
 
79
        ;
 
80
 
 
81
group_conf
 
82
        :       ID '{' namevalue_conf '}'
 
83
        {
 
84
                $$ = cgroup_config_parse_controller_options($1, $3);
 
85
                if (!$$) {
 
86
                        fprintf(stderr, "parsing failed at line number %d\n",
 
87
                                line_no);
 
88
                        $$ = 0;
 
89
                        return $$;
 
90
                }
 
91
        }
 
92
        |       group_conf ID '{' namevalue_conf '}' 
 
93
        {
 
94
                $$ = cgroup_config_parse_controller_options($2, $4);
 
95
                if (!$$) {
 
96
                        fprintf(stderr, "parsing failed at line number %d\n",
 
97
                                line_no);
 
98
                        $$ = 0;
 
99
                        return $$;
 
100
                }
 
101
        }
 
102
        |       PERM '{' task_or_admin '}'
 
103
        {
 
104
                $$ = $3;
 
105
                if (!$$) {
 
106
                        fprintf(stderr, "parsing failed at line number %d\n",
 
107
                                line_no);
 
108
                        $$ = 0;
 
109
                        return $$;
 
110
                }
 
111
        }
 
112
        ;
 
113
 
 
114
namevalue_conf
 
115
        :       ID '=' ID ';'
 
116
        {
 
117
                $1 = realloc($1, strlen($1) + strlen($3) + 2);
 
118
                $1 = strncat($1, " ", strlen(" "));
 
119
                $$ = strncat($1, $3, strlen($3));
 
120
                free($3);
 
121
        }
 
122
        |       namevalue_conf ID '=' ID ';'
 
123
        {
 
124
                int len = 0;
 
125
                if ($1)
 
126
                        len = strlen($1);
 
127
                $2 = realloc($2, len + strlen($2) + strlen($4) + 3);
 
128
                $2 = strncat($2, " ", strlen(" "));
 
129
                $$ = strncat($2, $4, strlen($4));
 
130
                if ($1) {
 
131
                        $2 = strncat($2, ":", strlen(":"));
 
132
                        $$ = strncat($2, $1, strlen($1));
 
133
                }
 
134
                free($4);
 
135
        }
 
136
        |
 
137
        {
 
138
                $$ = NULL;
 
139
        }
 
140
        ;
 
141
 
 
142
task_namevalue_conf
 
143
        :       ID '=' ID ';'
 
144
        {
 
145
                $$ = cgroup_config_group_task_perm($1, $3);
 
146
                if (!$$) {
 
147
                        fprintf(stderr, "parsing failed at line number %d\n",
 
148
                                line_no);
 
149
                        $$ = 0;
 
150
                        return $$;
 
151
                }
 
152
        }
 
153
        |       task_namevalue_conf ID '=' ID ';'
 
154
        {
 
155
                $$ = $1 && cgroup_config_group_task_perm($2, $4);
 
156
                if (!$$) {
 
157
                        fprintf(stderr, "parsing failed at line number %d\n",
 
158
                                line_no);
 
159
                        $$ = 0;
 
160
                        return $$;
 
161
                }
 
162
        }
 
163
        ;
 
164
 
 
165
admin_namevalue_conf
 
166
        :       ID '=' ID ';'
 
167
        {
 
168
                $$ = cgroup_config_group_admin_perm($1, $3);
 
169
                if (!$$) {
 
170
                        fprintf(stderr, "parsing failed at line number %d\n",
 
171
                                line_no);
 
172
                        $$ = 0;
 
173
                        return $$;
 
174
                }
 
175
        }
 
176
        |       admin_namevalue_conf ID '=' ID ';'
 
177
        {
 
178
                $$ = $1 && cgroup_config_group_admin_perm($2, $4);
 
179
                if (!$$) {
 
180
                        fprintf(stderr, "parsing failed at line number %d\n",
 
181
                                line_no);
 
182
                        $$ = 0;
 
183
                        return $$;
 
184
                }
 
185
        }
 
186
        ;
 
187
 
 
188
task_or_admin
 
189
        :       TASK '{' task_namevalue_conf '}' admin_conf
 
190
        {
 
191
                $$ = $3 && $5;
 
192
                if (!$$) {
 
193
                        fprintf(stderr, "parsing failed at line number %d\n",
 
194
                                line_no);
 
195
                        $$ = 0;
 
196
                        return $$;
 
197
                }
 
198
        }
 
199
        |       ADMIN '{' admin_namevalue_conf '}' task_conf
 
200
        {
 
201
                $$ = $3 && $5;
 
202
                if (!$$) {
 
203
                        fprintf(stderr, "parsing failed at line number %d\n",
 
204
                                line_no);
 
205
                        $$ = 0;
 
206
                        return $$;
 
207
                }
 
208
        }
 
209
        ;
 
210
 
 
211
admin_conf:     ADMIN '{' admin_namevalue_conf '}'
 
212
        {
 
213
                $$ = $3;
 
214
                if (!$$) {
 
215
                        fprintf(stderr, "parsing failed at line number %d\n",
 
216
                                line_no);
 
217
                        $$ = 0;
 
218
                        return $$;
 
219
                }
 
220
        }
 
221
        ;
 
222
 
 
223
task_conf:      TASK '{' task_namevalue_conf '}'
 
224
        {
 
225
                $$ = $3;
 
226
                if (!$$) {
 
227
                        fprintf(stderr, "parsing failed at line number %d\n",
 
228
                                line_no);
 
229
                        $$ = 0;
 
230
                        return $$;
 
231
                }
 
232
        }
 
233
        ;
 
234
 
 
235
mountvalue_conf
 
236
        :       ID '=' ID ';'
 
237
        {
 
238
                if (!cgroup_config_insert_into_mount_table($1, $3)) {
 
239
                        cgroup_config_cleanup_mount_table();
 
240
                        $$ = 0;
 
241
                        return $$;
 
242
                }
 
243
                $$ = 1;
 
244
        }
 
245
        |       mountvalue_conf ID '=' ID ';'
 
246
        {
 
247
                if (!cgroup_config_insert_into_mount_table($2, $4)) {
 
248
                        cgroup_config_cleanup_mount_table();
 
249
                        $$ = 0;
 
250
                        return $$;
 
251
                }
 
252
                $$ = 1;
 
253
        }
 
254
        ;
 
255
 
 
256
mount   :       MOUNT '{' mountvalue_conf '}'
 
257
        {
 
258
                $$ = $3;
 
259
                if (!$$) {
 
260
                        fprintf(stderr, "parsing failed at line number %d\n",
 
261
                                line_no);
 
262
                        $$ = 0;
 
263
                        return $$;
 
264
                }
 
265
        }
 
266
        ;
 
267
 
 
268
 
 
269
%%