]>
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.
19 #include <lxc/lxccontainer.h>
24 #include <sys/types.h>
30 #include "lxc/state.h"
38 #define MYNAME "lxctest1"
40 int main(int argc
, char *argv
[])
43 struct lxc_container
*c
= NULL
;
44 int fret
= EXIT_FAILURE
;
45 char v1
[2], v2
[256], v3
[2048];
46 struct lxc_log log
= {};
47 char template[sizeof(P_tmpdir
"/attach_XXXXXX")];
49 (void)strlcpy(template, P_tmpdir
"/attach_XXXXXX", sizeof(template));
51 fd_log
= lxc_make_tmpfile(template, false);
53 lxc_error("Failed to create temporary log file for container %s\n", MYNAME
);
59 log
.prefix
= "get_item";
62 if (lxc_log_init(&log
))
65 if ((c
= lxc_container_new("testxyz", NULL
)) == NULL
) {
66 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
70 /* EXPECT SUCCESS: lxc.log.syslog with valid value. */
71 if (!c
->set_config_item(c
, "lxc.log.syslog", "local0")) {
72 lxc_error("%s\n", "Failed to set lxc.log.syslog.\n");
76 ret
= c
->get_config_item(c
, "lxc.log.syslog", v2
, 255);
78 lxc_error("Failed to retrieve lxc.log.syslog: %d.\n", ret
);
82 if (strcmp(v2
, "local0") != 0) {
83 lxc_error("Expected: local0 == %s.\n", v2
);
86 lxc_debug("Retrieving value for lxc.log.syslog correctly returned: %s.\n", v2
);
88 /* EXPECT FAILURE: lxc.log.syslog with invalid value. */
89 if (c
->set_config_item(c
, "lxc.log.syslog", "NONSENSE")) {
90 lxc_error("%s\n", "Succeeded int setting lxc.log.syslog to invalid value \"NONSENSE\".\n");
93 lxc_debug("%s\n", "Successfully failed to set lxc.log.syslog to invalid value.\n");
95 if (!c
->set_config_item(c
, "lxc.hook.pre-start", "hi there")) {
96 fprintf(stderr
, "%d: failed to set hook.pre-start\n", __LINE__
);
100 ret
= c
->get_config_item(c
, "lxc.hook.pre-start", v2
, 255);
102 fprintf(stderr
, "%d: get_config_item(lxc.hook.pre-start) returned %d\n", __LINE__
, ret
);
105 fprintf(stderr
, "lxc.hook.pre-start returned %d %s\n", ret
, v2
);
107 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
109 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
112 fprintf(stderr
, "%d: get_config_item(lxc.net) returned %d %s\n", __LINE__
, ret
, v2
);
114 if (!c
->set_config_item(c
, "lxc.tty.max", "4")) {
115 fprintf(stderr
, "%d: failed to set tty\n", __LINE__
);
119 ret
= c
->get_config_item(c
, "lxc.tty.max", v2
, 255);
121 fprintf(stderr
, "%d: get_config_item(lxc.tty) returned %d\n", __LINE__
, ret
);
124 fprintf(stderr
, "lxc.tty returned %d %s\n", ret
, v2
);
126 if (!c
->set_config_item(c
, "lxc.arch", "x86")) {
127 fprintf(stderr
, "%d: failed to set arch\n", __LINE__
);
131 ret
= c
->get_config_item(c
, "lxc.arch", v2
, 255);
133 fprintf(stderr
, "%d: get_config_item(lxc.arch) returned %d\n", __LINE__
, ret
);
136 printf("lxc.arch returned %d %s\n", ret
, v2
);
138 if (!c
->set_config_item(c
, "lxc.init.uid", "100")) {
139 fprintf(stderr
, "%d: failed to set init_uid\n", __LINE__
);
143 ret
= c
->get_config_item(c
, "lxc.init.uid", v2
, 255);
145 fprintf(stderr
, "%d: get_config_item(lxc.init_uid) returned %d\n", __LINE__
, ret
);
148 printf("lxc.init_uid returned %d %s\n", ret
, v2
);
150 if (!c
->set_config_item(c
, "lxc.init.gid", "100")) {
151 fprintf(stderr
, "%d: failed to set init_gid\n", __LINE__
);
155 ret
= c
->get_config_item(c
, "lxc.init.gid", v2
, 255);
157 fprintf(stderr
, "%d: get_config_item(lxc.init_gid) returned %d\n", __LINE__
, ret
);
160 printf("lxc.init_gid returned %d %s\n", ret
, v2
);
162 if (c
->set_config_item(c
, "lxc.init.groups", "10,20,foo,40")) {
163 fprintf(stderr
, "%d: managed to set lxc.init.groups to '10,20,foo,40'\n", __LINE__
);
167 if (!c
->set_config_item(c
, "lxc.init.groups", "10,20,30,40")) {
168 fprintf(stderr
, "%d: managed to set lxc.init.groups to '10,20,30,40'\n", __LINE__
);
172 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
174 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
177 ret
= strcmp("10,20,30,40", v2
);
178 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
183 if (!c
->set_config_item(c
, "lxc.init.groups", "50,60,70,80")) {
184 fprintf(stderr
, "%d: failed to set lxc.init.groups to '50,60,70,80'\n", __LINE__
);
188 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
190 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
193 ret
= strcmp("10,20,30,40,50,60,70,80", v2
);
194 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
199 if (!c
->set_config_item(c
, "lxc.init.groups", "")) {
200 fprintf(stderr
, "%d: failed to set lxc.init.groups to ''\n", __LINE__
);
204 ret
= c
->get_config_item(c
, "lxc.init.groups", v2
, 255);
206 fprintf(stderr
, "%d: failed to get lxc.init.groups\n", __LINE__
);
209 ret
= strcmp("", v2
);
210 printf("%d: lxc.init.groups returned %d %s\n", __LINE__
, ret
, v2
);
215 #define HNAME "hostname1"
216 // demonstrate proper usage:
220 if (!c
->set_config_item(c
, "lxc.uts.name", HNAME
)) {
221 fprintf(stderr
, "%d: failed to set utsname\n", __LINE__
);
225 len
= c
->get_config_item(c
, "lxc.uts.name", NULL
, 0); // query the size of the string
227 fprintf(stderr
, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__
, len
);
230 printf("lxc.utsname returned %d\n", len
);
232 // allocate the length of string + 1 for trailing \0
233 alloced
= malloc(len
+1);
235 fprintf(stderr
, "%d: failed to allocate %d bytes for utsname\n", __LINE__
, len
);
239 // now pass in the malloc'd array, and pass in length of string + 1: again
240 // because we need room for the trailing \0
241 ret
= c
->get_config_item(c
, "lxc.uts.name", alloced
, len
+1);
243 fprintf(stderr
, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__
, ret
);
247 if (strcmp(alloced
, HNAME
) != 0 || ret
!= len
) {
248 fprintf(stderr
, "lxc.utsname returned wrong value: %d %s not %d %s\n", ret
, alloced
, len
, HNAME
);
251 printf("lxc.utsname returned %d %s\n", len
, alloced
);
254 if (!c
->set_config_item(c
, "lxc.mount.entry", "hi there")) {
255 fprintf(stderr
, "%d: failed to set mount.entry\n", __LINE__
);
259 ret
= c
->get_config_item(c
, "lxc.mount.entry", v2
, 255);
261 fprintf(stderr
, "%d: get_config_item(lxc.mount.entry) returned %d\n", __LINE__
, ret
);
264 printf("lxc.mount.entry returned %d %s\n", ret
, v2
);
266 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
268 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
272 if (!c
->set_config_item(c
, "lxc.prlimit.nofile", "1234:unlimited")) {
273 fprintf(stderr
, "%d: failed to set limit.nofile\n", __LINE__
);
277 ret
= c
->get_config_item(c
, "lxc.prlimit.nofile", v2
, 255);
279 fprintf(stderr
, "%d: get_config_item(lxc.prlimit.nofile) returned %d\n", __LINE__
, ret
);
283 if (strcmp(v2
, "1234:unlimited")) {
284 fprintf(stderr
, "%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited\n", __LINE__
, ret
, v2
);
287 printf("lxc.prlimit.nofile returned %d %s\n", ret
, v2
);
289 if (!c
->set_config_item(c
, "lxc.prlimit.stack", "unlimited")) {
290 fprintf(stderr
, "%d: failed to set limit.stack\n", __LINE__
);
294 ret
= c
->get_config_item(c
, "lxc.prlimit.stack", v2
, 255);
296 fprintf(stderr
, "%d: get_config_item(lxc.prlimit.stack) returned %d\n", __LINE__
, ret
);
300 if (strcmp(v2
, "unlimited")) {
301 fprintf(stderr
, "%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited\n", __LINE__
, ret
, v2
);
304 printf("lxc.prlimit.stack returned %d %s\n", ret
, v2
);
306 #define LIMIT_STACK "lxc.prlimit.stack = unlimited\n"
307 #define ALL_LIMITS "lxc.prlimit.nofile = 1234:unlimited\n" LIMIT_STACK
308 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
309 if (ret
!= sizeof(ALL_LIMITS
)-1) {
310 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
314 if (strcmp(v3
, ALL_LIMITS
)) {
315 fprintf(stderr
, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_LIMITS
)-1, ALL_LIMITS
);
318 printf("lxc.prlimit returned %d %s\n", ret
, v3
);
320 if (!c
->clear_config_item(c
, "lxc.prlimit.nofile")) {
321 fprintf(stderr
, "%d: failed clearing limit.nofile\n", __LINE__
);
325 ret
= c
->get_config_item(c
, "lxc.prlimit", v3
, 2047);
326 if (ret
!= sizeof(LIMIT_STACK
)-1) {
327 fprintf(stderr
, "%d: get_config_item(limit) returned %d\n", __LINE__
, ret
);
331 if (strcmp(v3
, LIMIT_STACK
)) {
332 fprintf(stderr
, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(LIMIT_STACK
)-1, LIMIT_STACK
);
335 printf("lxc.prlimit returned %d %s\n", ret
, v3
);
337 #define SYSCTL_SOMAXCONN "lxc.sysctl.net.core.somaxconn = 256\n"
338 #define ALL_SYSCTLS "lxc.sysctl.net.ipv4.ip_forward = 1\n" SYSCTL_SOMAXCONN
340 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
342 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
346 if (!c
->set_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward", "1")) {
347 fprintf(stderr
, "%d: failed to set lxc.sysctl.net.ipv4.ip_forward\n", __LINE__
);
351 ret
= c
->get_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward", v2
, 255);
353 fprintf(stderr
, "%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d\n", __LINE__
, ret
);
357 if (strcmp(v2
, "1")) {
358 fprintf(stderr
, "%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1\n", __LINE__
, ret
, v2
);
361 printf("lxc.sysctl.net.ipv4.ip_forward returned %d %s\n", ret
, v2
);
363 if (!c
->set_config_item(c
, "lxc.sysctl.net.core.somaxconn", "256")) {
364 fprintf(stderr
, "%d: failed to set lxc.sysctl.net.core.somaxconn\n", __LINE__
);
368 ret
= c
->get_config_item(c
, "lxc.sysctl.net.core.somaxconn", v2
, 255);
370 fprintf(stderr
, "%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d\n", __LINE__
, ret
);
374 if (strcmp(v2
, "256")) {
375 fprintf(stderr
, "%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256\n", __LINE__
, ret
, v2
);
378 printf("lxc.sysctl.net.core.somaxconn returned %d %s\n", ret
, v2
);
380 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
381 if (ret
!= sizeof(ALL_SYSCTLS
)-1) {
382 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
386 if (strcmp(v3
, ALL_SYSCTLS
)) {
387 fprintf(stderr
, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_SYSCTLS
) - 1, ALL_SYSCTLS
);
390 printf("lxc.sysctl returned %d %s\n", ret
, v3
);
392 if (!c
->clear_config_item(c
, "lxc.sysctl.net.ipv4.ip_forward")) {
393 fprintf(stderr
, "%d: failed clearing lxc.sysctl.net.ipv4.ip_forward\n", __LINE__
);
397 ret
= c
->get_config_item(c
, "lxc.sysctl", v3
, 2047);
398 if (ret
!= sizeof(SYSCTL_SOMAXCONN
) - 1) {
399 fprintf(stderr
, "%d: get_config_item(sysctl) returned %d\n", __LINE__
, ret
);
403 if (strcmp(v3
, SYSCTL_SOMAXCONN
)) {
404 fprintf(stderr
, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(SYSCTL_SOMAXCONN
) - 1, SYSCTL_SOMAXCONN
);
407 printf("lxc.sysctl returned %d %s\n", ret
, v3
);
409 #define PROC_OOM_SCORE_ADJ "lxc.proc.oom_score_adj = 10\n"
410 #define ALL_PROCS "lxc.proc.setgroups = allow\n" PROC_OOM_SCORE_ADJ
412 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
414 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
418 if (!c
->set_config_item(c
, "lxc.proc.setgroups", "allow")) {
419 fprintf(stderr
, "%d: failed to set lxc.proc.setgroups\n", __LINE__
);
423 ret
= c
->get_config_item(c
, "lxc.proc.setgroups", v2
, 255);
425 fprintf(stderr
, "%d: get_config_item(lxc.proc.setgroups) returned %d\n", __LINE__
, ret
);
429 if (strcmp(v2
, "allow")) {
430 fprintf(stderr
, "%d: lxc.proc.setgroups returned wrong value: %d %s not 10\n", __LINE__
, ret
, v2
);
433 printf("lxc.proc.setgroups returned %d %s\n", ret
, v2
);
435 if (!c
->set_config_item(c
, "lxc.proc.oom_score_adj", "10")) {
436 fprintf(stderr
, "%d: failed to set lxc.proc.oom_score_adj\n", __LINE__
);
440 ret
= c
->get_config_item(c
, "lxc.proc.oom_score_adj", v2
, 255);
442 fprintf(stderr
, "%d: get_config_item(lxc.proc.oom_score_adj) returned %d\n", __LINE__
, ret
);
446 if (strcmp(v2
, "10")) {
447 fprintf(stderr
, "%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10\n", __LINE__
, ret
, v2
);
450 printf("lxc.proc.oom_score_adj returned %d %s\n", ret
, v2
);
452 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
453 if (ret
!= sizeof(ALL_PROCS
)-1) {
454 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
458 if (strcmp(v3
, ALL_PROCS
)) {
459 fprintf(stderr
, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__
, ret
, v3
, (int)sizeof(ALL_PROCS
) - 1, ALL_PROCS
);
462 printf("lxc.proc returned %d %s\n", ret
, v3
);
464 if (!c
->clear_config_item(c
, "lxc.proc.setgroups")) {
465 fprintf(stderr
, "%d: failed clearing lxc.proc.setgroups\n", __LINE__
);
469 ret
= c
->get_config_item(c
, "lxc.proc", v3
, 2047);
471 fprintf(stderr
, "%d: get_config_item(proc) returned %d\n", __LINE__
, ret
);
475 if (strcmp(v3
, PROC_OOM_SCORE_ADJ
)) {
476 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
);
479 printf("lxc.proc returned %d %s\n", ret
, v3
);
481 if (!c
->set_config_item(c
, "lxc.apparmor.profile", "unconfined")) {
482 fprintf(stderr
, "%d: failed to set aa_profile\n", __LINE__
);
486 ret
= c
->get_config_item(c
, "lxc.apparmor.profile", v2
, 255);
488 fprintf(stderr
, "%d: get_config_item(lxc.aa_profile) returned %d\n", __LINE__
, ret
);
491 printf("lxc.aa_profile returned %d %s\n", ret
, v2
);
493 lxc_container_put(c
);
495 // new test with real container
496 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
497 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
501 lxc_container_put(c
);
503 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
504 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
508 if (!c
->createl(c
, "busybox", NULL
, NULL
, 0, NULL
)) {
509 fprintf(stderr
, "%d: failed to create a trusty container\n", __LINE__
);
512 lxc_container_put(c
);
514 /* XXX TODO load_config needs to clear out any old config first */
515 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
516 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
520 ret
= c
->get_config_item(c
, "lxc.cap.drop", NULL
, 300);
521 if (ret
< 5 || ret
> 255) {
522 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) with NULL returned %d\n", __LINE__
, ret
);
526 ret
= c
->get_config_item(c
, "lxc.cap.drop", v1
, 1);
527 if (ret
< 5 || ret
> 255) {
528 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) returned %d\n", __LINE__
, ret
);
532 ret
= c
->get_config_item(c
, "lxc.cap.drop", v2
, 255);
534 fprintf(stderr
, "%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__
, ret
, v2
);
537 printf("%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__
, ret
, v2
);
539 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
541 fprintf(stderr
, "%d: get_config_item(lxc.net) returned %d\n", __LINE__
, ret
);
544 printf("%d: get_config_item(lxc.net) returned %d %s\n", __LINE__
, ret
, v2
);
546 if (!c
->set_config_item(c
, "lxc.net.0.type", "veth")) {
547 fprintf(stderr
, "%d: failed to set lxc.net.0.type\n", __LINE__
);
551 if (!c
->set_config_item(c
, "lxc.net.0.link", "lxcbr0")) {
552 fprintf(stderr
, "%d: failed to set network.link\n", __LINE__
);
556 if (!c
->set_config_item(c
, "lxc.net.0.flags", "up")) {
557 fprintf(stderr
, "%d: failed to set network.flags\n", __LINE__
);
561 if (!c
->set_config_item(c
, "lxc.net.0.hwaddr", "00:16:3e:xx:xx:xx")) {
562 fprintf(stderr
, "%d: failed to set network.hwaddr\n", __LINE__
);
566 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.address", "10.2.3.4")) {
567 fprintf(stderr
, "%d: failed to set ipv4\n", __LINE__
);
571 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.address", v2
, 255);
573 fprintf(stderr
, "%d: lxc.net.0.ipv4 returned %d\n", __LINE__
, ret
);
577 if (!c
->clear_config_item(c
, "lxc.net.0.ipv4.address")) {
578 fprintf(stderr
, "%d: failed clearing all ipv4 entries\n", __LINE__
);
582 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.address", v2
, 255);
584 fprintf(stderr
, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__
, ret
);
588 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.gateway", "10.2.3.254")) {
589 fprintf(stderr
, "%d: failed to set ipv4.gateway\n", __LINE__
);
593 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.gateway", v2
, 255);
595 fprintf(stderr
, "%d: lxc.net.0.ipv4.gateway returned %d\n", __LINE__
, ret
);
599 if (!c
->set_config_item(c
, "lxc.net.0.ipv4.gateway", "")) {
600 fprintf(stderr
, "%d: failed clearing ipv4.gateway\n", __LINE__
);
604 ret
= c
->get_config_item(c
, "lxc.net.0.ipv4.gateway", v2
, 255);
606 fprintf(stderr
, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__
, ret
);
610 ret
= c
->get_config_item(c
, "lxc.net.0.link", v2
, 255);
612 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
615 printf("%d: get_config_item (link) returned %d %s\n", __LINE__
, ret
, v2
);
617 ret
= c
->get_config_item(c
, "lxc.net.0.name", v2
, 255);
619 fprintf(stderr
, "%d: get_config_item returned %d\n", __LINE__
, ret
);
622 printf("%d: get_config_item (name) returned %d %s\n", __LINE__
, ret
, v2
);
624 if (!c
->clear_config_item(c
, "lxc.net")) {
625 fprintf(stderr
, "%d: clear_config_item failed\n", __LINE__
);
629 ret
= c
->get_config_item(c
, "lxc.net", v2
, 255);
631 fprintf(stderr
, "%d: network was not actually cleared (get_network returned %d)\n", __LINE__
, ret
);
635 ret
= c
->get_config_item(c
, "lxc.cgroup", v3
, 2047);
637 fprintf(stderr
, "%d: get_config_item(cgroup.devices) returned %d\n", __LINE__
, ret
);
640 printf("%d: get_config_item (cgroup.devices) returned %d %s\n", __LINE__
, ret
, v3
);
642 ret
= c
->get_config_item(c
, "lxc.cgroup.devices.allow", v3
, 2047);
644 fprintf(stderr
, "%d: get_config_item(cgroup.devices.devices.allow) returned %d\n", __LINE__
, ret
);
647 printf("%d: get_config_item (cgroup.devices.devices.allow) returned %d %s\n", __LINE__
, ret
, v3
);
649 if (!c
->clear_config_item(c
, "lxc.cgroup")) {
650 fprintf(stderr
, "%d: failed clearing lxc.cgroup\n", __LINE__
);
654 if (!c
->clear_config_item(c
, "lxc.cap.drop")) {
655 fprintf(stderr
, "%d: failed clearing lxc.cap.drop\n", __LINE__
);
659 if (!c
->clear_config_item(c
, "lxc.mount.entry")) {
660 fprintf(stderr
, "%d: failed clearing lxc.mount.entry\n", __LINE__
);
664 if (!c
->clear_config_item(c
, "lxc.hook")) {
665 fprintf(stderr
, "%d: failed clearing lxc.hook\n", __LINE__
);
669 if (!lxc_config_item_is_supported("lxc.arch")) {
670 fprintf(stderr
, "%d: failed to report \"lxc.arch\" as supported configuration item\n", __LINE__
);
674 if (lxc_config_item_is_supported("lxc.nonsense")) {
675 fprintf(stderr
, "%d: failed to detect \"lxc.nonsense\" as unsupported configuration item\n", __LINE__
);
679 if (lxc_config_item_is_supported("lxc.arch.nonsense")) {
680 fprintf(stderr
, "%d: failed to detect \"lxc.arch.nonsense\" as unsupported configuration item\n", __LINE__
);
684 if (c
->set_config_item(c
, "lxc.notaconfigkey", "invalid")) {
685 fprintf(stderr
, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__
);
690 printf("All get_item tests passed\n");
696 lxc_container_put(c
);
698 if (fret
!= EXIT_SUCCESS
) {
701 while ((buflen
= read(fd_log
, buf
, 1024)) > 0) {
702 buflen
= write(STDERR_FILENO
, buf
, buflen
);
708 (void)unlink(template);