From: Christian Brauner Date: Tue, 2 Feb 2021 22:30:00 +0000 (+0100) Subject: test: add logging to device_add_remove X-Git-Tag: lxc-5.0.0~305^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4f24357189fd74965d516c8373f1ca75a405668;p=thirdparty%2Flxc.git test: add logging to device_add_remove Signed-off-by: Christian Brauner --- diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 0e90ce50f..3260fdba5 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -275,7 +275,54 @@ lxc_test_createtest_SOURCES = createtest.c lxc_test_criu_check_feature_SOURCES = criu_check_feature.c lxctest.h lxc_test_cve_2019_5736_SOURCES = cve-2019-5736.c lxctest.h lxc_test_destroytest_SOURCES = destroytest.c -lxc_test_device_add_remove_SOURCES = device_add_remove.c +lxc_test_device_add_remove_SOURCES = device_add_remove.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_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_list_SOURCES = list.c diff --git a/src/tests/device_add_remove.c b/src/tests/device_add_remove.c index 50ccb2d51..4cc400776 100644 --- a/src/tests/device_add_remove.c +++ b/src/tests/device_add_remove.c @@ -20,14 +20,41 @@ #include #include +#include "lxctest.h" +#include "memory_utils.h" +#include "utils.h" + +#ifndef HAVE_STRLCPY +#include "include/strlcpy.h" +#endif + #define NAME "device_add_remove_test" #define DEVICE "/dev/loop-control" int main(int argc, char *argv[]) { + __do_close int fd_log = -EBADF; int ret = 1; + struct lxc_log log = {}; + char template[sizeof(P_tmpdir"/attach_XXXXXX")]; struct lxc_container *c; + (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", NAME); + exit(EXIT_FAILURE); + } + log.name = NAME; + log.file = template; + log.level = "TRACE"; + log.prefix = "device_add_remove"; + log.quiet = false; + log.lxcpath = NULL; + if (lxc_log_init(&log)) + goto out; + c = lxc_container_new(NAME, NULL); if (!c) { fprintf(stderr, "Unable to instantiate container (%s)...\n", NAME); @@ -69,6 +96,17 @@ int main(int argc, char *argv[]) ret = 0; out: + if (ret != 0) { + char buf[4096]; + ssize_t buflen; + while ((buflen = read(fd_log, buf, 1024)) > 0) { + buflen = write(STDERR_FILENO, buf, buflen); + if (buflen <= 0) + break; + } + } + (void)unlink(template); + lxc_container_put(c); return ret; }