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.
This commit is contained in:
Yu Watanabe
2025-09-17 22:20:42 +09:00
parent 2ff79a81a8
commit 6a616e62ad
4 changed files with 20 additions and 3 deletions
+6 -2
View File
@@ -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) {
+3
View File
@@ -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");
+4 -1
View File
@@ -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;
+7
View File
@@ -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");