lxc_test_device_add_remove_SOURCES += ../lxc/seccomp.c ../lxc/lxcseccomp.h
endif
lxc_test_getkeys_SOURCES = getkeys.c
-lxc_test_get_item_SOURCES = get_item.c
+lxc_test_get_item_SOURCES = get_item.c \
+ ../lxc/af_unix.c ../lxc/af_unix.h \
+ ../lxc/caps.c ../lxc/caps.h \
+ ../lxc/cgroups/cgfsng.c \
+ ../lxc/cgroups/cgroup.c ../lxc/cgroups/cgroup.h \
+ ../lxc/cgroups/cgroup2_devices.c ../lxc/cgroups/cgroup2_devices.h \
+ ../lxc/cgroups/cgroup_utils.c ../lxc/cgroups/cgroup_utils.h \
+ ../lxc/commands.c ../lxc/commands.h \
+ ../lxc/commands_utils.c ../lxc/commands_utils.h \
+ ../lxc/conf.c ../lxc/conf.h \
+ ../lxc/confile.c ../lxc/confile.h \
+ ../lxc/confile_utils.c ../lxc/confile_utils.h \
+ ../lxc/error.c ../lxc/error.h \
+ ../lxc/file_utils.c ../lxc/file_utils.h \
+ ../include/netns_ifaddrs.c ../include/netns_ifaddrs.h \
+ ../lxc/initutils.c ../lxc/initutils.h \
+ ../lxc/log.c ../lxc/log.h \
+ ../lxc/lxclock.c ../lxc/lxclock.h \
+ ../lxc/mainloop.c ../lxc/mainloop.h \
+ ../lxc/monitor.c ../lxc/monitor.h \
+ ../lxc/namespace.c ../lxc/namespace.h \
+ ../lxc/network.c ../lxc/network.h \
+ ../lxc/nl.c ../lxc/nl.h \
+ ../lxc/parse.c ../lxc/parse.h \
+ ../lxc/process_utils.c ../lxc/process_utils.h \
+ ../lxc/ringbuf.c ../lxc/ringbuf.h \
+ ../lxc/start.c ../lxc/start.h \
+ ../lxc/state.c ../lxc/state.h \
+ ../lxc/storage/btrfs.c ../lxc/storage/btrfs.h \
+ ../lxc/storage/dir.c ../lxc/storage/dir.h \
+ ../lxc/storage/loop.c ../lxc/storage/loop.h \
+ ../lxc/storage/lvm.c ../lxc/storage/lvm.h \
+ ../lxc/storage/nbd.c ../lxc/storage/nbd.h \
+ ../lxc/storage/overlay.c ../lxc/storage/overlay.h \
+ ../lxc/storage/rbd.c ../lxc/storage/rbd.h \
+ ../lxc/storage/rsync.c ../lxc/storage/rsync.h \
+ ../lxc/storage/storage.c ../lxc/storage/storage.h \
+ ../lxc/storage/storage_utils.c ../lxc/storage/storage_utils.h \
+ ../lxc/storage/zfs.c ../lxc/storage/zfs.h \
+ ../lxc/sync.c ../lxc/sync.h \
+ ../lxc/string_utils.c ../lxc/string_utils.h \
+ ../lxc/terminal.c ../lxc/terminal.h \
+ ../lxc/utils.c ../lxc/utils.h \
+ ../lxc/uuid.c ../lxc/uuid.h \
+ $(LSM_SOURCES)
+if ENABLE_SECCOMP
+lxc_test_get_item_SOURCES += ../lxc/seccomp.c ../lxc/lxcseccomp.h
+endif
lxc_test_list_SOURCES = list.c
lxc_test_locktests_SOURCES = locktests.c \
../lxc/af_unix.c ../lxc/af_unix.h \
#include "lxc/state.h"
#include "lxctest.h"
+#include "utils.h"
+
+#ifndef HAVE_STRLCPY
+#include "include/strlcpy.h"
+#endif
#define MYNAME "lxctest1"
int main(int argc, char *argv[])
{
- int ret;
- struct lxc_container *c;
+ int fd_log, ret;
+ struct lxc_container *c = NULL;
int fret = EXIT_FAILURE;
char v1[2], v2[256], v3[2048];
+ struct lxc_log log = {};
+ char template[sizeof(P_tmpdir"/attach_XXXXXX")];
+
+ (void)strlcpy(template, P_tmpdir"/attach_XXXXXX", sizeof(template));
+
+ fd_log = lxc_make_tmpfile(template, false);
+ if (fd_log < 0) {
+ lxc_error("Failed to create temporary log file for container %s\n", MYNAME);
+ exit(EXIT_FAILURE);
+ }
+ log.name = MYNAME;
+ log.file = template;
+ log.level = "TRACE";
+ log.prefix = "get_item";
+ log.quiet = false;
+ log.lxcpath = NULL;
+ if (lxc_log_init(&log))
+ goto out;
if ((c = lxc_container_new("testxyz", NULL)) == NULL) {
fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
}
printf("lxc.init_gid returned %d %s\n", ret, v2);
- if (!c->set_config_item(c, "lxc.init.groups", "")) {
- fprintf(stderr, "%d: failed to set init_groups\n", __LINE__);
+ if (c->set_config_item(c, "lxc.init.groups", "10,20,foo,40")) {
+ fprintf(stderr, "%d: managed to set lxc.init.groups to '10,20,foo,40'\n", __LINE__);
goto out;
}
- if (!c->set_config_item(c, "lxc.init.groups", "10,20,foo,40")) {
- printf("failed to set init_groups to '10,20,foo,40' as expected\n");
- } else {
+ if (!c->set_config_item(c, "lxc.init.groups", "10,20,30,40")) {
+ fprintf(stderr, "%d: managed to set lxc.init.groups to '10,20,30,40'\n", __LINE__);
goto out;
}
- if (!c->set_config_item(c, "lxc.init.groups", "10,20,30,40")) {
- fprintf(stderr, "%d: failed to set init_groups\n", __LINE__);
+ ret = c->get_config_item(c, "lxc.init.groups", v2, 255);
+ if (ret < 0) {
+ fprintf(stderr, "%d: failed to get lxc.init.groups\n", __LINE__);
+ goto out;
+ }
+ ret = strcmp("10,20,30,40", v2);
+ printf("%d: lxc.init.groups returned %d %s\n", __LINE__, ret, v2);
+ if (ret != 0) {
+ goto out;
+ }
+
+ if (!c->set_config_item(c, "lxc.init.groups", "50,60,70,80")) {
+ fprintf(stderr, "%d: failed to set lxc.init.groups to '50,60,70,80'\n", __LINE__);
goto out;
}
ret = c->get_config_item(c, "lxc.init.groups", v2, 255);
if (ret < 0) {
- fprintf(stderr, "%d: get_config_item(lxc.init_gid) returned %d\n",
- __LINE__, ret);
+ fprintf(stderr, "%d: failed to get lxc.init.groups\n", __LINE__);
goto out;
}
- ret = strcmp("10,20,30,40", v2);
- printf("lxc.init_groups returned %d %s\n", ret, v2);
+ ret = strcmp("10,20,30,40,50,60,70,80", v2);
+ printf("%d: lxc.init.groups returned %d %s\n", __LINE__, ret, v2);
+ if (ret != 0) {
+ goto out;
+ }
+
+ if (!c->set_config_item(c, "lxc.init.groups", "")) {
+ fprintf(stderr, "%d: failed to set lxc.init.groups to ''\n", __LINE__);
+ goto out;
+ }
+
+ ret = c->get_config_item(c, "lxc.init.groups", v2, 255);
+ if (ret < 0) {
+ fprintf(stderr, "%d: failed to get lxc.init.groups\n", __LINE__);
+ goto out;
+ }
+ ret = strcmp("", v2);
+ printf("%d: lxc.init.groups returned %d %s\n", __LINE__, ret, v2);
if (ret != 0) {
goto out;
}
c->destroy(c);
lxc_container_put(c);
}
+ if (fret != EXIT_SUCCESS) {
+ char buf[4096];
+ ssize_t buflen;
+ while ((buflen = read(fd_log, buf, 1024)) > 0) {
+ buflen = write(STDERR_FILENO, buf, buflen);
+ if (buflen <= 0)
+ break;
+ }
+ close(fd_log);
+ }
+ (void)unlink(template);
exit(fret);
}