From ec757e920c9f57a89a4378c10cd96264b058f418 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Oct 2023 14:05:25 +0200 Subject: [PATCH 1/2] test/test-chown-rec: skip ACL tests if kernel has no ACL support The second half of `chown_recursive` works only if the kernel has ACL support. --- src/test/test-chown-rec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/test-chown-rec.c b/src/test/test-chown-rec.c index dcff17efec..5d83f5915a 100644 --- a/src/test/test-chown-rec.c +++ b/src/test/test-chown-rec.c @@ -44,6 +44,7 @@ TEST(chown_recursive) { const char *p; const uid_t uid = getuid(); const gid_t gid = getgid(); + int r; umask(022); assert_se(mkdtemp_malloc(NULL, &t) >= 0); @@ -95,7 +96,11 @@ TEST(chown_recursive) { /* We now apply an xattr to the dir, and check it again */ p = strjoina(t, "/dir"); - assert_se(setxattr(p, "system.posix_acl_access", acl, sizeof(acl), 0) >= 0); + r = RET_NERRNO(setxattr(p, "system.posix_acl_access", acl, sizeof(acl), 0)); + if (ERRNO_IS_NEG_NOT_SUPPORTED(r)) + return (void) log_tests_skipped_errno(r, "no acl supported on /tmp"); + + assert_se(r >= 0); assert_se(setxattr(p, "system.posix_acl_default", default_acl, sizeof(default_acl), 0) >= 0); assert_se(lstat(p, &st) >= 0); assert_se(S_ISDIR(st.st_mode)); From 8a87a16bbbfd1bf965e9efe67b91e1eabb7df2c4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Oct 2023 14:24:56 +0200 Subject: [PATCH 2/2] test/test-execute: skip PrivateNetwork tests if kernel has no dummy netdevice support --- src/test/test-execute.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 68796ce1ac..417e484fc9 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -38,6 +38,7 @@ static char *user_runtime_unit_dir = NULL; static bool can_unshare; +static bool have_net_dummy; static unsigned n_ran_tests = 0; STATIC_DESTRUCTOR_REGISTER(user_runtime_unit_dir, freep); @@ -1074,6 +1075,9 @@ static void test_exec_ambientcapabilities(Manager *m) { static void test_exec_privatenetwork(Manager *m) { int r; + if (!have_net_dummy) + return (void)log_notice("Skipping %s, dummy network interface not available", __func__); + r = find_executable("ip", NULL); if (r < 0) { log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__); @@ -1087,6 +1091,9 @@ static void test_exec_privatenetwork(Manager *m) { static void test_exec_networknamespacepath(Manager *m) { int r; + if (!have_net_dummy) + return (void)log_notice("Skipping %s, dummy network interface not available", __func__); + r = find_executable("ip", NULL); if (r < 0) { log_notice_errno(r, "Skipping %s, could not find ip binary: %m", __func__); @@ -1424,18 +1431,23 @@ static int intro(void) { return log_tests_skipped("/sys is mounted read-only"); /* Create dummy network interface for testing PrivateNetwork=yes */ - (void) system("ip link add dummy-test-exec type dummy"); + have_net_dummy = system("ip link add dummy-test-exec type dummy") == 0; - /* Create a network namespace and a dummy interface in it for NetworkNamespacePath= */ - (void) system("ip netns add test-execute-netns"); - (void) system("ip netns exec test-execute-netns ip link add dummy-test-ns type dummy"); + if (have_net_dummy) { + /* Create a network namespace and a dummy interface in it for NetworkNamespacePath= */ + (void) system("ip netns add test-execute-netns"); + (void) system("ip netns exec test-execute-netns ip link add dummy-test-ns type dummy"); + } return EXIT_SUCCESS; } static int outro(void) { - (void) system("ip link del dummy-test-exec"); - (void) system("ip netns del test-execute-netns"); + if (have_net_dummy) { + (void) system("ip link del dummy-test-exec"); + (void) system("ip netns del test-execute-netns"); + } + (void) rmdir(PRIVATE_UNIT_DIR); return EXIT_SUCCESS;