94084c
commit 3438bbca90895d32825a52e31a77dc44d273c1c1
94084c
Author: Florian Weimer <fweimer@redhat.com>
94084c
Date:   Mon Jan 24 18:14:24 2022 +0100
94084c
94084c
    Linux: Detect user namespace support in io/tst-getcwd-smallbuff
94084c
    
94084c
    Otherwise the test fails with certain container runtimes.
94084c
    
94084c
    Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
94084c
    (cherry picked from commit 5b8e7980c5dabd9aaefeba4f0208baa8cf7653ee)
94084c
94084c
diff --git a/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c b/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
94084c
index d460d6e7662dc5e4..55362f6060a2b3be 100644
94084c
--- a/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
94084c
+++ b/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
94084c
@@ -34,6 +34,7 @@
94084c
 #include <sys/un.h>
94084c
 #include <support/check.h>
94084c
 #include <support/temp_file.h>
94084c
+#include <support/test-driver.h>
94084c
 #include <support/xsched.h>
94084c
 #include <support/xunistd.h>
94084c
 
94084c
@@ -188,6 +189,23 @@ do_test (void)
94084c
   xmkdir (MOUNT_NAME, S_IRWXU);
94084c
   atexit (do_cleanup);
94084c
 
94084c
+  /* Check whether user namespaces are supported.  */
94084c
+  {
94084c
+    pid_t pid = xfork ();
94084c
+    if (pid == 0)
94084c
+      {
94084c
+	if (unshare (CLONE_NEWUSER | CLONE_NEWNS) != 0)
94084c
+	  _exit (EXIT_UNSUPPORTED);
94084c
+	else
94084c
+	  _exit (0);
94084c
+      }
94084c
+    int status;
94084c
+    xwaitpid (pid, &status, 0);
94084c
+    TEST_VERIFY_EXIT (WIFEXITED (status));
94084c
+    if (WEXITSTATUS (status) != 0)
94084c
+      return WEXITSTATUS (status);
94084c
+  }
94084c
+
94084c
   TEST_VERIFY_EXIT (socketpair (AF_UNIX, SOCK_STREAM, 0, sockfd) == 0);
94084c
   pid_t child_pid = xclone (child_func, NULL, child_stack,
94084c
 			    sizeof (child_stack),