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