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

ChangeLog
modules/execute-tests
tests/test-execute-child.c

index 511765e126babce8c0f9a66ef4113a23f0a1b870..76562fea4204222b7b21c552c4b9da974f01b709 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-08-29  Bruno Haible  <bruno@clisp.org>
+
+       execute: Fix test failure when running under QEMU user-mode.
+       * tests/test-execute-child.c: Include <stdbool.h>, qemu.h.
+       (main): Under QEMU user-mode, allow fd 3 to be open.
+       * modules/execute-tests (Files): Add qemu.h.
+       (Depends-on): Add stdbool.
+
 2021-08-29  Bruno Haible  <bruno@clisp.org>
 
        posix_spawn_file_actions_addfchdir: Avoid test failure under QEMU.
index 735f55c94d3b3001df7fadb9625ecb4e861b1593..14d48676c5ea8caa277cbf27f4f89255b886721d 100644 (file)
@@ -6,6 +6,7 @@ tests/test-execute-script.c
 tests/executable-script
 tests/executable-script.sh
 tests/executable-shell-script
+tests/qemu.h
 tests/macros.h
 
 Depends-on:
@@ -14,6 +15,7 @@ fcntl
 mkdir
 msvc-inval
 read-file
+stdbool
 stdint
 unistd
 
index dbaae1e96203d13d840762b608c9bd9f0647c000..481e50f3482ac4d76566cc65243cf273f1fb9838 100644 (file)
@@ -41,6 +41,7 @@ is_device (int fd)
 /* Now include the other header files.  */
 #include <fcntl.h>
 #include <signal.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -57,6 +58,7 @@ is_device (int fd)
 
 /* In this file, we use only system functions, no overrides from gnulib.  */
 #undef atoi
+#undef close
 #undef fcntl
 #undef fflush
 #undef fgetc
@@ -64,13 +66,18 @@ is_device (int fd)
 #undef fputs
 #undef getcwd
 #undef isatty
+#undef open
 #undef raise
 #undef read
 #undef sprintf
+#undef strcasestr
 #undef strcmp
 #undef strlen
+#undef strstr
 #undef write
 
+#include "qemu.h"
+
 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
 static void __cdecl
 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
@@ -166,12 +173,15 @@ 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 = 3, that references
+           /dev/urandom.  We need to ignore this fd.  */
+        bool is_qemu = is_running_under_qemu_user ();
         char buf[300];
         buf[0] = '\0';
         char *p = buf;
         int fd;
         for (fd = 0; fd < 20; fd++)
-          if (is_open (fd))
+          if (is_open (fd) && !(is_qemu && fd == 3))
             {
               sprintf (p, "%d ", fd);
               p += strlen (p);