]> Savannah Git Hosting - gnulib.git/commitdiff
spawn-pipe: Fix test failure when running under QEMU user-mode.
authorBruno Haible <bruno@clisp.org>
Mon, 30 Aug 2021 00:06:23 +0000 (02:06 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 30 Aug 2021 00:14:33 +0000 (02:14 +0200)
* tests/test-spawn-pipe-child.c: Include <stdbool.h>, <string.h>,
qemu.h.
(main): Under QEMU user-mode, allow fd 2 or fd 3 to be open.
* modules/spawn-pipe-tests (Files): Add qemu.h.
(Depends-on): Add stdbool.

ChangeLog
modules/spawn-pipe-tests
tests/test-spawn-pipe-child.c

index 76562fea4204222b7b21c552c4b9da974f01b709..7933058e8f4bd2394a6e1ae72c754b9b9c2da54e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-08-29  Bruno Haible  <bruno@clisp.org>
+
+       spawn-pipe: Fix test failure when running under QEMU user-mode.
+       * tests/test-spawn-pipe-child.c: Include <stdbool.h>, <string.h>,
+       qemu.h.
+       (main): Under QEMU user-mode, allow fd 2 or fd 3 to be open.
+       * modules/spawn-pipe-tests (Files): Add qemu.h.
+       (Depends-on): Add stdbool.
+
 2021-08-29  Bruno Haible  <bruno@clisp.org>
 
        execute: Fix test failure when running under QEMU user-mode.
index a204031a612e3cd336ef6f6942265bdc0b8fe9c2..64bcde2b5938d6a8e60d41d014509278d9937d75 100644 (file)
@@ -6,11 +6,13 @@ tests/test-spawn-pipe-script.c
 tests/executable-script
 tests/executable-script.sh
 tests/executable-shell-script
+tests/qemu.h
 tests/macros.h
 
 Depends-on:
 close
 msvc-inval
+stdbool
 stdint
 
 configure.ac:
index 9d4dd174b15d093031e5bfc27b7b7d16c48521bc..ee0ba9ad64ccd12d914529d04aa502a5b7a7b9c9 100644 (file)
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #if defined _WIN32 && ! defined __CYGWIN__
@@ -47,12 +49,17 @@ static FILE *myerr;
 #undef fdopen
 #undef fflush
 #undef fprintf
+#undef open
 #undef read
+#undef strcasestr
+#undef strstr
 #undef write
 #if defined _WIN32 && !defined __CYGWIN__
 # define fdopen _fdopen
 #endif
 
+#include "qemu.h"
+
 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
 static void __cdecl
 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
@@ -97,6 +104,10 @@ main (int argc, char *argv[])
   _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
 #endif
 
+  /* QEMU 6.1 in user-mode passes an open fd, usually = 3, that references
+     /dev/urandom.  We need to ignore this fd.  */
+  bool is_qemu = is_running_under_qemu_user ();
+
   /* Read one byte from fd 0, and write its value plus one to fd 1.
      fd 2 should be closed iff the argument is 1.  Check that no other file
      descriptors leaked.  */
@@ -120,7 +131,8 @@ main (int argc, char *argv[])
          was closed.  Similarly on native Windows.  Future POSIX will allow
          this, see <http://austingroupbugs.net/view.php?id=173>.  */
 #if !(defined __hpux || (defined _WIN32 && ! defined __CYGWIN__))
-      ASSERT (! is_open (STDERR_FILENO));
+      if (!is_qemu)
+        ASSERT (! is_open (STDERR_FILENO));
 #endif
       break;
     default:
@@ -129,11 +141,12 @@ main (int argc, char *argv[])
 
   int fd;
   for (fd = 3; fd < 7; fd++)
-    {
-      errno = 0;
-      ASSERT (close (fd) == -1);
-      ASSERT (errno == EBADF);
-    }
+    if (!(is_qemu && fd == 3))
+      {
+        errno = 0;
+        ASSERT (close (fd) == -1);
+        ASSERT (errno == EBADF);
+      }
 
   return 0;
 }