+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.
#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__
#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,
_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. */
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:
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;
}