From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7866) id B06323858438; Mon, 18 Jul 2022 18:57:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B06323858438 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Hudson-Doyle To: glibc-cvs@sourceware.org Subject: [glibc] linux: return UNSUPPORTED from tst-mount if entering mount namespace fails X-Act-Checkin: glibc X-Git-Author: Michael Hudson-Doyle X-Git-Refname: refs/heads/master X-Git-Oldrev: 49889fb256a7f9b894b2d16fea23de1ac25b65e2 X-Git-Newrev: 1f4e90d4683af3763a360951ea1b5e1f164e028a Message-Id: <20220718185738.B06323858438@sourceware.org> Date: Mon, 18 Jul 2022 18:57:38 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 18:57:38 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1f4e90d4683af3763a360951ea1b5e1f164e028a commit 1f4e90d4683af3763a360951ea1b5e1f164e028a Author: Michael Hudson-Doyle Date: Mon Jul 18 11:16:57 2022 +1200 linux: return UNSUPPORTED from tst-mount if entering mount namespace fails Before this the test fails if run in a chroot by a non-root user: warning: could not become root outside namespace (Operation not permitted) ../sysdeps/unix/sysv/linux/tst-mount.c:36: numeric comparison failure left: 1 (0x1); from: errno right: 19 (0x13); from: ENODEV error: ../sysdeps/unix/sysv/linux/tst-mount.c:39: not true: fd != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:46: not true: r != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:48: not true: r != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:52: numeric comparison failure left: 1 (0x1); from: errno right: 9 (0x9); from: EBADF error: ../sysdeps/unix/sysv/linux/tst-mount.c:55: not true: mfd != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:58: numeric comparison failure left: 1 (0x1); from: errno right: 2 (0x2); from: ENOENT error: ../sysdeps/unix/sysv/linux/tst-mount.c:61: not true: r != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:65: numeric comparison failure left: 1 (0x1); from: errno right: 2 (0x2); from: ENOENT error: ../sysdeps/unix/sysv/linux/tst-mount.c:68: not true: pfd != -1 error: ../sysdeps/unix/sysv/linux/tst-mount.c:75: not true: fd_tree != -1 ../sysdeps/unix/sysv/linux/tst-mount.c:88: numeric comparison failure left: 1 (0x1); from: errno right: 38 (0x26); from: ENOSYS error: 12 test failures Checking that the test can enter a new mount namespace is more correct than just checking the return value of support_become_root() as the test code changes the mount namespace it runs in so running it as root on a system that does not support mount namespaces should still skip. Also change the test to remove the unnecessary fork. Reviewed-by: Carlos O'Donell Diff: --- sysdeps/unix/sysv/linux/tst-mount.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/sysdeps/unix/sysv/linux/tst-mount.c b/sysdeps/unix/sysv/linux/tst-mount.c index 502d7e3433..b6333a60e6 100644 --- a/sysdeps/unix/sysv/linux/tst-mount.c +++ b/sysdeps/unix/sysv/linux/tst-mount.c @@ -20,15 +20,18 @@ #include #include #include -#include #include _Static_assert (sizeof (struct mount_attr) == MOUNT_ATTR_SIZE_VER0, "sizeof (struct mount_attr) != MOUNT_ATTR_SIZE_VER0"); -static void -subprocess (void) +static int +do_test (void) { + support_become_root (); + if (!support_enter_mount_namespace ()) + FAIL_UNSUPPORTED ("cannot enter mount namespace, skipping test"); + int r = fsopen ("it_should_be_not_a_valid_mount", 0); TEST_VERIFY_EXIT (r == -1); if (errno == ENOSYS) @@ -100,20 +103,4 @@ subprocess (void) _exit (0); } -static int -do_test (void) -{ - support_become_root (); - - pid_t pid = xfork (); - if (pid == 0) - subprocess (); - - int status; - xwaitpid (pid, &status, 0); - TEST_VERIFY (WIFEXITED (status)); - - return 0; -} - #include