From: Yu Watanabe Date: Tue, 9 Sep 2025 06:15:02 +0000 (+0900) Subject: test: skip several test cases when running in chroot X-Git-Tag: v259-rc1~535^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a616e62ad43fb52eacf083508253aeb9f57da5d;p=thirdparty%2Fsystemd.git test: skip several test cases when running in chroot When we are running in chroot, safe_fork() with FORK_MOUNTNS_SLAVE fails with the following eror: ``` Failed to set mount propagation to MS_SLAVE for all mounts: Invalid argument ``` Let's skip the test cases when we are running in chroot. --- diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index e1ee9e433fb..dc4a32e8a18 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -5,6 +5,7 @@ #include "sd-event.h" +#include "capability-util.h" #include "device-internal.h" #include "device-private.h" #include "device-util.h" @@ -25,14 +26,17 @@ #include "tests.h" #include "tmpfile-util.h" #include "udev-util.h" +#include "virt.h" TEST(mdio_bus) { int r; /* For issue #37711 */ - if (getuid() != 0) - return (void) log_tests_skipped("not running as root"); + if (getuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) + return (void) log_tests_skipped("Not privileged"); + if (running_in_chroot() > 0) + return (void) log_tests_skipped("Running in chroot"); ASSERT_OK(r = safe_fork("(mdio_bus)", FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGTERM|FORK_REOPEN_LOG|FORK_LOG|FORK_WAIT|FORK_NEW_MOUNTNS|FORK_MOUNTNS_SLAVE, NULL)); if (r == 0) { diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 4dad93cfb4f..916ade79606 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -1613,6 +1613,9 @@ static int intro(void) { if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) return log_tests_skipped("not privileged"); + if (running_in_chroot() > 0) + return log_tests_skipped("running in chroot"); + if (enter_cgroup_subroot(NULL) == -ENOMEDIUM) return log_tests_skipped("cgroupfs not available"); diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index a83de3f2b00..57d9a050a5c 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -23,6 +23,7 @@ #include "strv.h" #include "tests.h" #include "tmpfile-util.h" +#include "virt.h" #define FORK_COMMON_FLAGS \ (FORK_CLOSE_ALL_FDS | \ @@ -36,7 +37,9 @@ #define CHECK_PRIV \ if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) \ - return (void) log_tests_skipped("Not privileged"); + return (void) log_tests_skipped("Not privileged"); \ + if (running_in_chroot() > 0) \ + return (void) log_tests_skipped("running in chroot"); TEST(mount_option_mangle) { char *opts = NULL; diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index ceb59ce4555..1da10e9ccc6 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -18,6 +18,7 @@ #include "string-util.h" #include "tests.h" #include "tmpfile-util.h" +#include "virt.h" static void test_mount_propagation_flag_one(const char *name, int ret, unsigned long expected) { unsigned long flags; @@ -455,6 +456,12 @@ static int intro(void) { /* let's move into our own mount namespace with all propagation from the host turned off, so * that /proc/self/mountinfo is static and constant for the whole time our test runs. */ + if (running_in_chroot() > 0) { + /* We cannot remount file system with MS_PRIVATE when running in chroot. */ + log_notice("Running in chroot, proceeding in originating mount namespace."); + return EXIT_SUCCESS; + } + if (unshare(CLONE_NEWNS) < 0) { if (!ERRNO_IS_PRIVILEGE(errno)) return log_error_errno(errno, "Failed to detach mount namespace: %m");