lxc_error("%s\n", "Failed to set lxc.log.syslog.\n");
goto out;
}
+
ret = c->get_config_item(c, "lxc.log.syslog", v2, 255);
if (ret < 0) {
lxc_error("Failed to retrieve lxc.log.syslog: %d.\n", ret);
goto out;
}
+
if (strcmp(v2, "local0") != 0) {
lxc_error("Expected: local0 == %s.\n", v2);
goto out;
fprintf(stderr, "%d: failed to set hook.pre-start\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.hook.pre-start", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.hook.pre-start) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set tty\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.tty.max", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.tty) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set arch\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.arch", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.arch) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set init_uid\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.init.uid", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.init_uid) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set init_gid\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.init.gid", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.init_gid) returned %d\n", __LINE__, ret);
#define HNAME "hostname1"
// demonstrate proper usage:
char *alloced;
+ int len;
+
if (!c->set_config_item(c, "lxc.uts.name", HNAME)) {
fprintf(stderr, "%d: failed to set utsname\n", __LINE__);
goto out;
}
- int len;
len = c->get_config_item(c, "lxc.uts.name", NULL, 0); // query the size of the string
if (len < 0) {
fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, len);
fprintf(stderr, "%d: failed to allocate %d bytes for utsname\n", __LINE__, len);
goto out;
}
+
// now pass in the malloc'd array, and pass in length of string + 1: again
// because we need room for the trailing \0
ret = c->get_config_item(c, "lxc.uts.name", alloced, len+1);
fprintf(stderr, "%d: get_config_item(lxc.utsname) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(alloced, HNAME) != 0 || ret != len) {
fprintf(stderr, "lxc.utsname returned wrong value: %d %s not %d %s\n", ret, alloced, len, HNAME);
goto out;
fprintf(stderr, "%d: failed to set mount.entry\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.mount.entry", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.mount.entry) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set limit.nofile\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.prlimit.nofile", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.prlimit.nofile) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "1234:unlimited")) {
fprintf(stderr, "%d: lxc.prlimit.nofile returned wrong value: %d %s not 14 1234:unlimited\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: failed to set limit.stack\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.prlimit.stack", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.prlimit.stack) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "unlimited")) {
fprintf(stderr, "%d: lxc.prlimit.stack returned wrong value: %d %s not 9 unlimited\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, ALL_LIMITS)) {
fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_LIMITS)-1, ALL_LIMITS);
goto out;
fprintf(stderr, "%d: failed clearing limit.nofile\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.prlimit", v3, 2047);
if (ret != sizeof(LIMIT_STACK)-1) {
fprintf(stderr, "%d: get_config_item(limit) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, LIMIT_STACK)) {
fprintf(stderr, "%d: lxc.prlimit returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(LIMIT_STACK)-1, LIMIT_STACK);
goto out;
fprintf(stderr, "%d: failed to set lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.sysctl.net.ipv4.ip_forward", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.ipv4.ip_forward) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "1")) {
fprintf(stderr, "%d: lxc.sysctl.net.ipv4.ip_forward returned wrong value: %d %s not 1\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: failed to set lxc.sysctl.net.core.somaxconn\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.sysctl.net.core.somaxconn", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.sysctl.net.core.somaxconn) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "256")) {
fprintf(stderr, "%d: lxc.sysctl.net.core.somaxconn returned wrong value: %d %s not 256\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, ALL_SYSCTLS)) {
fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_SYSCTLS) - 1, ALL_SYSCTLS);
goto out;
fprintf(stderr, "%d: failed clearing lxc.sysctl.net.ipv4.ip_forward\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.sysctl", v3, 2047);
if (ret != sizeof(SYSCTL_SOMAXCONN) - 1) {
fprintf(stderr, "%d: get_config_item(sysctl) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, SYSCTL_SOMAXCONN)) {
fprintf(stderr, "%d: lxc.sysctl returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(SYSCTL_SOMAXCONN) - 1, SYSCTL_SOMAXCONN);
goto out;
fprintf(stderr, "%d: get_config_item(lxc.proc.setgroups) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "allow")) {
fprintf(stderr, "%d: lxc.proc.setgroups returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: get_config_item(lxc.proc.oom_score_adj) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v2, "10")) {
fprintf(stderr, "%d: lxc.proc.oom_score_adj returned wrong value: %d %s not 10\n", __LINE__, ret, v2);
goto out;
fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, ALL_PROCS)) {
fprintf(stderr, "%d: lxc.proc returned wrong value: %d %s not %d %s\n", __LINE__, ret, v3, (int)sizeof(ALL_PROCS) - 1, ALL_PROCS);
goto out;
fprintf(stderr, "%d: failed clearing lxc.proc.setgroups\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.proc", v3, 2047);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(proc) returned %d\n", __LINE__, ret);
goto out;
}
+
if (strcmp(v3, PROC_OOM_SCORE_ADJ)) {
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);
goto out;
fprintf(stderr, "%d: failed to set aa_profile\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.apparmor.profile", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.aa_profile) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
goto out;
}
+
if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
fprintf(stderr, "%d: failed to create a trusty container\n", __LINE__);
goto out;
fprintf(stderr, "%d: get_config_item(lxc.cap.drop) with NULL returned %d\n", __LINE__, ret);
goto out;
}
+
ret = c->get_config_item(c, "lxc.cap.drop", v1, 1);
if (ret < 5 || ret > 255) {
fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d\n", __LINE__, ret);
goto out;
}
+
ret = c->get_config_item(c, "lxc.cap.drop", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
goto out;
}
printf("%d: get_config_item(lxc.cap.drop) returned %d %s\n", __LINE__, ret, v2);
+
ret = c->get_config_item(c, "lxc.net", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item(lxc.net) returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: failed to set lxc.net.0.type\n", __LINE__);
goto out;
}
+
if (!c->set_config_item(c, "lxc.net.0.link", "lxcbr0")) {
fprintf(stderr, "%d: failed to set network.link\n", __LINE__);
goto out;
}
+
if (!c->set_config_item(c, "lxc.net.0.flags", "up")) {
fprintf(stderr, "%d: failed to set network.flags\n", __LINE__);
goto out;
}
+
if (!c->set_config_item(c, "lxc.net.0.hwaddr", "00:16:3e:xx:xx:xx")) {
fprintf(stderr, "%d: failed to set network.hwaddr\n", __LINE__);
goto out;
}
+
if (!c->set_config_item(c, "lxc.net.0.ipv4.address", "10.2.3.4")) {
fprintf(stderr, "%d: failed to set ipv4\n", __LINE__);
goto out;
fprintf(stderr, "%d: lxc.net.0.ipv4 returned %d\n", __LINE__, ret);
goto out;
}
+
if (!c->clear_config_item(c, "lxc.net.0.ipv4.address")) {
fprintf(stderr, "%d: failed clearing all ipv4 entries\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.net.0.ipv4.address", v2, 255);
if (ret != 0) {
fprintf(stderr, "%d: after clearing ipv4 entries get_item(lxc.network.0.ipv4 returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: lxc.net.0.ipv4.gateway returned %d\n", __LINE__, ret);
goto out;
}
+
if (!c->set_config_item(c, "lxc.net.0.ipv4.gateway", "")) {
fprintf(stderr, "%d: failed clearing ipv4.gateway\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.net.0.ipv4.gateway", v2, 255);
if (ret != 0) {
fprintf(stderr, "%d: after clearing ipv4.gateway get_item(lxc.network.0.ipv4.gateway returned %d\n", __LINE__, ret);
goto out;
}
printf("%d: get_config_item (link) returned %d %s\n", __LINE__, ret, v2);
+
ret = c->get_config_item(c, "lxc.net.0.name", v2, 255);
if (ret < 0) {
fprintf(stderr, "%d: get_config_item returned %d\n", __LINE__, ret);
fprintf(stderr, "%d: clear_config_item failed\n", __LINE__);
goto out;
}
+
ret = c->get_config_item(c, "lxc.net", v2, 255);
if (ret != 0) {
fprintf(stderr, "%d: network was not actually cleared (get_network returned %d)\n", __LINE__, ret);
fprintf(stderr, "%d: failed clearing lxc.cgroup\n", __LINE__);
goto out;
}
+
if (!c->clear_config_item(c, "lxc.cap.drop")) {
fprintf(stderr, "%d: failed clearing lxc.cap.drop\n", __LINE__);
goto out;
}
+
if (!c->clear_config_item(c, "lxc.mount.entry")) {
fprintf(stderr, "%d: failed clearing lxc.mount.entry\n", __LINE__);
goto out;
}
+
if (!c->clear_config_item(c, "lxc.hook")) {
fprintf(stderr, "%d: failed clearing lxc.hook\n", __LINE__);
goto out;
printf("All get_item tests passed\n");
fret = EXIT_SUCCESS;
+
out:
if (c) {
c->destroy(c);