]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/get_item.c
confile: add lxc.init.groups to keep additional groups
[mirror_lxc.git] / src / tests / get_item.c
1 /* liblxcapi
2 *
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 #include <lxc/lxccontainer.h>
20
21 #include <unistd.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <stdlib.h>
27 #include <errno.h>
28 #include <string.h>
29
30 #include "lxc/state.h"
31 #include "lxctest.h"
32
33 #define MYNAME "lxctest1"
34
35 int main(int argc, char *argv[])
36 {
37 int ret;
38 struct lxc_container *c;
39 int fret = EXIT_FAILURE;
40 char v1[2], v2[256], v3[2048];
41
42 if ((c = lxc_container_new("testxyz", NULL)) == NULL) {
43 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
44 exit(EXIT_FAILURE);
45 }
46
47 /* EXPECT SUCCESS: lxc.log.syslog with valid value. */
48 if (!c->set_config_item(c, "lxc.log.syslog", "local0")) {
49 lxc_error("%s\n", "Failed to set lxc.log.syslog.\n");
50 goto out;
51 }
52
53 ret = c->get_config_item(c, "lxc.log.syslog", v2, 255);
54 if (ret < 0) {
55 lxc_error("Failed to retrieve lxc.log.syslog: %d.\n", ret);
56 goto out;
57 }
58
59 if (strcmp(v2, "local0") != 0) {
60 lxc_error("Expected: local0 == %s.\n", v2);
61 goto out;
62 }
63 lxc_debug("Retrieving value for lxc.log.syslog correctly returned: %s.\n", v2);
64
65 /* EXPECT FAILURE: lxc.log.syslog with invalid value. */
66 if (c->set_config_item(c, "lxc.log.syslog", "NONSENSE")) {
67 lxc_error("%s\n", "Succeeded int setting lxc.log.syslog to invalid value \"NONSENSE\".\n");
68 goto out;
69 }
70 lxc_debug("%s\n", "Successfully failed to set lxc.log.syslog to invalid value.\n");
71
72 if (!c->set_config_item(c, "lxc.hook.pre-start", "hi there")) {
73 fprintf(stderr, "%d: failed to set hook.pre-start\n", __LINE__);
74 goto out;
75 }
76
77 ret = c->get_config_item(c, "lxc.hook.pre-start", v2, 255);
78 if (ret < 0) {
79 fprintf(stderr, "%d: get_config_item(lxc.hook.pre-start) returned %d\n", __LINE__, ret);
80 goto out;
81 }
82 fprintf(stderr, "lxc.hook.pre-start returned %d %s\n", ret, v2);
83
84 ret = c->get_config_item(c, "lxc.net", v2, 255);
85 if (ret < 0) {
86 fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
87 goto out;
88 }
89 fprintf(stderr, "%d: get_config_item(lxc.net) returned %d %s\n", __LINE__, ret, v2);
90
91 if (!c->set_config_item(c, "lxc.tty.max", "4")) {
92 fprintf(stderr, "%d: failed to set tty\n", __LINE__);
93 goto out;
94 }
95
96 ret = c->get_config_item(c, "lxc.tty.max", v2, 255);
97 if (ret < 0) {
98 fprintf(stderr, "%d: get_config_item(lxc.tty) returned %d\n", __LINE__, ret);
99 goto out;
100 }
101 fprintf(stderr, "lxc.tty returned %d %s\n", ret, v2);
102
103 if (!c->set_config_item(c, "lxc.arch", "x86")) {
104 fprintf(stderr, "%d: failed to set arch\n", __LINE__);
105 goto out;
106 }
107
108 ret = c->get_config_item(c, "lxc.arch", v2, 255);
109 if (ret < 0) {
110 fprintf(stderr, "%d: get_config_item(lxc.arch) returned %d\n", __LINE__, ret);
111 goto out;
112 }
113 printf("lxc.arch returned %d %s\n", ret, v2);
114
115 if (!c->set_config_item(c, "lxc.init.uid", "100")) {
116 fprintf(stderr, "%d: failed to set init_uid\n", __LINE__);
117 goto out;
118 }
119
120 ret = c->get_config_item(c, "lxc.init.uid", v2, 255);
121 if (ret < 0) {
122 fprintf(stderr, "%d: get_config_item(lxc.init_uid) returned %d\n", __LINE__, ret);
123 goto out;
124 }
125 printf("lxc.init_uid returned %d %s\n", ret, v2);
126
127 if (!c->set_config_item(c, "lxc.init.gid", "100")) {
128 fprintf(stderr, "%d: failed to set init_gid\n", __LINE__);
129 goto out;
130 }
131
132 ret = c->get_config_item(c, "lxc.init.gid", v2, 255);
133 if (ret < 0) {
134 fprintf(stderr, "%d: get_config_item(lxc.init_gid) returned %d\n", __LINE__, ret);
135 goto out;
136 }
137 printf("lxc.init_gid returned %d %s\n", ret, v2);
138
139 if (!c->set_config_item(c, "lxc.init.groups", "")) {
140 fprintf(stderr, "%d: failed to set init_groups\n", __LINE__);
141 goto out;
142 }
143
144 if (!c->set_config_item(c, "lxc.init.groups", "10,20,foo,40")) {
145 printf("failed to set init_groups to '10,20,foo,40' as expected\n");
146 } else {
147 goto out;
148 }
149
150 if (!c->set_config_item(c, "lxc.init.groups", "10,20,30,40")) {
151 fprintf(stderr, "%d: failed to set init_groups\n", __LINE__);
152 goto out;
153 }
154
155 ret = c->get_config_item(c, "lxc.init.groups", v2, 255);
156 if (ret < 0) {
157 fprintf(stderr, "%d: get_config_item(lxc.init_gid) returned %d\n",
158 __LINE__, ret);
159 goto out;
160 }
161 ret = strcmp("10,20,30,40", v2);
162 printf("lxc.init_groups returned %d %s\n", ret, v2);
163 if (ret != 0) {
164 goto out;
165 }
166
167 #define HNAME "hostname1"
168 // demonstrate proper usage:
169 char *alloced;
170 int len;
171
172 if (!c->set_config_item(c, "lxc.uts.name", HNAME)) {
173 fprintf(stderr, "%d: failed to set utsname\n", __LINE__);
174 goto out;
175 }
176
177 len = c->get_config_item(c, "lxc.uts.name", NULL, 0); // query the size of the string
178 if (len < 0) {
179 fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, len);
180 goto out;
181 }
182 printf("lxc.utsname returned %d\n", len);
183
184 // allocate the length of string + 1 for trailing \0
185 alloced = malloc(len+1);
186 if (!alloced) {
187 fprintf(stderr, "%d: failed to allocate %d bytes for utsname\n", __LINE__, len);
188 goto out;
189 }
190
191 // now pass in the malloc'd array, and pass in length of string + 1: again
192 // because we need room for the trailing \0
193 ret = c->get_config_item(c, "lxc.uts.name", alloced, len+1);
194 if (ret < 0) {
195 fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, ret);
196 goto out;
197 }
198
199 if (strcmp(alloced, HNAME) != 0 || ret != len) {
200 fprintf(stderr, "lxc.utsname returned wrong value: %d %s not %d %s\n", ret, alloced, len, HNAME);
201 goto out;
202 }
203 printf("lxc.utsname returned %d %s\n", len, alloced);
204 free(alloced);
205
206 if (!c->set_config_item(c, "lxc.mount.entry", "hi there")) {
207 fprintf(stderr, "%d: failed to set mount.entry\n", __LINE__);
208 goto out;
209 }
210
211 ret = c->get_config_item(c, "lxc.mount.entry", v2, 255);
212 if (ret < 0) {
213 fprintf(stderr, "%d: get_config_item(lxc.mount.entry) returned %d\n", __LINE__, ret);
214 goto out;
215 }
216 printf("lxc.mount.entry returned %d %s\n", ret, v2);
217
218 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
219 if (ret != 0) {
220 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
221 goto out;
222 }
223
224 if (!c->set_config_item(c, "lxc.prlimit.nofile", "1234:unlimited")) {
225 fprintf(stderr, "%d: failed to set limit.nofile\n", __LINE__);
226 goto out;
227 }
228
229 ret = c->get_config_item(c, "lxc.prlimit.nofile", v2, 255);
230 if (ret < 0) {
231 fprintf(stderr, "%d: get_config_item(lxc.prlimit.nofile) returned %d\n", __LINE__, ret);
232 goto out;
233 }
234
235 if (strcmp(v2, "1234:unlimited")) {
236 fprintf(stderr, "%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited\n", __LINE__, ret, v2);
237 goto out;
238 }
239 printf("lxc.prlimit.nofile returned %d %s\n", ret, v2);
240
241 if (!c->set_config_item(c, "lxc.prlimit.stack", "unlimited")) {
242 fprintf(stderr, "%d: failed to set limit.stack\n", __LINE__);
243 goto out;
244 }
245
246 ret = c->get_config_item(c, "lxc.prlimit.stack", v2, 255);
247 if (ret < 0) {
248 fprintf(stderr, "%d: get_config_item(lxc.prlimit.stack) returned %d\n", __LINE__, ret);
249 goto out;
250 }
251
252 if (strcmp(v2, "unlimited")) {
253 fprintf(stderr, "%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited\n", __LINE__, ret, v2);
254 goto out;
255 }
256 printf("lxc.prlimit.stack returned %d %s\n", ret, v2);
257
258 #define LIMIT_STACK "lxc.prlimit.stack = unlimited\n"
259 #define ALL_LIMITS "lxc.prlimit.nofile = 1234:unlimited\n" LIMIT_STACK
260 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
261 if (ret != sizeof(ALL_LIMITS)-1) {
262 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
263 goto out;
264 }
265
266 if (strcmp(v3, ALL_LIMITS)) {
267 fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_LIMITS)-1, ALL_LIMITS);
268 goto out;
269 }
270 printf("lxc.prlimit returned %d %s\n", ret, v3);
271
272 if (!c->clear_config_item(c, "lxc.prlimit.nofile")) {
273 fprintf(stderr, "%d: failed clearing limit.nofile\n", __LINE__);
274 goto out;
275 }
276
277 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
278 if (ret != sizeof(LIMIT_STACK)-1) {
279 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
280 goto out;
281 }
282
283 if (strcmp(v3, LIMIT_STACK)) {
284 fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(LIMIT_STACK)-1, LIMIT_STACK);
285 goto out;
286 }
287 printf("lxc.prlimit returned %d %s\n", ret, v3);
288
289 #define SYSCTL_SOMAXCONN "lxc.sysctl.net.core.somaxconn = 256\n"
290 #define ALL_SYSCTLS "lxc.sysctl.net.ipv4.ip_forward = 1\n" SYSCTL_SOMAXCONN
291
292 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
293 if (ret != 0) {
294 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
295 goto out;
296 }
297
298 if (!c->set_config_item(c, "lxc.sysctl.net.ipv4.ip_forward", "1")) {
299 fprintf(stderr, "%d: failed to set lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
300 goto out;
301 }
302
303 ret = c->get_config_item(c, "lxc.sysctl.net.ipv4.ip_forward", v2, 255);
304 if (ret < 0) {
305 fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d\n", __LINE__, ret);
306 goto out;
307 }
308
309 if (strcmp(v2, "1")) {
310 fprintf(stderr, "%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1\n", __LINE__, ret, v2);
311 goto out;
312 }
313 printf("lxc.sysctl.net.ipv4.ip_forward returned %d %s\n", ret, v2);
314
315 if (!c->set_config_item(c, "lxc.sysctl.net.core.somaxconn", "256")) {
316 fprintf(stderr, "%d: failed to set lxc.sysctl.net.core.somaxconn\n", __LINE__);
317 goto out;
318 }
319
320 ret = c->get_config_item(c, "lxc.sysctl.net.core.somaxconn", v2, 255);
321 if (ret < 0) {
322 fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d\n", __LINE__, ret);
323 goto out;
324 }
325
326 if (strcmp(v2, "256")) {
327 fprintf(stderr, "%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256\n", __LINE__, ret, v2);
328 goto out;
329 }
330 printf("lxc.sysctl.net.core.somaxconn returned %d %s\n", ret, v2);
331
332 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
333 if (ret != sizeof(ALL_SYSCTLS)-1) {
334 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
335 goto out;
336 }
337
338 if (strcmp(v3, ALL_SYSCTLS)) {
339 fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_SYSCTLS) - 1, ALL_SYSCTLS);
340 goto out;
341 }
342 printf("lxc.sysctl returned %d %s\n", ret, v3);
343
344 if (!c->clear_config_item(c, "lxc.sysctl.net.ipv4.ip_forward")) {
345 fprintf(stderr, "%d: failed clearing lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
346 goto out;
347 }
348
349 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
350 if (ret != sizeof(SYSCTL_SOMAXCONN) - 1) {
351 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
352 goto out;
353 }
354
355 if (strcmp(v3, SYSCTL_SOMAXCONN)) {
356 fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(SYSCTL_SOMAXCONN) - 1, SYSCTL_SOMAXCONN);
357 goto out;
358 }
359 printf("lxc.sysctl returned %d %s\n", ret, v3);
360
361 #define PROC_OOM_SCORE_ADJ "lxc.proc.oom_score_adj = 10\n"
362 #define ALL_PROCS "lxc.proc.setgroups = allow\n" PROC_OOM_SCORE_ADJ
363
364 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
365 if (ret != 0) {
366 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
367 goto out;
368 }
369
370 if (!c->set_config_item(c, "lxc.proc.setgroups", "allow")) {
371 fprintf(stderr, "%d: failed to set lxc.proc.setgroups\n", __LINE__);
372 goto out;
373 }
374
375 ret = c->get_config_item(c, "lxc.proc.setgroups", v2, 255);
376 if (ret < 0) {
377 fprintf(stderr, "%d: get_config_item(lxc.proc.setgroups) returned %d\n", __LINE__, ret);
378 goto out;
379 }
380
381 if (strcmp(v2, "allow")) {
382 fprintf(stderr, "%d: lxc.proc.setgroups returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
383 goto out;
384 }
385 printf("lxc.proc.setgroups returned %d %s\n", ret, v2);
386
387 if (!c->set_config_item(c, "lxc.proc.oom_score_adj", "10")) {
388 fprintf(stderr, "%d: failed to set lxc.proc.oom_score_adj\n", __LINE__);
389 goto out;
390 }
391
392 ret = c->get_config_item(c, "lxc.proc.oom_score_adj", v2, 255);
393 if (ret < 0) {
394 fprintf(stderr, "%d: get_config_item(lxc.proc.oom_score_adj) returned %d\n", __LINE__, ret);
395 goto out;
396 }
397
398 if (strcmp(v2, "10")) {
399 fprintf(stderr, "%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
400 goto out;
401 }
402 printf("lxc.proc.oom_score_adj returned %d %s\n", ret, v2);
403
404 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
405 if (ret != sizeof(ALL_PROCS)-1) {
406 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
407 goto out;
408 }
409
410 if (strcmp(v3, ALL_PROCS)) {
411 fprintf(stderr, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_PROCS) - 1, ALL_PROCS);
412 goto out;
413 }
414 printf("lxc.proc returned %d %s\n", ret, v3);
415
416 if (!c->clear_config_item(c, "lxc.proc.setgroups")) {
417 fprintf(stderr, "%d: failed clearing lxc.proc.setgroups\n", __LINE__);
418 goto out;
419 }
420
421 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
422 if (ret < 0) {
423 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
424 goto out;
425 }
426
427 if (strcmp(v3, PROC_OOM_SCORE_ADJ)) {
428 fprintf(stderr, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(PROC_OOM_SCORE_ADJ) - 1, PROC_OOM_SCORE_ADJ);
429 goto out;
430 }
431 printf("lxc.proc returned %d %s\n", ret, v3);
432
433 if (!c->set_config_item(c, "lxc.apparmor.profile", "unconfined")) {
434 fprintf(stderr, "%d: failed to set aa_profile\n", __LINE__);
435 goto out;
436 }
437
438 ret = c->get_config_item(c, "lxc.apparmor.profile", v2, 255);
439 if (ret < 0) {
440 fprintf(stderr, "%d: get_config_item(lxc.aa_profile) returned %d\n", __LINE__, ret);
441 goto out;
442 }
443 printf("lxc.aa_profile returned %d %s\n", ret, v2);
444
445 lxc_container_put(c);
446
447 // new test with real container
448 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
449 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
450 goto out;
451 }
452 c->destroy(c);
453 lxc_container_put(c);
454
455 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
456 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
457 goto out;
458 }
459
460 if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
461 fprintf(stderr, "%d: failed to create a trusty container\n", __LINE__);
462 goto out;
463 }
464 lxc_container_put(c);
465
466 /* XXX TODO load_config needs to clear out any old config first */
467 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
468 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
469 goto out;
470 }
471
472 ret = c->get_config_item(c, "lxc.cap.drop", NULL, 300);
473 if (ret < 5 || ret > 255) {
474 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) with NULL returned %d\n", __LINE__, ret);
475 goto out;
476 }
477
478 ret = c->get_config_item(c, "lxc.cap.drop", v1, 1);
479 if (ret < 5 || ret > 255) {
480 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d\n", __LINE__, ret);
481 goto out;
482 }
483
484 ret = c->get_config_item(c, "lxc.cap.drop", v2, 255);
485 if (ret < 0) {
486 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
487 goto out;
488 }
489 printf("%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
490
491 ret = c->get_config_item(c, "lxc.net", v2, 255);
492 if (ret < 0) {
493 fprintf(stderr, "%d: get_config_item(lxc.net) returned %d\n", __LINE__, ret);
494 goto out;
495 }
496 printf("%d: get_config_item(lxc.net) returned %d %s\n", __LINE__, ret, v2);
497
498 if (!c->set_config_item(c, "lxc.net.0.type", "veth")) {
499 fprintf(stderr, "%d: failed to set lxc.net.0.type\n", __LINE__);
500 goto out;
501 }
502
503 if (!c->set_config_item(c, "lxc.net.0.link", "lxcbr0")) {
504 fprintf(stderr, "%d: failed to set network.link\n", __LINE__);
505 goto out;
506 }
507
508 if (!c->set_config_item(c, "lxc.net.0.flags", "up")) {
509 fprintf(stderr, "%d: failed to set network.flags\n", __LINE__);
510 goto out;
511 }
512
513 if (!c->set_config_item(c, "lxc.net.0.hwaddr", "00:16:3e:xx:xx:xx")) {
514 fprintf(stderr, "%d: failed to set network.hwaddr\n", __LINE__);
515 goto out;
516 }
517
518 if (!c->set_config_item(c, "lxc.net.0.ipv4.address", "10.2.3.4")) {
519 fprintf(stderr, "%d: failed to set ipv4\n", __LINE__);
520 goto out;
521 }
522
523 ret = c->get_config_item(c, "lxc.net.0.ipv4.address", v2, 255);
524 if (ret <= 0) {
525 fprintf(stderr, "%d: lxc.net.0.ipv4 returned %d\n", __LINE__, ret);
526 goto out;
527 }
528
529 if (!c->clear_config_item(c, "lxc.net.0.ipv4.address")) {
530 fprintf(stderr, "%d: failed clearing all ipv4 entries\n", __LINE__);
531 goto out;
532 }
533
534 ret = c->get_config_item(c, "lxc.net.0.ipv4.address", v2, 255);
535 if (ret != 0) {
536 fprintf(stderr, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__, ret);
537 goto out;
538 }
539
540 if (!c->set_config_item(c, "lxc.net.0.ipv4.gateway", "10.2.3.254")) {
541 fprintf(stderr, "%d: failed to set ipv4.gateway\n", __LINE__);
542 goto out;
543 }
544
545 ret = c->get_config_item(c, "lxc.net.0.ipv4.gateway", v2, 255);
546 if (ret <= 0) {
547 fprintf(stderr, "%d: lxc.net.0.ipv4.gateway returned %d\n", __LINE__, ret);
548 goto out;
549 }
550
551 if (!c->set_config_item(c, "lxc.net.0.ipv4.gateway", "")) {
552 fprintf(stderr, "%d: failed clearing ipv4.gateway\n", __LINE__);
553 goto out;
554 }
555
556 ret = c->get_config_item(c, "lxc.net.0.ipv4.gateway", v2, 255);
557 if (ret != 0) {
558 fprintf(stderr, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__, ret);
559 goto out;
560 }
561
562 ret = c->get_config_item(c, "lxc.net.0.link", v2, 255);
563 if (ret < 0) {
564 fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
565 goto out;
566 }
567 printf("%d: get_config_item (link) returned %d %s\n", __LINE__, ret, v2);
568
569 ret = c->get_config_item(c, "lxc.net.0.name", v2, 255);
570 if (ret < 0) {
571 fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
572 goto out;
573 }
574 printf("%d: get_config_item (name) returned %d %s\n", __LINE__, ret, v2);
575
576 if (!c->clear_config_item(c, "lxc.net")) {
577 fprintf(stderr, "%d: clear_config_item failed\n", __LINE__);
578 goto out;
579 }
580
581 ret = c->get_config_item(c, "lxc.net", v2, 255);
582 if (ret != 0) {
583 fprintf(stderr, "%d: network was not actually cleared (get_network returned %d)\n", __LINE__, ret);
584 goto out;
585 }
586
587 ret = c->get_config_item(c, "lxc.cgroup", v3, 2047);
588 if (ret < 0) {
589 fprintf(stderr, "%d: get_config_item(cgroup.devices) returned %d\n", __LINE__, ret);
590 goto out;
591 }
592 printf("%d: get_config_item (cgroup.devices) returned %d %s\n", __LINE__, ret, v3);
593
594 ret = c->get_config_item(c, "lxc.cgroup.devices.allow", v3, 2047);
595 if (ret < 0) {
596 fprintf(stderr, "%d: get_config_item(cgroup.devices.devices.allow) returned %d\n", __LINE__, ret);
597 goto out;
598 }
599 printf("%d: get_config_item (cgroup.devices.devices.allow) returned %d %s\n", __LINE__, ret, v3);
600
601 if (!c->clear_config_item(c, "lxc.cgroup")) {
602 fprintf(stderr, "%d: failed clearing lxc.cgroup\n", __LINE__);
603 goto out;
604 }
605
606 if (!c->clear_config_item(c, "lxc.cap.drop")) {
607 fprintf(stderr, "%d: failed clearing lxc.cap.drop\n", __LINE__);
608 goto out;
609 }
610
611 if (!c->clear_config_item(c, "lxc.mount.entry")) {
612 fprintf(stderr, "%d: failed clearing lxc.mount.entry\n", __LINE__);
613 goto out;
614 }
615
616 if (!c->clear_config_item(c, "lxc.hook")) {
617 fprintf(stderr, "%d: failed clearing lxc.hook\n", __LINE__);
618 goto out;
619 }
620
621 if (!lxc_config_item_is_supported("lxc.arch")) {
622 fprintf(stderr, "%d: failed to report \"lxc.arch\" as supported configuration item\n", __LINE__);
623 goto out;
624 }
625
626 if (lxc_config_item_is_supported("lxc.nonsense")) {
627 fprintf(stderr, "%d: failed to detect \"lxc.nonsense\" as unsupported configuration item\n", __LINE__);
628 goto out;
629 }
630
631 if (lxc_config_item_is_supported("lxc.arch.nonsense")) {
632 fprintf(stderr, "%d: failed to detect \"lxc.arch.nonsense\" as unsupported configuration item\n", __LINE__);
633 goto out;
634 }
635
636 if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
637 fprintf(stderr, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__);
638 goto out;
639 }
640
641
642 printf("All get_item tests passed\n");
643 fret = EXIT_SUCCESS;
644
645 out:
646 if (c) {
647 c->destroy(c);
648 lxc_container_put(c);
649 }
650
651 exit(fret);
652 }