]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/get_item.c
spelling: timeout
[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 #define HNAME "hostname1"
140 // demonstrate proper usage:
141 char *alloced;
142 int len;
143
144 if (!c->set_config_item(c, "lxc.uts.name", HNAME)) {
145 fprintf(stderr, "%d: failed to set utsname\n", __LINE__);
146 goto out;
147 }
148
149 len = c->get_config_item(c, "lxc.uts.name", NULL, 0); // query the size of the string
150 if (len < 0) {
151 fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, len);
152 goto out;
153 }
154 printf("lxc.utsname returned %d\n", len);
155
156 // allocate the length of string + 1 for trailing \0
157 alloced = malloc(len+1);
158 if (!alloced) {
159 fprintf(stderr, "%d: failed to allocate %d bytes for utsname\n", __LINE__, len);
160 goto out;
161 }
162
163 // now pass in the malloc'd array, and pass in length of string + 1: again
164 // because we need room for the trailing \0
165 ret = c->get_config_item(c, "lxc.uts.name", alloced, len+1);
166 if (ret < 0) {
167 fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, ret);
168 goto out;
169 }
170
171 if (strcmp(alloced, HNAME) != 0 || ret != len) {
172 fprintf(stderr, "lxc.utsname returned wrong value: %d %s not %d %s\n", ret, alloced, len, HNAME);
173 goto out;
174 }
175 printf("lxc.utsname returned %d %s\n", len, alloced);
176 free(alloced);
177
178 if (!c->set_config_item(c, "lxc.mount.entry", "hi there")) {
179 fprintf(stderr, "%d: failed to set mount.entry\n", __LINE__);
180 goto out;
181 }
182
183 ret = c->get_config_item(c, "lxc.mount.entry", v2, 255);
184 if (ret < 0) {
185 fprintf(stderr, "%d: get_config_item(lxc.mount.entry) returned %d\n", __LINE__, ret);
186 goto out;
187 }
188 printf("lxc.mount.entry returned %d %s\n", ret, v2);
189
190 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
191 if (ret != 0) {
192 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
193 goto out;
194 }
195
196 if (!c->set_config_item(c, "lxc.prlimit.nofile", "1234:unlimited")) {
197 fprintf(stderr, "%d: failed to set limit.nofile\n", __LINE__);
198 goto out;
199 }
200
201 ret = c->get_config_item(c, "lxc.prlimit.nofile", v2, 255);
202 if (ret < 0) {
203 fprintf(stderr, "%d: get_config_item(lxc.prlimit.nofile) returned %d\n", __LINE__, ret);
204 goto out;
205 }
206
207 if (strcmp(v2, "1234:unlimited")) {
208 fprintf(stderr, "%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited\n", __LINE__, ret, v2);
209 goto out;
210 }
211 printf("lxc.prlimit.nofile returned %d %s\n", ret, v2);
212
213 if (!c->set_config_item(c, "lxc.prlimit.stack", "unlimited")) {
214 fprintf(stderr, "%d: failed to set limit.stack\n", __LINE__);
215 goto out;
216 }
217
218 ret = c->get_config_item(c, "lxc.prlimit.stack", v2, 255);
219 if (ret < 0) {
220 fprintf(stderr, "%d: get_config_item(lxc.prlimit.stack) returned %d\n", __LINE__, ret);
221 goto out;
222 }
223
224 if (strcmp(v2, "unlimited")) {
225 fprintf(stderr, "%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited\n", __LINE__, ret, v2);
226 goto out;
227 }
228 printf("lxc.prlimit.stack returned %d %s\n", ret, v2);
229
230 #define LIMIT_STACK "lxc.prlimit.stack = unlimited\n"
231 #define ALL_LIMITS "lxc.prlimit.nofile = 1234:unlimited\n" LIMIT_STACK
232 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
233 if (ret != sizeof(ALL_LIMITS)-1) {
234 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
235 goto out;
236 }
237
238 if (strcmp(v3, ALL_LIMITS)) {
239 fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_LIMITS)-1, ALL_LIMITS);
240 goto out;
241 }
242 printf("lxc.prlimit returned %d %s\n", ret, v3);
243
244 if (!c->clear_config_item(c, "lxc.prlimit.nofile")) {
245 fprintf(stderr, "%d: failed clearing limit.nofile\n", __LINE__);
246 goto out;
247 }
248
249 ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
250 if (ret != sizeof(LIMIT_STACK)-1) {
251 fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
252 goto out;
253 }
254
255 if (strcmp(v3, LIMIT_STACK)) {
256 fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(LIMIT_STACK)-1, LIMIT_STACK);
257 goto out;
258 }
259 printf("lxc.prlimit returned %d %s\n", ret, v3);
260
261 #define SYSCTL_SOMAXCONN "lxc.sysctl.net.core.somaxconn = 256\n"
262 #define ALL_SYSCTLS "lxc.sysctl.net.ipv4.ip_forward = 1\n" SYSCTL_SOMAXCONN
263
264 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
265 if (ret != 0) {
266 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
267 goto out;
268 }
269
270 if (!c->set_config_item(c, "lxc.sysctl.net.ipv4.ip_forward", "1")) {
271 fprintf(stderr, "%d: failed to set lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
272 goto out;
273 }
274
275 ret = c->get_config_item(c, "lxc.sysctl.net.ipv4.ip_forward", v2, 255);
276 if (ret < 0) {
277 fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d\n", __LINE__, ret);
278 goto out;
279 }
280
281 if (strcmp(v2, "1")) {
282 fprintf(stderr, "%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1\n", __LINE__, ret, v2);
283 goto out;
284 }
285 printf("lxc.sysctl.net.ipv4.ip_forward returned %d %s\n", ret, v2);
286
287 if (!c->set_config_item(c, "lxc.sysctl.net.core.somaxconn", "256")) {
288 fprintf(stderr, "%d: failed to set lxc.sysctl.net.core.somaxconn\n", __LINE__);
289 goto out;
290 }
291
292 ret = c->get_config_item(c, "lxc.sysctl.net.core.somaxconn", v2, 255);
293 if (ret < 0) {
294 fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d\n", __LINE__, ret);
295 goto out;
296 }
297
298 if (strcmp(v2, "256")) {
299 fprintf(stderr, "%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256\n", __LINE__, ret, v2);
300 goto out;
301 }
302 printf("lxc.sysctl.net.core.somaxconn returned %d %s\n", ret, v2);
303
304 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
305 if (ret != sizeof(ALL_SYSCTLS)-1) {
306 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
307 goto out;
308 }
309
310 if (strcmp(v3, ALL_SYSCTLS)) {
311 fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_SYSCTLS) - 1, ALL_SYSCTLS);
312 goto out;
313 }
314 printf("lxc.sysctl returned %d %s\n", ret, v3);
315
316 if (!c->clear_config_item(c, "lxc.sysctl.net.ipv4.ip_forward")) {
317 fprintf(stderr, "%d: failed clearing lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
318 goto out;
319 }
320
321 ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
322 if (ret != sizeof(SYSCTL_SOMAXCONN) - 1) {
323 fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
324 goto out;
325 }
326
327 if (strcmp(v3, SYSCTL_SOMAXCONN)) {
328 fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(SYSCTL_SOMAXCONN) - 1, SYSCTL_SOMAXCONN);
329 goto out;
330 }
331 printf("lxc.sysctl returned %d %s\n", ret, v3);
332
333 #define PROC_OOM_SCORE_ADJ "lxc.proc.oom_score_adj = 10\n"
334 #define ALL_PROCS "lxc.proc.setgroups = allow\n" PROC_OOM_SCORE_ADJ
335
336 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
337 if (ret != 0) {
338 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
339 goto out;
340 }
341
342 if (!c->set_config_item(c, "lxc.proc.setgroups", "allow")) {
343 fprintf(stderr, "%d: failed to set lxc.proc.setgroups\n", __LINE__);
344 goto out;
345 }
346
347 ret = c->get_config_item(c, "lxc.proc.setgroups", v2, 255);
348 if (ret < 0) {
349 fprintf(stderr, "%d: get_config_item(lxc.proc.setgroups) returned %d\n", __LINE__, ret);
350 goto out;
351 }
352
353 if (strcmp(v2, "allow")) {
354 fprintf(stderr, "%d: lxc.proc.setgroups returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
355 goto out;
356 }
357 printf("lxc.proc.setgroups returned %d %s\n", ret, v2);
358
359 if (!c->set_config_item(c, "lxc.proc.oom_score_adj", "10")) {
360 fprintf(stderr, "%d: failed to set lxc.proc.oom_score_adj\n", __LINE__);
361 goto out;
362 }
363
364 ret = c->get_config_item(c, "lxc.proc.oom_score_adj", v2, 255);
365 if (ret < 0) {
366 fprintf(stderr, "%d: get_config_item(lxc.proc.oom_score_adj) returned %d\n", __LINE__, ret);
367 goto out;
368 }
369
370 if (strcmp(v2, "10")) {
371 fprintf(stderr, "%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
372 goto out;
373 }
374 printf("lxc.proc.oom_score_adj returned %d %s\n", ret, v2);
375
376 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
377 if (ret != sizeof(ALL_PROCS)-1) {
378 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
379 goto out;
380 }
381
382 if (strcmp(v3, ALL_PROCS)) {
383 fprintf(stderr, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_PROCS) - 1, ALL_PROCS);
384 goto out;
385 }
386 printf("lxc.proc returned %d %s\n", ret, v3);
387
388 if (!c->clear_config_item(c, "lxc.proc.setgroups")) {
389 fprintf(stderr, "%d: failed clearing lxc.proc.setgroups\n", __LINE__);
390 goto out;
391 }
392
393 ret = c->get_config_item(c, "lxc.proc", v3, 2047);
394 if (ret < 0) {
395 fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
396 goto out;
397 }
398
399 if (strcmp(v3, PROC_OOM_SCORE_ADJ)) {
400 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);
401 goto out;
402 }
403 printf("lxc.proc returned %d %s\n", ret, v3);
404
405 if (!c->set_config_item(c, "lxc.apparmor.profile", "unconfined")) {
406 fprintf(stderr, "%d: failed to set aa_profile\n", __LINE__);
407 goto out;
408 }
409
410 ret = c->get_config_item(c, "lxc.apparmor.profile", v2, 255);
411 if (ret < 0) {
412 fprintf(stderr, "%d: get_config_item(lxc.aa_profile) returned %d\n", __LINE__, ret);
413 goto out;
414 }
415 printf("lxc.aa_profile returned %d %s\n", ret, v2);
416
417 lxc_container_put(c);
418
419 // new test with real container
420 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
421 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
422 goto out;
423 }
424 c->destroy(c);
425 lxc_container_put(c);
426
427 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
428 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
429 goto out;
430 }
431
432 if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
433 fprintf(stderr, "%d: failed to create a trusty container\n", __LINE__);
434 goto out;
435 }
436 lxc_container_put(c);
437
438 /* XXX TODO load_config needs to clear out any old config first */
439 if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
440 fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
441 goto out;
442 }
443
444 ret = c->get_config_item(c, "lxc.cap.drop", NULL, 300);
445 if (ret < 5 || ret > 255) {
446 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) with NULL returned %d\n", __LINE__, ret);
447 goto out;
448 }
449
450 ret = c->get_config_item(c, "lxc.cap.drop", v1, 1);
451 if (ret < 5 || ret > 255) {
452 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d\n", __LINE__, ret);
453 goto out;
454 }
455
456 ret = c->get_config_item(c, "lxc.cap.drop", v2, 255);
457 if (ret < 0) {
458 fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
459 goto out;
460 }
461 printf("%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
462
463 ret = c->get_config_item(c, "lxc.net", v2, 255);
464 if (ret < 0) {
465 fprintf(stderr, "%d: get_config_item(lxc.net) returned %d\n", __LINE__, ret);
466 goto out;
467 }
468 printf("%d: get_config_item(lxc.net) returned %d %s\n", __LINE__, ret, v2);
469
470 if (!c->set_config_item(c, "lxc.net.0.type", "veth")) {
471 fprintf(stderr, "%d: failed to set lxc.net.0.type\n", __LINE__);
472 goto out;
473 }
474
475 if (!c->set_config_item(c, "lxc.net.0.link", "lxcbr0")) {
476 fprintf(stderr, "%d: failed to set network.link\n", __LINE__);
477 goto out;
478 }
479
480 if (!c->set_config_item(c, "lxc.net.0.flags", "up")) {
481 fprintf(stderr, "%d: failed to set network.flags\n", __LINE__);
482 goto out;
483 }
484
485 if (!c->set_config_item(c, "lxc.net.0.hwaddr", "00:16:3e:xx:xx:xx")) {
486 fprintf(stderr, "%d: failed to set network.hwaddr\n", __LINE__);
487 goto out;
488 }
489
490 if (!c->set_config_item(c, "lxc.net.0.ipv4.address", "10.2.3.4")) {
491 fprintf(stderr, "%d: failed to set ipv4\n", __LINE__);
492 goto out;
493 }
494
495 ret = c->get_config_item(c, "lxc.net.0.ipv4.address", v2, 255);
496 if (ret <= 0) {
497 fprintf(stderr, "%d: lxc.net.0.ipv4 returned %d\n", __LINE__, ret);
498 goto out;
499 }
500
501 if (!c->clear_config_item(c, "lxc.net.0.ipv4.address")) {
502 fprintf(stderr, "%d: failed clearing all ipv4 entries\n", __LINE__);
503 goto out;
504 }
505
506 ret = c->get_config_item(c, "lxc.net.0.ipv4.address", v2, 255);
507 if (ret != 0) {
508 fprintf(stderr, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__, ret);
509 goto out;
510 }
511
512 if (!c->set_config_item(c, "lxc.net.0.ipv4.gateway", "10.2.3.254")) {
513 fprintf(stderr, "%d: failed to set ipv4.gateway\n", __LINE__);
514 goto out;
515 }
516
517 ret = c->get_config_item(c, "lxc.net.0.ipv4.gateway", v2, 255);
518 if (ret <= 0) {
519 fprintf(stderr, "%d: lxc.net.0.ipv4.gateway returned %d\n", __LINE__, ret);
520 goto out;
521 }
522
523 if (!c->set_config_item(c, "lxc.net.0.ipv4.gateway", "")) {
524 fprintf(stderr, "%d: failed clearing ipv4.gateway\n", __LINE__);
525 goto out;
526 }
527
528 ret = c->get_config_item(c, "lxc.net.0.ipv4.gateway", v2, 255);
529 if (ret != 0) {
530 fprintf(stderr, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__, ret);
531 goto out;
532 }
533
534 ret = c->get_config_item(c, "lxc.net.0.link", v2, 255);
535 if (ret < 0) {
536 fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
537 goto out;
538 }
539 printf("%d: get_config_item (link) returned %d %s\n", __LINE__, ret, v2);
540
541 ret = c->get_config_item(c, "lxc.net.0.name", v2, 255);
542 if (ret < 0) {
543 fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
544 goto out;
545 }
546 printf("%d: get_config_item (name) returned %d %s\n", __LINE__, ret, v2);
547
548 if (!c->clear_config_item(c, "lxc.net")) {
549 fprintf(stderr, "%d: clear_config_item failed\n", __LINE__);
550 goto out;
551 }
552
553 ret = c->get_config_item(c, "lxc.net", v2, 255);
554 if (ret != 0) {
555 fprintf(stderr, "%d: network was not actually cleared (get_network returned %d)\n", __LINE__, ret);
556 goto out;
557 }
558
559 ret = c->get_config_item(c, "lxc.cgroup", v3, 2047);
560 if (ret < 0) {
561 fprintf(stderr, "%d: get_config_item(cgroup.devices) returned %d\n", __LINE__, ret);
562 goto out;
563 }
564 printf("%d: get_config_item (cgroup.devices) returned %d %s\n", __LINE__, ret, v3);
565
566 ret = c->get_config_item(c, "lxc.cgroup.devices.allow", v3, 2047);
567 if (ret < 0) {
568 fprintf(stderr, "%d: get_config_item(cgroup.devices.devices.allow) returned %d\n", __LINE__, ret);
569 goto out;
570 }
571 printf("%d: get_config_item (cgroup.devices.devices.allow) returned %d %s\n", __LINE__, ret, v3);
572
573 if (!c->clear_config_item(c, "lxc.cgroup")) {
574 fprintf(stderr, "%d: failed clearing lxc.cgroup\n", __LINE__);
575 goto out;
576 }
577
578 if (!c->clear_config_item(c, "lxc.cap.drop")) {
579 fprintf(stderr, "%d: failed clearing lxc.cap.drop\n", __LINE__);
580 goto out;
581 }
582
583 if (!c->clear_config_item(c, "lxc.mount.entry")) {
584 fprintf(stderr, "%d: failed clearing lxc.mount.entry\n", __LINE__);
585 goto out;
586 }
587
588 if (!c->clear_config_item(c, "lxc.hook")) {
589 fprintf(stderr, "%d: failed clearing lxc.hook\n", __LINE__);
590 goto out;
591 }
592
593 if (!lxc_config_item_is_supported("lxc.arch")) {
594 fprintf(stderr, "%d: failed to report \"lxc.arch\" as supported configuration item\n", __LINE__);
595 goto out;
596 }
597
598 if (lxc_config_item_is_supported("lxc.nonsense")) {
599 fprintf(stderr, "%d: failed to detect \"lxc.nonsense\" as unsupported configuration item\n", __LINE__);
600 goto out;
601 }
602
603 if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
604 fprintf(stderr, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__);
605 goto out;
606 }
607
608
609 printf("All get_item tests passed\n");
610 fret = EXIT_SUCCESS;
611
612 out:
613 if (c) {
614 c->destroy(c);
615 lxc_container_put(c);
616 }
617
618 exit(fret);
619 }