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