>From f765c6881f9b237163aa0178df3da5540f282f87 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 30 Aug 2021 02:06:23 +0200 Subject: [PATCH 2/2] spawn-pipe: Fix test failure when running under QEMU user-mode. * tests/test-spawn-pipe-child.c: Include , , 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 | 9 +++++++++ modules/spawn-pipe-tests | 2 ++ tests/test-spawn-pipe-child.c | 25 +++++++++++++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76562fea4..7933058e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2021-08-29 Bruno Haible + + spawn-pipe: Fix test failure when running under QEMU user-mode. + * tests/test-spawn-pipe-child.c: Include , , + 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 execute: Fix test failure when running under QEMU user-mode. diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests index a204031a6..64bcde2b5 100644 --- a/modules/spawn-pipe-tests +++ b/modules/spawn-pipe-tests @@ -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: diff --git a/tests/test-spawn-pipe-child.c b/tests/test-spawn-pipe-child.c index 9d4dd174b..ee0ba9ad6 100644 --- a/tests/test-spawn-pipe-child.c +++ b/tests/test-spawn-pipe-child.c @@ -18,9 +18,11 @@ #include #include +#include #include #include #include +#include #include #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 . */ #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; } -- 2.25.1