]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/get_item.c
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
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.
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.
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.
22 #include <lxc/lxccontainer.h>
27 #include <sys/types.h>
41 #define MYNAME "lxctest1"
43 int main(int argc
, char *argv
[])
46 struct lxc_container
*c
= NULL
;
47 int fret
= EXIT_FAILURE
;
48 char v1
[2], v2
[256], v3
[2048];
49 struct lxc_log log
= {};
50 char template[sizeof(P_tmpdir
"/attach_XXXXXX")];
52 (void)strlcpy(template, P_tmpdir
"/attach_XXXXXX", sizeof(template));
54 fd_log
= lxc_make_tmpfile(template, false);
56 lxc_error("Failed to create temporary log file for container %s\n", MYNAME
);
62 log
.prefix
= "get_item";
65 if (lxc_log_init(&log
))
68 if ((c
= lxc_container_new("testxyz", NULL
)) == NULL
) {
69 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
73 /* EXPECT SUCCESS: lxc.log.syslog with valid value. */
74 if (!c
->set_config_item(c
, "lxc.log.syslog", "local0")) {
75 lxc_error("%s\n", "Failed to set lxc.log.syslog.\n");
79 ret
= c
->get_config_item(c
, "lxc.log.syslog", v2
, 255);
81 lxc_error("Failed to retrieve lxc.log.syslog: %d.\n", ret
);
85 if (strcmp(v2
, "local0") != 0) {
86 lxc_error("Expected: local0 == %s.\n", v2
);
89 lxc_debug("Retrieving value for lxc.log.syslog correctly returned: %s.\n", v2
);
91 /* EXPECT FAILURE: lxc.log.syslog with invalid value. */
92 if (c
->set_config_item(c
, "lxc.log.syslog", "NONSENSE")) {
93 lxc_error("%s\n", "Succeeded int setting lxc.log.syslog to invalid value \"NONSENSE\".\n");
96 lxc_debug("%s\n", "Successfully failed to set lxc.log.syslog to invalid value.\n");
98 if (!c
->set_config_item(c
, "lxc.hook.pre-start", "hi there")) {
99 fprintf(stderr
, "%d: failed to set hook.pre-start\n", __LINE__
);
103 ret
= c
->get_config_item(c
, "lxc.hook.pre-start", v2
, 255);
105 fprintf(stderr
, "%d: get_config_item(lxc.hook.pre-start) returned %d\n", __LINE__
, ret
);
108 fprintf(stderr
, "lxc.hook.pre-start returned %d %s\n", ret
, v2
);
110 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
112 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
115 fprintf(stderr
, "%d: get_config_item(lxc.net) returned %d %s\n", __LINE__
, ret
, v2
);
117 if (!c
->set_config_item(c
, "lxc.tty.max", "4")) {
118 fprintf(stderr
, "%d: failed to set tty\n", __LINE__
);
122 ret
= c
->get_config_item(c
, "lxc.tty.max", v2
, 255);
124 fprintf(stderr
, "%d: get_config_item(lxc.tty) returned %d\n", __LINE__
, ret
);
127 fprintf(stderr
, "lxc.tty returned %d %s\n", ret
, v2
);
129 if (!c
->set_config_item(c
, "lxc.arch", "x86")) {
130 fprintf(stderr
, "%d: failed to set arch\n", __LINE__
);
134 ret
= c
->get_config_item(c
, "lxc.arch", v2
, 255);
136 fprintf(stderr
, "%d: get_config_item(lxc.arch) returned %d\n", __LINE__
, ret
);
139 printf("lxc.arch returned %d %s\n", ret
, v2
);
141 if (!c
->set_config_item(c
, "lxc.init.uid", "100")) {
142 fprintf(stderr
, "%d: failed to set init_uid\n", __LINE__
);
146 ret
= c
->get_config_item(c
, "lxc.init.uid", v2
, 255);
148 fprintf(stderr
, "%d: get_config_item(lxc.init_uid) returned %d\n", __LINE__
, ret
);
151 printf("lxc.init_uid returned %d %s\n", ret
, v2
);
153 if (!c
->set_config_item(c
, "lxc.init.gid", "100")) {
154 fprintf(stderr
, "%d: failed to set init_gid\n", __LINE__
);
158 ret
= c
->get_config_item(c
, "lxc.init.gid", v2
, 255);
160 fprintf(stderr
, "%d: get_config_item(lxc.init_gid) returned %d\n", __LINE__
, ret
);
163 printf("lxc.init_gid returned %d %s\n", ret
, v2
);
165 if (c
->set_config_item(c
, "lxc.init.groups", "10,20,foo,40")) {
166 fprintf(stderr
, "%d: managed to set lxc.init.groups to '10,20,foo,40'\n", __LINE__
);
170 if (!c
->set_config_item(c
, "lxc.init.groups", "10,20,30,40")) {
171 fprintf(stderr
, "%d: managed to set lxc.init.groups to '10,20,30,40'\n", __LINE__
);
175 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
177 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
180 ret
= strcmp("10,20,30,40", v2
);
181 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
186 if (!c
->set_config_item(c
, "lxc.init.groups", "50,60,70,80")) {
187 fprintf(stderr
, "%d: failed to set lxc.init.groups to '50,60,70,80'\n", __LINE__
);
191 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
193 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
196 ret
= strcmp("10,20,30,40,50,60,70,80", v2
);
197 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
202 if (!c
->set_config_item(c
, "lxc.init.groups", "")) {
203 fprintf(stderr
, "%d: failed to set lxc.init.groups to ''\n", __LINE__
);
207 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
209 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
212 ret
= strcmp("", v2
);
213 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
218 #define HNAME "hostname1"
219 // demonstrate proper usage:
223 if (!c
->set_config_item(c
, "lxc.uts.name", HNAME
)) {
224 fprintf(stderr
, "%d: failed to set utsname\n", __LINE__
);
228 len
= c
->get_config_item(c
, "lxc.uts.name", NULL
, 0); // query the size of the string
230 fprintf(stderr
, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__
, len
);
233 printf("lxc.utsname returned %d\n", len
);
235 // allocate the length of string + 1 for trailing \0
236 alloced
= malloc(len
+1);
238 fprintf(stderr
, "%d: failed to allocate %d bytes for utsname\n", __LINE__
, len
);
242 // now pass in the malloc'd array, and pass in length of string + 1: again
243 // because we need room for the trailing \0
244 ret
= c
->get_config_item(c
, "lxc.uts.name", alloced
, len
+1);
246 fprintf(stderr
, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__
, ret
);
250 if (strcmp(alloced
, HNAME
) != 0 || ret
!= len
) {
251 fprintf(stderr
, "lxc.utsname returned wrong value: %d %s not %d %s\n", ret
, alloced
, len
, HNAME
);
254 printf("lxc.utsname returned %d %s\n", len
, alloced
);
257 if (!c
->set_config_item(c
, "lxc.mount.entry", "hi there")) {
258 fprintf(stderr
, "%d: failed to set mount.entry\n", __LINE__
);
262 ret
= c
->get_config_item(c
, "lxc.mount.entry", v2
, 255);
264 fprintf(stderr
, "%d: get_config_item(lxc.mount.entry) returned %d\n", __LINE__
, ret
);
267 printf("lxc.mount.entry returned %d %s\n", ret
, v2
);
269 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
271 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
275 if (!c
->set_config_item(c
, "lxc.prlimit.nofile", "1234:unlimited")) {
276 fprintf(stderr
, "%d: failed to set limit.nofile\n", __LINE__
);
280 ret
= c
->get_config_item(c
, "lxc.prlimit.nofile", v2
, 255);
282 fprintf(stderr
, "%d: get_config_item(lxc.prlimit.nofile) returned %d\n", __LINE__
, ret
);
286 if (strcmp(v2
, "1234:unlimited")) {
287 fprintf(stderr
, "%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited\n", __LINE__
, ret
, v2
);
290 printf("lxc.prlimit.nofile returned %d %s\n", ret
, v2
);
292 if (!c
->set_config_item(c
, "lxc.prlimit.stack", "unlimited")) {
293 fprintf(stderr
, "%d: failed to set limit.stack\n", __LINE__
);
297 ret
= c
->get_config_item(c
, "lxc.prlimit.stack", v2
, 255);
299 fprintf(stderr
, "%d: get_config_item(lxc.prlimit.stack) returned %d\n", __LINE__
, ret
);
303 if (strcmp(v2
, "unlimited")) {
304 fprintf(stderr
, "%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited\n", __LINE__
, ret
, v2
);
307 printf("lxc.prlimit.stack returned %d %s\n", ret
, v2
);
309 #define LIMIT_STACK "lxc.prlimit.stack = unlimited\n"
310 #define ALL_LIMITS "lxc.prlimit.nofile = 1234:unlimited\n" LIMIT_STACK
311 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
312 if (ret
!= sizeof(ALL_LIMITS
)-1) {
313 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
317 if (strcmp(v3
, ALL_LIMITS
)) {
318 fprintf(stderr
, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_LIMITS
)-1, ALL_LIMITS
);
321 printf("lxc.prlimit returned %d %s\n", ret
, v3
);
323 if (!c
->clear_config_item(c
, "lxc.prlimit.nofile")) {
324 fprintf(stderr
, "%d: failed clearing limit.nofile\n", __LINE__
);
328 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
329 if (ret
!= sizeof(LIMIT_STACK
)-1) {
330 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
334 if (strcmp(v3
, LIMIT_STACK
)) {
335 fprintf(stderr
, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(LIMIT_STACK
)-1, LIMIT_STACK
);
338 printf("lxc.prlimit returned %d %s\n", ret
, v3
);
340 #define SYSCTL_SOMAXCONN "lxc.sysctl.net.core.somaxconn = 256\n"
341 #define ALL_SYSCTLS "lxc.sysctl.net.ipv4.ip_forward = 1\n" SYSCTL_SOMAXCONN
343 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
345 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
349 if (!c
->set_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward", "1")) {
350 fprintf(stderr
, "%d: failed to set lxc.sysctl.net.ipv4.ip_forward\n", __LINE__
);
354 ret
= c
->get_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward", v2
, 255);
356 fprintf(stderr
, "%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d\n", __LINE__
, ret
);
360 if (strcmp(v2
, "1")) {
361 fprintf(stderr
, "%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1\n", __LINE__
, ret
, v2
);
364 printf("lxc.sysctl.net.ipv4.ip_forward returned %d %s\n", ret
, v2
);
366 if (!c
->set_config_item(c
, "lxc.sysctl.net.core.somaxconn", "256")) {
367 fprintf(stderr
, "%d: failed to set lxc.sysctl.net.core.somaxconn\n", __LINE__
);
371 ret
= c
->get_config_item(c
, "lxc.sysctl.net.core.somaxconn", v2
, 255);
373 fprintf(stderr
, "%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d\n", __LINE__
, ret
);
377 if (strcmp(v2
, "256")) {
378 fprintf(stderr
, "%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256\n", __LINE__
, ret
, v2
);
381 printf("lxc.sysctl.net.core.somaxconn returned %d %s\n", ret
, v2
);
383 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
384 if (ret
!= sizeof(ALL_SYSCTLS
)-1) {
385 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
389 if (strcmp(v3
, ALL_SYSCTLS
)) {
390 fprintf(stderr
, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_SYSCTLS
) - 1, ALL_SYSCTLS
);
393 printf("lxc.sysctl returned %d %s\n", ret
, v3
);
395 if (!c
->clear_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward")) {
396 fprintf(stderr
, "%d: failed clearing lxc.sysctl.net.ipv4.ip_forward\n", __LINE__
);
400 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
401 if (ret
!= sizeof(SYSCTL_SOMAXCONN
) - 1) {
402 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
406 if (strcmp(v3
, SYSCTL_SOMAXCONN
)) {
407 fprintf(stderr
, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(SYSCTL_SOMAXCONN
) - 1, SYSCTL_SOMAXCONN
);
410 printf("lxc.sysctl returned %d %s\n", ret
, v3
);
412 #define PROC_OOM_SCORE_ADJ "lxc.proc.oom_score_adj = 10\n"
413 #define ALL_PROCS "lxc.proc.setgroups = allow\n" PROC_OOM_SCORE_ADJ
415 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
417 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
421 if (!c
->set_config_item(c
, "lxc.proc.setgroups", "allow")) {
422 fprintf(stderr
, "%d: failed to set lxc.proc.setgroups\n", __LINE__
);
426 ret
= c
->get_config_item(c
, "lxc.proc.setgroups", v2
, 255);
428 fprintf(stderr
, "%d: get_config_item(lxc.proc.setgroups) returned %d\n", __LINE__
, ret
);
432 if (strcmp(v2
, "allow")) {
433 fprintf(stderr
, "%d: lxc.proc.setgroups returned wrong value: %d %s not 10\n", __LINE__
, ret
, v2
);
436 printf("lxc.proc.setgroups returned %d %s\n", ret
, v2
);
438 if (!c
->set_config_item(c
, "lxc.proc.oom_score_adj", "10")) {
439 fprintf(stderr
, "%d: failed to set lxc.proc.oom_score_adj\n", __LINE__
);
443 ret
= c
->get_config_item(c
, "lxc.proc.oom_score_adj", v2
, 255);
445 fprintf(stderr
, "%d: get_config_item(lxc.proc.oom_score_adj) returned %d\n", __LINE__
, ret
);
449 if (strcmp(v2
, "10")) {
450 fprintf(stderr
, "%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10\n", __LINE__
, ret
, v2
);
453 printf("lxc.proc.oom_score_adj returned %d %s\n", ret
, v2
);
455 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
456 if (ret
!= sizeof(ALL_PROCS
)-1) {
457 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
461 if (strcmp(v3
, ALL_PROCS
)) {
462 fprintf(stderr
, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_PROCS
) - 1, ALL_PROCS
);
465 printf("lxc.proc returned %d %s\n", ret
, v3
);
467 if (!c
->clear_config_item(c
, "lxc.proc.setgroups")) {
468 fprintf(stderr
, "%d: failed clearing lxc.proc.setgroups\n", __LINE__
);
472 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
474 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
478 if (strcmp(v3
, PROC_OOM_SCORE_ADJ
)) {
479 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
);
482 printf("lxc.proc returned %d %s\n", ret
, v3
);
484 if (!c
->set_config_item(c
, "lxc.apparmor.profile", "unconfined")) {
485 fprintf(stderr
, "%d: failed to set aa_profile\n", __LINE__
);
489 ret
= c
->get_config_item(c
, "lxc.apparmor.profile", v2
, 255);
491 fprintf(stderr
, "%d: get_config_item(lxc.aa_profile) returned %d\n", __LINE__
, ret
);
494 printf("lxc.aa_profile returned %d %s\n", ret
, v2
);
496 lxc_container_put(c
);
498 // new test with real container
499 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
500 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
504 lxc_container_put(c
);
506 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
507 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
511 if (!c
->createl(c
, "busybox", NULL
, NULL
, 0, NULL
)) {
512 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
515 lxc_container_put(c
);
517 /* XXX TODO load_config needs to clear out any old config first */
518 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
519 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
523 ret
= c
->get_config_item(c
, "lxc.cap.drop", NULL
, 300);
524 if (ret
< 5 || ret
> 255) {
525 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) with NULL returned %d\n", __LINE__
, ret
);
529 ret
= c
->get_config_item(c
, "lxc.cap.drop", v1
, 1);
530 if (ret
< 5 || ret
> 255) {
531 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) returned %d\n", __LINE__
, ret
);
535 ret
= c
->get_config_item(c
, "lxc.cap.drop", v2
, 255);
537 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__
, ret
, v2
);
540 printf("%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__
, ret
, v2
);
542 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
544 fprintf(stderr
, "%d: get_config_item(lxc.net) returned %d\n", __LINE__
, ret
);
547 printf("%d: get_config_item(lxc.net) returned %d %s\n", __LINE__
, ret
, v2
);
549 if (!c
->set_config_item(c
, "lxc.net.0.type", "veth")) {
550 fprintf(stderr
, "%d: failed to set lxc.net.0.type\n", __LINE__
);
554 if (!c
->set_config_item(c
, "lxc.net.0.link", "lxcbr0")) {
555 fprintf(stderr
, "%d: failed to set network.link\n", __LINE__
);
559 if (!c
->set_config_item(c
, "lxc.net.0.flags", "up")) {
560 fprintf(stderr
, "%d: failed to set network.flags\n", __LINE__
);
564 if (!c
->set_config_item(c
, "lxc.net.0.hwaddr", "00:16:3e:xx:xx:xx")) {
565 fprintf(stderr
, "%d: failed to set network.hwaddr\n", __LINE__
);
569 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.address", "10.2.3.4")) {
570 fprintf(stderr
, "%d: failed to set ipv4\n", __LINE__
);
574 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.address", v2
, 255);
576 fprintf(stderr
, "%d: lxc.net.0.ipv4 returned %d\n", __LINE__
, ret
);
580 if (!c
->clear_config_item(c
, "lxc.net.0.ipv4.address")) {
581 fprintf(stderr
, "%d: failed clearing all ipv4 entries\n", __LINE__
);
585 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.address", v2
, 255);
587 fprintf(stderr
, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__
, ret
);
591 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.gateway", "10.2.3.254")) {
592 fprintf(stderr
, "%d: failed to set ipv4.gateway\n", __LINE__
);
596 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.gateway", v2
, 255);
598 fprintf(stderr
, "%d: lxc.net.0.ipv4.gateway returned %d\n", __LINE__
, ret
);
602 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.gateway", "")) {
603 fprintf(stderr
, "%d: failed clearing ipv4.gateway\n", __LINE__
);
607 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.gateway", v2
, 255);
609 fprintf(stderr
, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__
, ret
);
613 ret
= c
->get_config_item(c
, "lxc.net.0.link", v2
, 255);
615 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
618 printf("%d: get_config_item (link) returned %d %s\n", __LINE__
, ret
, v2
);
620 ret
= c
->get_config_item(c
, "lxc.net.0.name", v2
, 255);
622 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
625 printf("%d: get_config_item (name) returned %d %s\n", __LINE__
, ret
, v2
);
627 if (!c
->clear_config_item(c
, "lxc.net")) {
628 fprintf(stderr
, "%d: clear_config_item failed\n", __LINE__
);
632 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
634 fprintf(stderr
, "%d: network was not actually cleared (get_network returned %d)\n", __LINE__
, ret
);
638 ret
= c
->get_config_item(c
, "lxc.cgroup", v3
, 2047);
640 fprintf(stderr
, "%d: get_config_item(cgroup.devices) returned %d\n", __LINE__
, ret
);
643 printf("%d: get_config_item (cgroup.devices) returned %d %s\n", __LINE__
, ret
, v3
);
645 ret
= c
->get_config_item(c
, "lxc.cgroup.devices.allow", v3
, 2047);
647 fprintf(stderr
, "%d: get_config_item(cgroup.devices.devices.allow) returned %d\n", __LINE__
, ret
);
650 printf("%d: get_config_item (cgroup.devices.devices.allow) returned %d %s\n", __LINE__
, ret
, v3
);
652 if (!c
->clear_config_item(c
, "lxc.cgroup")) {
653 fprintf(stderr
, "%d: failed clearing lxc.cgroup\n", __LINE__
);
657 if (!c
->clear_config_item(c
, "lxc.cap.drop")) {
658 fprintf(stderr
, "%d: failed clearing lxc.cap.drop\n", __LINE__
);
662 if (!c
->clear_config_item(c
, "lxc.mount.entry")) {
663 fprintf(stderr
, "%d: failed clearing lxc.mount.entry\n", __LINE__
);
667 if (!c
->clear_config_item(c
, "lxc.hook")) {
668 fprintf(stderr
, "%d: failed clearing lxc.hook\n", __LINE__
);
672 if (!lxc_config_item_is_supported("lxc.arch")) {
673 fprintf(stderr
, "%d: failed to report \"lxc.arch\" as supported configuration item\n", __LINE__
);
677 if (lxc_config_item_is_supported("lxc.nonsense")) {
678 fprintf(stderr
, "%d: failed to detect \"lxc.nonsense\" as unsupported configuration item\n", __LINE__
);
682 if (lxc_config_item_is_supported("lxc.arch.nonsense")) {
683 fprintf(stderr
, "%d: failed to detect \"lxc.arch.nonsense\" as unsupported configuration item\n", __LINE__
);
687 if (c
->set_config_item(c
, "lxc.notaconfigkey", "invalid")) {
688 fprintf(stderr
, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__
);
693 printf("All get_item tests passed\n");
699 lxc_container_put(c
);
701 if (fret
!= EXIT_SUCCESS
) {
704 while ((buflen
= read(fd_log
, buf
, 1024)) > 0) {
705 buflen
= write(STDERR_FILENO
, buf
, buflen
);
711 (void)unlink(template);