From: Daan De Meyer Date: Mon, 24 Nov 2025 12:07:39 +0000 (+0100) Subject: tests: Assume we're running in a chroot if check fails X-Git-Tag: v259-rc2~35^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43687c22ab5a07906482271cf47c581087924638;p=thirdparty%2Fsystemd.git tests: Assume we're running in a chroot if check fails running_in_chroot() will fail when a test is executed as a non-root user without CAP_DAC_READ_SEARCH as it won't be able to access /proc/1/root. Let's make things more robust by skipping tests if we can't detect if we're in a chroot or not, since if we can't even detect if we're in a chroot or not, chances are we're missing the required privileges to execute the test anyway. --- diff --git a/src/test/test-execute.c b/src/test/test-execute.c index d0435210349..65908bc8fcd 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -1612,7 +1612,7 @@ 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) + if (running_in_chroot() != 0) return log_tests_skipped("running in chroot"); if (enter_cgroup_subroot(NULL) == -ENOMEDIUM) diff --git a/src/test/test-loop-block.c b/src/test/test-loop-block.c index 144f898f3c7..76046f98ada 100644 --- a/src/test/test-loop-block.c +++ b/src/test/test-loop-block.c @@ -240,7 +240,7 @@ static int run(int argc, char *argv[]) { if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) return log_tests_skipped("not running privileged"); - if (detect_container() > 0 || running_in_chroot() > 0) + if (detect_container() != 0 || running_in_chroot() != 0) return log_tests_skipped("Test not supported in a container/chroot, requires udev/uevent notifications"); assert_se(loop_device_make(fd, O_RDWR, 0, UINT64_MAX, 0, LO_FLAGS_PARTSCAN, LOCK_EX, &loop) >= 0); diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 5d352a7df07..7e40ca79ea3 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -38,7 +38,7 @@ #define CHECK_PRIV \ if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) \ return (void) log_tests_skipped("Not privileged"); \ - if (running_in_chroot() > 0) \ + if (running_in_chroot() != 0) \ return (void) log_tests_skipped("running in chroot"); TEST(mount_option_mangle) { diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index 04426365f89..d4c830b4768 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -457,7 +457,7 @@ 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) { + 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; diff --git a/src/test/test-reread-partition-table.c b/src/test/test-reread-partition-table.c index c56e44d8efd..33ab36c5f2c 100644 --- a/src/test/test-reread-partition-table.c +++ b/src/test/test-reread-partition-table.c @@ -49,7 +49,7 @@ TEST(rereadpt) { return (void) log_tests_skipped("test not available in container"); if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) return (void) log_tests_skipped("test requires privileges"); - if (running_in_chroot() > 0) + if (running_in_chroot() != 0) return (void) log_tests_skipped("test not available in chroot()"); _cleanup_free_ char *sfdisk_path = NULL;