From f26b57d12a2ea08a9b2622dfb2a5cc76988318b1 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 26 Feb 2016 09:00:33 -0500 Subject: Move test-loopback to normal tests In the normal case lo should be already configured and this should be a noop, even when run under root. --- Makefile.am | 2 +- src/test/test-loopback.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0f17bad8b1..5f5d9f0105 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1387,7 +1387,6 @@ EXTRA_DIST += \ manual_tests += \ test-ns \ - test-loopback \ test-hostname \ test-daemon \ test-cgroup \ @@ -1411,6 +1410,7 @@ manual_tests += \ endif tests += \ + test-loopback \ test-engine \ test-cgroup-mask \ test-job-type \ diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c index 2748395ade..7b67337331 100644 --- a/src/test/test-loopback.c +++ b/src/test/test-loopback.c @@ -31,7 +31,7 @@ int main(int argc, char* argv[]) { r = loopback_setup(); if (r < 0) - fprintf(stderr, "loopback: %s\n", strerror(-r)); + log_error("loopback: %m"); - return 0; + return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- cgit v1.2.3-54-g00ecf From a4bfedec701fb4433923c338b623d1d3e21ed620 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 26 Feb 2016 09:06:10 -0500 Subject: Rename test-boot-timestamp to test-boot-timestamps and enable by default The source file name and the binary name were mismatched. Rename binary to match. Make the test exit with TEST_SKIP if the data is missing or we have no permissions. Otherwise, the data will be printed, which should be safe to enable by default. --- .gitignore | 2 +- Makefile.am | 8 +++---- src/test/test-boot-timestamps.c | 51 +++++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 18db046cac..162160ef21 100644 --- a/.gitignore +++ b/.gitignore @@ -133,7 +133,7 @@ /test-audit-type /test-barrier /test-bitmap -/test-boot-timestamp +/test-boot-timestamps /test-btrfs /test-bus-benchmark /test-bus-chat diff --git a/Makefile.am b/Makefile.am index 5f5d9f0105..0ee52324a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1651,13 +1651,13 @@ test_dns_domain_LDADD = \ if ENABLE_EFI -manual_tests += \ - test-boot-timestamp +tests += \ + test-boot-timestamps -test_boot_timestamp_SOURCES = \ +test_boot_timestamps_SOURCES = \ src/test/test-boot-timestamps.c -test_boot_timestamp_LDADD = \ +test_boot_timestamps_LDADD = \ libshared.la endif diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c index d2add5880c..9fb6bbef93 100644 --- a/src/test/test-boot-timestamps.c +++ b/src/test/test-boot-timestamps.c @@ -34,17 +34,18 @@ static int test_acpi_fpdt(void) { r = acpi_get_boot_usec(&loader_start, &loader_exit); if (r < 0) { - if (r != -ENOENT) - log_error_errno(r, "Failed to read ACPI FPDT: %m"); - return r; + bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); + + log_full_errno(ok ? LOG_DEBUG : LOG_ERR, + r, "Failed to read ACPI FPDT: %m"); + return ok ? 0 : r; } log_info("ACPI FPDT: loader start=%s exit=%s duration=%s", format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC), format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC), format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC)); - - return 0; + return 1; } static int test_efi_loader(void) { @@ -57,33 +58,34 @@ static int test_efi_loader(void) { r = efi_loader_get_boot_usec(&loader_start, &loader_exit); if (r < 0) { - if (r != -ENOENT) - log_error_errno(r, "Failed to read EFI loader data: %m"); - return r; + bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); + + log_full_errno(ok ? LOG_DEBUG : LOG_ERR, + r, "Failed to read EFI loader data: %m"); + return ok ? 0 : r; } log_info("EFI Loader: start=%s exit=%s duration=%s", format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC), format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC), format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC)); - - return 0; + return 1; } -int main(int argc, char* argv[]) { +static int test_boot_timestamps(void) { char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)]; int r; dual_timestamp fw, l, k; - test_acpi_fpdt(); - test_efi_loader(); - dual_timestamp_from_monotonic(&k, 0); r = boot_timestamps(NULL, &fw, &l); if (r < 0) { - log_error_errno(r, "Failed to read variables: %m"); - return 1; + bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); + + log_full_errno(ok ? LOG_DEBUG : LOG_ERR, + r, "Failed to read variables: %m"); + return ok ? 0 : r; } log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0)); @@ -91,6 +93,21 @@ int main(int argc, char* argv[]) { log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime)); log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime)); log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime)); + return 1; +} + +int main(int argc, char* argv[]) { + int p, q, r; + + log_set_max_level(LOG_DEBUG); + log_parse_environment(); + + p = test_acpi_fpdt(); + assert(p >= 0); + q = test_efi_loader(); + assert(q >= 0); + r = test_boot_timestamps(); + assert(r >= 0); - return 0; + return (p > 0 || q > 0 || r >> 0) ? EXIT_SUCCESS : EXIT_TEST_SKIP; } -- cgit v1.2.3-54-g00ecf From 67a47c609683559dddba0c8e3875723010a088e1 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 27 Feb 2016 11:30:22 -0500 Subject: shared/acpi-fpdt: use ENODATA for missing data and skip test This data is simply missing on non-UEFI systems, and it is useful to distinguish that from corrupted data. --- src/shared/acpi-fpdt.c | 6 +++++- src/test/test-boot-timestamps.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/shared/acpi-fpdt.c b/src/shared/acpi-fpdt.c index 3cb9e781fd..6779691c28 100644 --- a/src/shared/acpi-fpdt.c +++ b/src/shared/acpi-fpdt.c @@ -119,7 +119,7 @@ int acpi_get_boot_usec(usec_t *loader_start, usec_t *loader_exit) { } if (ptr == 0) - return -EINVAL; + return -ENODATA; /* read Firmware Basic Boot Performance Data Record */ fd = open("/dev/mem", O_CLOEXEC|O_RDONLY); @@ -146,6 +146,10 @@ int acpi_get_boot_usec(usec_t *loader_start, usec_t *loader_exit) { if (brec.type != ACPI_FPDT_BOOT_REC) return -EINVAL; + if (brec.exit_services_exit == 0) + /* Non-UEFI compatible boot. */ + return -ENODATA; + if (brec.startup_start == 0 || brec.exit_services_exit < brec.startup_start) return -EINVAL; if (brec.exit_services_exit > NSEC_PER_HOUR) diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c index 9fb6bbef93..8e68d6510d 100644 --- a/src/test/test-boot-timestamps.c +++ b/src/test/test-boot-timestamps.c @@ -34,7 +34,7 @@ static int test_acpi_fpdt(void) { r = acpi_get_boot_usec(&loader_start, &loader_exit); if (r < 0) { - bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); + bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES) || r == -ENODATA; log_full_errno(ok ? LOG_DEBUG : LOG_ERR, r, "Failed to read ACPI FPDT: %m"); -- cgit v1.2.3-54-g00ecf From 134953c99c7441c4fa2d8000face10608f8832ec Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 26 Feb 2016 09:10:48 -0500 Subject: Enable test-daemon, test-log, test-watchdog by default Those should be safe to run, resulting in some messages in logs. --- Makefile.am | 6 +++--- src/test/test-daemon.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0ee52324a3..c6f6bc5d37 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1388,11 +1388,8 @@ EXTRA_DIST += \ manual_tests += \ test-ns \ test-hostname \ - test-daemon \ test-cgroup \ test-install \ - test-watchdog \ - test-log \ test-ipcrm \ test-btrfs \ test-acd \ @@ -1410,8 +1407,11 @@ manual_tests += \ endif tests += \ + test-daemon \ + test-log \ test-loopback \ test-engine \ + test-watchdog \ test-cgroup-mask \ test-job-type \ test-env-replace \ diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c index 4ce00f4b1f..a7cb426282 100644 --- a/src/test/test-daemon.c +++ b/src/test/test-daemon.c @@ -38,27 +38,27 @@ int main(int argc, char*argv[]) { sd_notify(0, "STATUS=Starting up"); - sleep(5); + sleep(1); sd_notify(0, "STATUS=Running\n" "READY=1"); - sleep(5); + sleep(1); sd_notify(0, "STATUS=Reloading\n" "RELOADING=1"); - sleep(5); + sleep(1); sd_notify(0, "STATUS=Running\n" "READY=1"); - sleep(5); + sleep(1); sd_notify(0, "STATUS=Quitting\n" "STOPPING=1"); - sleep(5); + sleep(1); return EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf From c1ab81916286747a1b466716188f05ae373dff6e Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 26 Feb 2016 18:39:20 -0500 Subject: Enable test-ipcrm, test-hostname in unsafe tests --- Makefile.am | 12 +++++++++--- configure.ac | 6 ++++-- src/test/test-ipcrm.c | 11 ++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index c6f6bc5d37..e2d5328c1b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -131,8 +131,12 @@ TEST_EXTENSIONS = .py PY_LOG_COMPILER = $(PYTHON) DISABLE_HARD_ERRORS = yes if ENABLE_TESTS -noinst_PROGRAMS = $(manual_tests) $(tests) +noinst_PROGRAMS = $(manual_tests) $(tests) $(unsafe_tests) TESTS = $(tests) +if ENABLE_UNSAFE_TESTS +TESTS += \ + $(unsafe_tests) +endif else noinst_PROGRAMS = TESTS = @@ -1387,15 +1391,17 @@ EXTRA_DIST += \ manual_tests += \ test-ns \ - test-hostname \ test-cgroup \ test-install \ - test-ipcrm \ test-btrfs \ test-acd \ test-ipv4ll-manual \ test-ask-password-api +unsafe_tests = \ + test-hostname \ + test-ipcrm + if HAVE_LIBIPTC manual_tests += \ test-firewall-util diff --git a/configure.ac b/configure.ac index e55d1a02a6..79340bcca9 100644 --- a/configure.ac +++ b/configure.ac @@ -1487,9 +1487,10 @@ AS_IF([test x"$cross_compiling" = "xyes"], [], [ ]) AC_ARG_ENABLE(tests, - [AC_HELP_STRING([--disable-tests], [disable tests])], + [AC_HELP_STRING([--disable-tests], [disable tests, or enable extra tests with =unsafe])], enable_tests=$enableval, enable_tests=yes) -AM_CONDITIONAL(ENABLE_TESTS, [test x$enable_tests = xyes]) +AM_CONDITIONAL(ENABLE_TESTS, [test x$enable_tests = xyes -o x$enable_tests = xunsafe]) +AM_CONDITIONAL(ENABLE_UNSAFE_TESTS, [test x$enable_tests = xunsafe]) AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug@<:@=LIST@:>@], [enable extra debugging (hashmap,mmap-cache)])], @@ -1611,6 +1612,7 @@ AC_MSG_RESULT([ ldconfig support: ${enable_ldconfig} hibernate support: ${enable_hibernate} extra debugging: ${enable_debug} + tests: ${enable_tests} prefix: ${prefix} rootprefix: ${with_rootprefix} diff --git a/src/test/test-ipcrm.c b/src/test/test-ipcrm.c index 2464d32458..47b1c4443d 100644 --- a/src/test/test-ipcrm.c +++ b/src/test/test-ipcrm.c @@ -23,9 +23,14 @@ int main(int argc, char *argv[]) { uid_t uid; - - assert_se(argc == 2); - assert_se(parse_uid(argv[1], &uid) >= 0); + int r; + const char* name = argv[1] ?: "nfsnobody"; + + r = get_user_creds(&name, &uid, NULL, NULL, NULL); + if (r < 0) { + log_error("Failed to resolve \"nobody\": %m"); + return EXIT_FAILURE; + } return clean_ipc(uid) < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf From 8b663bdf9b4ec7ce62106df01b09bf9df59ebd91 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 27 Feb 2016 10:35:46 -0500 Subject: build-sys: ignore Python 2 bytecode files We ignored __pycache__ which works for Python 3, but the rule for Python 2 got lost somehow. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 162160ef21..ddb630b164 100644 --- a/.gitignore +++ b/.gitignore @@ -280,6 +280,7 @@ /v4l_id Makefile.in __pycache__/ +*.py[co] aclocal.m4 config.h config.h.in -- cgit v1.2.3-54-g00ecf From cc4c1d22907fe0a69c23edb312fde2e2ac531112 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 1 Mar 2016 21:40:56 -0500 Subject: test-libudev: modernization --- src/test/test-libudev.c | 258 +++++++++++++++++++----------------------------- 1 file changed, 101 insertions(+), 157 deletions(-) diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index a7eb60e8cf..5ac513b013 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -24,170 +24,140 @@ #include "libudev.h" +#include "fd-util.h" +#include "log.h" #include "stdio-util.h" #include "string-util.h" #include "udev-util.h" #include "util.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) - static void print_device(struct udev_device *device) { const char *str; dev_t devnum; int count; struct udev_list_entry *list_entry; - printf("*** device: %p ***\n", device); + log_info("*** device: %p ***", device); str = udev_device_get_action(device); if (str != NULL) - printf("action: '%s'\n", str); + log_info("action: '%s'", str); str = udev_device_get_syspath(device); - printf("syspath: '%s'\n", str); + log_info("syspath: '%s'", str); str = udev_device_get_sysname(device); - printf("sysname: '%s'\n", str); + log_info("sysname: '%s'", str); str = udev_device_get_sysnum(device); if (str != NULL) - printf("sysnum: '%s'\n", str); + log_info("sysnum: '%s'", str); str = udev_device_get_devpath(device); - printf("devpath: '%s'\n", str); + log_info("devpath: '%s'", str); str = udev_device_get_subsystem(device); if (str != NULL) - printf("subsystem: '%s'\n", str); + log_info("subsystem: '%s'", str); str = udev_device_get_devtype(device); if (str != NULL) - printf("devtype: '%s'\n", str); + log_info("devtype: '%s'", str); str = udev_device_get_driver(device); if (str != NULL) - printf("driver: '%s'\n", str); + log_info("driver: '%s'", str); str = udev_device_get_devnode(device); if (str != NULL) - printf("devname: '%s'\n", str); + log_info("devname: '%s'", str); devnum = udev_device_get_devnum(device); if (major(devnum) > 0) - printf("devnum: %u:%u\n", major(devnum), minor(devnum)); + log_info("devnum: %u:%u", major(devnum), minor(devnum)); count = 0; udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) { - printf("link: '%s'\n", udev_list_entry_get_name(list_entry)); + log_info("link: '%s'", udev_list_entry_get_name(list_entry)); count++; } if (count > 0) - printf("found %i links\n", count); + log_info("found %i links", count); count = 0; udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) { - printf("property: '%s=%s'\n", + log_info("property: '%s=%s'", udev_list_entry_get_name(list_entry), udev_list_entry_get_value(list_entry)); count++; } if (count > 0) - printf("found %i properties\n", count); + log_info("found %i properties", count); str = udev_device_get_property_value(device, "MAJOR"); if (str != NULL) - printf("MAJOR: '%s'\n", str); + log_info("MAJOR: '%s'", str); str = udev_device_get_sysattr_value(device, "dev"); if (str != NULL) - printf("attr{dev}: '%s'\n", str); - - printf("\n"); + log_info("attr{dev}: '%s'", str); } -static int test_device(struct udev *udev, const char *syspath) { +static void test_device(struct udev *udev, const char *syspath) { _cleanup_udev_device_unref_ struct udev_device *device; - printf("looking at device: %s\n", syspath); + log_info("looking at device: %s", syspath); device = udev_device_new_from_syspath(udev, syspath); - if (device == NULL) { - printf("no device found\n"); - return -1; - } - print_device(device); - - return 0; + if (device == NULL) + log_warning_errno(errno, "udev_device_new_from_syspath: %m"); + else + print_device(device); } -static int test_device_parents(struct udev *udev, const char *syspath) { +static void test_device_parents(struct udev *udev, const char *syspath) { _cleanup_udev_device_unref_ struct udev_device *device; struct udev_device *device_parent; - printf("looking at device: %s\n", syspath); + log_info("looking at device: %s", syspath); device = udev_device_new_from_syspath(udev, syspath); if (device == NULL) - return -1; + return; - printf("looking at parents\n"); + log_info("looking at parents"); device_parent = device; do { print_device(device_parent); device_parent = udev_device_get_parent(device_parent); } while (device_parent != NULL); - printf("looking at parents again\n"); + log_info("looking at parents again"); device_parent = device; do { print_device(device_parent); device_parent = udev_device_get_parent(device_parent); } while (device_parent != NULL); - - return 0; } -static int test_device_devnum(struct udev *udev) { +static void test_device_devnum(struct udev *udev) { dev_t devnum = makedev(1, 3); - struct udev_device *device; + _cleanup_udev_device_unref_ struct udev_device *device; - printf("looking up device: %u:%u\n", major(devnum), minor(devnum)); + log_info("looking up device: %u:%u", major(devnum), minor(devnum)); device = udev_device_new_from_devnum(udev, 'c', devnum); if (device == NULL) - return -1; - print_device(device); - udev_device_unref(device); - return 0; + log_warning_errno(errno, "udev_device_new_from_devnum: %m"); + else + print_device(device); } -static int test_device_subsys_name(struct udev *udev) { - struct udev_device *device; - - printf("looking up device: 'block':'sda'\n"); - device = udev_device_new_from_subsystem_sysname(udev, "block", "sda"); - if (device == NULL) - return -1; - print_device(device); - udev_device_unref(device); - - printf("looking up device: 'subsystem':'pci'\n"); - device = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci"); - if (device == NULL) - return -1; - print_device(device); - udev_device_unref(device); - - printf("looking up device: 'drivers':'scsi:sd'\n"); - device = udev_device_new_from_subsystem_sysname(udev, "drivers", "scsi:sd"); - if (device == NULL) - return -1; - print_device(device); - udev_device_unref(device); +static void test_device_subsys_name(struct udev *udev, const char *subsys, const char *dev) { + _cleanup_udev_device_unref_ struct udev_device *device; - printf("looking up device: 'module':'printk'\n"); - device = udev_device_new_from_subsystem_sysname(udev, "module", "printk"); + log_info("looking up device: '%s:%s'", subsys, dev); + device = udev_device_new_from_subsystem_sysname(udev, subsys, dev); if (device == NULL) - return -1; - print_device(device); - udev_device_unref(device); - return 0; + log_warning_errno(errno, "udev_device_new_from_subsystem_sysname: %m"); + else + print_device(device); } static int test_enumerate_print_list(struct udev_enumerate *enumerate) { @@ -200,63 +170,45 @@ static int test_enumerate_print_list(struct udev_enumerate *enumerate) { device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate), udev_list_entry_get_name(list_entry)); if (device != NULL) { - printf("device: '%s' (%s)\n", - udev_device_get_syspath(device), - udev_device_get_subsystem(device)); + log_info("device: '%s' (%s)", + udev_device_get_syspath(device), + udev_device_get_subsystem(device)); udev_device_unref(device); count++; } } - printf("found %i devices\n\n", count); + log_info("found %i devices", count); return count; } -static int test_monitor(struct udev *udev) { - struct udev_monitor *udev_monitor = NULL; - int fd_ep; - int fd_udev = -1; - struct epoll_event ep_udev, ep_stdin; +static void test_monitor(struct udev *udev) { + _cleanup_udev_monitor_unref_ struct udev_monitor *udev_monitor; + _cleanup_close_ int fd_ep; + int fd_udev; + struct epoll_event ep_udev = { + .events = EPOLLIN, + }, ep_stdin = { + .events = EPOLLIN, + .data.fd = STDIN_FILENO, + }; fd_ep = epoll_create1(EPOLL_CLOEXEC); - if (fd_ep < 0) { - printf("error creating epoll fd: %m\n"); - goto out; - } + assert_se(fd_ep >= 0); udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); - if (udev_monitor == NULL) { - printf("no socket\n"); - goto out; - } - fd_udev = udev_monitor_get_fd(udev_monitor); + assert_se(udev_monitor != NULL); - if (udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) < 0 || - udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) < 0 || - udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") < 0) { - printf("filter failed\n"); - goto out; - } + fd_udev = udev_monitor_get_fd(udev_monitor); + ep_udev.data.fd = fd_udev; - if (udev_monitor_enable_receiving(udev_monitor) < 0) { - printf("bind failed\n"); - goto out; - } + assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) >= 0); + assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) >= 0); + assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") >= 0); - memzero(&ep_udev, sizeof(struct epoll_event)); - ep_udev.events = EPOLLIN; - ep_udev.data.fd = fd_udev; - if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) { - printf("fail to add fd to epoll: %m\n"); - goto out; - } + assert_se(udev_monitor_enable_receiving(udev_monitor) >= 0); - memzero(&ep_stdin, sizeof(struct epoll_event)); - ep_stdin.events = EPOLLIN; - ep_stdin.data.fd = STDIN_FILENO; - if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) < 0) { - printf("fail to add fd to epoll: %m\n"); - goto out; - } + assert_se(epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) >= 0); + assert_se(epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) >= 0); for (;;) { int fdcount; @@ -265,7 +217,7 @@ static int test_monitor(struct udev *udev) { int i; printf("waiting for events from udev, press ENTER to exit\n"); - fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1); + fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), -1); printf("epoll fd count: %i\n", fdcount); for (i = 0; i < fdcount; i++) { @@ -279,36 +231,29 @@ static int test_monitor(struct udev *udev) { udev_device_unref(device); } else if (ev[i].data.fd == STDIN_FILENO && ev[i].events & EPOLLIN) { printf("exiting loop\n"); - goto out; + return; } } } -out: - if (fd_ep >= 0) - close(fd_ep); - udev_monitor_unref(udev_monitor); - return 0; } -static int test_queue(struct udev *udev) { +static void test_queue(struct udev *udev) { struct udev_queue *udev_queue; + bool empty; udev_queue = udev_queue_new(udev); - if (udev_queue == NULL) - return -1; - - if (udev_queue_get_queue_is_empty(udev_queue)) - printf("queue is empty\n"); + assert_se(udev_queue); + empty = udev_queue_get_queue_is_empty(udev_queue); + log_info("queue is %s", empty ? "empty" : "not empty"); udev_queue_unref(udev_queue); - return 0; } static int test_enumerate(struct udev *udev, const char *subsystem) { struct udev_enumerate *udev_enumerate; int r; - printf("enumerate '%s'\n", subsystem == NULL ? "" : subsystem); + log_info("enumerate '%s'", subsystem == NULL ? "" : subsystem); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -317,7 +262,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'net' + duplicated scan + null + zero\n"); + log_info("enumerate 'net' + duplicated scan + null + zero"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -337,7 +282,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'block'\n"); + log_info("enumerate 'block'"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -351,7 +296,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'not block'\n"); + log_info("enumerate 'not block'"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -360,7 +305,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'pci, mem, vc'\n"); + log_info("enumerate 'pci, mem, vc'"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -371,7 +316,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'subsystem'\n"); + log_info("enumerate 'subsystem'"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -379,7 +324,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) { test_enumerate_print_list(udev_enumerate); udev_enumerate_unref(udev_enumerate); - printf("enumerate 'property IF_FS_*=filesystem'\n"); + log_info("enumerate 'property IF_FS_*=filesystem'"); udev_enumerate = udev_enumerate_new(udev); if (udev_enumerate == NULL) return -1; @@ -397,32 +342,30 @@ static void test_hwdb(struct udev *udev, const char *modalias) { hwdb = udev_hwdb_new(udev); udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0)) - printf("'%s'='%s'\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry)); - printf("\n"); + log_info("'%s'='%s'", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry)); hwdb = udev_hwdb_unref(hwdb); assert_se(hwdb == NULL); } int main(int argc, char *argv[]) { - struct udev *udev = NULL; + _cleanup_udev_unref_ struct udev *udev = NULL; static const struct option options[] = { - { "syspath", required_argument, NULL, 'p' }, + { "syspath", required_argument, NULL, 'p' }, { "subsystem", required_argument, NULL, 's' }, - { "debug", no_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, + { "debug", no_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, {} }; const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; - char path[1024]; int c; udev = udev_new(); - printf("context: %p\n", udev); + log_info("context: %p", udev); if (udev == NULL) { - printf("no context\n"); + log_info("no context"); return 1; } @@ -444,14 +387,14 @@ int main(int argc, char *argv[]) { case 'h': printf("--debug --syspath= --subsystem= --help\n"); - goto out; + return EXIT_SUCCESS; case 'V': printf("%s\n", VERSION); - goto out; + return EXIT_SUCCESS; case '?': - goto out; + return EXIT_FAILURE; default: assert_not_reached("Unhandled option code."); @@ -459,14 +402,16 @@ int main(int argc, char *argv[]) { /* add sys path if needed */ - if (!startswith(syspath, "/sys")) { - xsprintf(path, "/sys/%s", syspath); - syspath = path; - } + if (!startswith(syspath, "/sys")) + syspath = strjoina("/sys/", syspath); test_device(udev, syspath); test_device_devnum(udev); - test_device_subsys_name(udev); + test_device_subsys_name(udev, "block", "sda"); + test_device_subsys_name(udev, "subsystem", "pci"); + test_device_subsys_name(udev, "drivers", "scsi:sd"); + test_device_subsys_name(udev, "module", "printk"); + test_device_parents(udev, syspath); test_enumerate(udev, subsystem); @@ -476,7 +421,6 @@ int main(int argc, char *argv[]) { test_hwdb(udev, "usb:v0D50p0011*"); test_monitor(udev); -out: - udev_unref(udev); - return 0; + + return EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf From 301a9c67aaad103a5fb0cd06d775ded208220f49 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 1 Mar 2016 21:44:08 -0500 Subject: test-libudev: disable monitor mode by default and add to automatic tests --- Makefile.am | 4 +++- src/test/test-libudev.c | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index e2d5328c1b..270f09641b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3709,8 +3709,10 @@ endif endif endif +tests += \ + test-libudev + manual_tests += \ - test-libudev \ test-udev test_libudev_SOURCES = \ diff --git a/src/test/test-libudev.c b/src/test/test-libudev.c index 5ac513b013..e28de9b37b 100644 --- a/src/test/test-libudev.c +++ b/src/test/test-libudev.c @@ -350,12 +350,14 @@ static void test_hwdb(struct udev *udev, const char *modalias) { int main(int argc, char *argv[]) { _cleanup_udev_unref_ struct udev *udev = NULL; + bool arg_monitor = false; static const struct option options[] = { { "syspath", required_argument, NULL, 'p' }, { "subsystem", required_argument, NULL, 's' }, { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, + { "monitor", no_argument, NULL, 'm' }, {} }; const char *syspath = "/devices/virtual/mem/null"; @@ -393,6 +395,10 @@ int main(int argc, char *argv[]) { printf("%s\n", VERSION); return EXIT_SUCCESS; + case 'm': + arg_monitor = true; + break; + case '?': return EXIT_FAILURE; @@ -420,7 +426,8 @@ int main(int argc, char *argv[]) { test_hwdb(udev, "usb:v0D50p0011*"); - test_monitor(udev); + if (arg_monitor) + test_monitor(udev); return EXIT_SUCCESS; } -- cgit v1.2.3-54-g00ecf From ce1e49c3d6ffd1067e04f26abc9dcd6ce9bc1401 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 1 Mar 2016 21:50:41 -0500 Subject: test-journal-enum: enable by default It will get at most ten values, I don't know why we wouldn't always run this test. --- Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 270f09641b..04553d81b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4123,11 +4123,9 @@ catalog-remove-hook: UNINSTALL_DATA_HOOKS += \ catalog-remove-hook -manual_tests += \ - test-journal-enum - tests += \ test-journal \ + test-journal-enum \ test-journal-send \ test-journal-syslog \ test-journal-match \ -- cgit v1.2.3-54-g00ecf From b3ad5fa944245c8dd57980271aaf840acaf31881 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 2 Mar 2016 15:29:36 -0500 Subject: lldp: fix memleak in_addr_to_string returned 0, which was treated as error by the calling code, which expects 1 on success. CID #1351757, #1351758. --- src/libsystemd-network/lldp-neighbor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index c61941cd70..190c9baece 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -446,7 +446,7 @@ static int format_mac_address(const void *data, size_t sz, char **ret) { static int format_network_address(const void *data, size_t sz, char **ret) { union in_addr_union a; - int family; + int family, r; if (sz == 6 && ((uint8_t*) data)[1] == 1) { memcpy(&a.in, (uint8_t*) data + 2, sizeof(a.in)); @@ -457,7 +457,10 @@ static int format_network_address(const void *data, size_t sz, char **ret) { } else return 0; - return in_addr_to_string(family, &a, ret); + r = in_addr_to_string(family, &a, ret); + if (r < 0) + return r; + return 1; } _public_ int sd_lldp_neighbor_get_chassis_id_as_string(sd_lldp_neighbor *n, const char **ret) { -- cgit v1.2.3-54-g00ecf From 72e551f40b0bcc6f59b093b70424f3af32ed759b Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 2 Mar 2016 15:43:30 -0500 Subject: networkctl: use ETHER_ADDR_NULL in one more place --- src/network/networkctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 0679114f74..e5b08d4826 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -147,7 +147,6 @@ static int link_info_compare(const void *a, const void *b) { } static int decode_link(sd_netlink_message *m, LinkInfo *info) { - static const struct ether_addr null_address = {}; const char *name; uint16_t type; int r; @@ -178,7 +177,7 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info) { info->has_mac_address = sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 && - memcmp(&info->mac_address, &null_address, sizeof(struct ether_addr)) != 0; + memcmp(&info->mac_address, ÐER_ADDR_NULL, sizeof(struct ether_addr)) != 0; info->has_mtu = sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu) && -- cgit v1.2.3-54-g00ecf From 2388b2f4d4481c69935abdc9c3ed9928d1f15a46 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 2 Mar 2016 15:43:41 -0500 Subject: networkctl: avoid reading past end of input buffer name is IFNAMSIZ bytes, but we would copy sizeof(info->name) bytes, which is IFNAMSIZ + 1. In effect we would go outside of the source buffer and possibly leave a non-null terminated string in info->name. CID #1351754. --- src/network/networkctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/network/networkctl.c b/src/network/networkctl.c index e5b08d4826..6ec7a911ca 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -45,6 +45,7 @@ #include "string-table.h" #include "string-util.h" #include "strv.h" +#include "strxcpyx.h" #include "terminal-util.h" #include "util.h" #include "verbs.h" @@ -173,7 +174,7 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info) { if (r < 0) return r; - strncpy(info->name, name, sizeof(info->name)); + strscpy(info->name, sizeof info->name, name); info->has_mac_address = sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 && -- cgit v1.2.3-54-g00ecf From b5ec6ada9cd03035c32b43d1df265d48cd6d168e Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 3 Mar 2016 11:39:02 -0500 Subject: test-selinux: use yes_no() and strnull() --- src/test/test-selinux.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/test-selinux.c b/src/test/test-selinux.c index c2152269f8..7545ad3764 100644 --- a/src/test/test-selinux.c +++ b/src/test/test-selinux.c @@ -23,7 +23,9 @@ #include "fd-util.h" #include "log.h" #include "selinux-util.h" +#include "string-util.h" #include "time-util.h" +#include "util.h" static void test_testing(void) { bool b; @@ -31,18 +33,18 @@ static void test_testing(void) { log_info("============ %s ==========", __func__); b = mac_selinux_use(); - log_info("mac_selinux_use → %d", b); + log_info("mac_selinux_use → %s", yes_no(b)); b = mac_selinux_have(); - log_info("mac_selinux_have → %d", b); + log_info("mac_selinux_have → %s", yes_no(b)); mac_selinux_retest(); b = mac_selinux_use(); - log_info("mac_selinux_use → %d", b); + log_info("mac_selinux_use → %s", yes_no(b)); b = mac_selinux_have(); - log_info("mac_selinux_have → %d", b); + log_info("mac_selinux_have → %s", yes_no(b)); } static void test_loading(void) { @@ -76,16 +78,19 @@ static void test_misc(const char* fname) { log_info("============ %s ==========", __func__); r = mac_selinux_get_our_label(&label); - log_info_errno(r, "mac_selinux_get_our_label → %d (%m), \"%s\"", r, label); + log_info_errno(r, "mac_selinux_get_our_label → %d (%m), \"%s\"", + r, strnull(label)); r = mac_selinux_get_create_label_from_exe(fname, &label2); - log_info_errno(r, "mac_selinux_create_label_from_exe → %d (%m), \"%s\"", r, label2); + log_info_errno(r, "mac_selinux_create_label_from_exe → %d (%m), \"%s\"", + r, strnull(label2)); fd = socket(AF_INET, SOCK_DGRAM, 0); assert_se(fd >= 0); r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3); - log_info_errno(r, "mac_selinux_get_child_mls_label → %d (%m), \"%s\"", r, label3); + log_info_errno(r, "mac_selinux_get_child_mls_label → %d (%m), \"%s\"", + r, strnull(label3)); } static void test_create_file_prepare(const char* fname) { -- cgit v1.2.3-54-g00ecf From 15b947fb798cd131355ba9935802d58e92bdba6e Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 4 Mar 2016 21:46:47 -0500 Subject: test-compress-benchmark: skip loop iteration if size is 0 Otherwise we would hit an assert in the compression code. --- src/journal/test-compress-benchmark.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 5b2d130cd6..0ef6d36a50 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -105,6 +105,8 @@ static void test_compress_decompress(const char* label, const char* type, int r; size = permute(i); + if (size == 0) + continue; log_debug("%s %zu %zu", type, i, size); -- cgit v1.2.3-54-g00ecf From 58015d7815bce405c7c0ac082d8c2f407ec07eeb Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Sat, 5 Mar 2016 11:22:45 -0500 Subject: README: bump kernel version to 3.12 It is required for %P is sysctl kernel.core_pattern. Fixes #2800. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 3bdf4107cf..0118c102f6 100644 --- a/README +++ b/README @@ -35,7 +35,7 @@ LICENSE: - except src/udev/* which is (currently still) GPLv2, GPLv2+ REQUIREMENTS: - Linux kernel >= 3.11 + Linux kernel >= 3.12 Linux kernel >= 4.2 for unified cgroup hierarchy support Kernel Config Options: -- cgit v1.2.3-54-g00ecf