summaryrefslogtreecommitdiff
path: root/tests/test-spawn-pipe-child.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-spawn-pipe-child.c')
-rw-r--r--tests/test-spawn-pipe-child.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/tests/test-spawn-pipe-child.c b/tests/test-spawn-pipe-child.c
index 9d4dd174b1..ee0ba9ad64 100644
--- a/tests/test-spawn-pipe-child.c
+++ b/tests/test-spawn-pipe-child.c
@@ -18,9 +18,11 @@
#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;
}