From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 03B0E1F8C6 for ; Mon, 30 Aug 2021 00:16:28 +0000 (UTC) Received: from localhost ([::1]:54106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKUyR-0002I4-N3 for normalperson@yhbt.net; Sun, 29 Aug 2021 20:16:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKUyN-0002Hv-C8 for bug-gnulib@gnu.org; Sun, 29 Aug 2021 20:16:23 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.21]:13935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKUyK-0006bu-Bl for bug-gnulib@gnu.org; Sun, 29 Aug 2021 20:16:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1630282576; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=6XfArub5c5ctIKnugfr5YVPwb8/TswfjpviUwp7hdp8=; b=nZWFDW4QczfKV98LPiZnjg362Yw8SpGyIfX4719nXxkrHL3ewPzKdbROr+BHGLjmOx KqZNWHZBKL+vvzrUnGQWjjmQ12l9sE4zV2BhLMcfe2nOGItuGJRAGvLfCR0JkTy+zgc/ h+IQmpTZLh7qPVNgIK9Yz6IPq0nOxL5UYAwOFTyDBkf9UsCWr8mO2Y+W6hAyV7vSrWNp tkdKJJpP17iZxR7ukvbaZTHVR73cFzstuAlTaVIoZEWK9C/nNpsilj9HcTN+bAuGF7Fk gb97vPRk90ibAv9YZCRzBvBGa59DoW855K514Ipo0ZXORbU22tLpbiEwsGwHoNZCafmy D3MA== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94z26ll5ip69ul0iGsqz23qGdf6ocUvVBxZEOAQ==" X-RZG-CLASS-ID: mo00 Received: from omega.localnet by smtp.strato.de (RZmta 47.31.0 AUTH) with ESMTPSA id I0beb9x7U0GGsiH (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 30 Aug 2021 02:16:16 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: execute, spawn-pipe: Fix test failures when running under QEMU user-mode Date: Mon, 30 Aug 2021 02:16:15 +0200 Message-ID: <4277706.clyjiGRsXx@omega> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart8924750.eFmWaWnqpD" Content-Transfer-Encoding: 7Bit Received-SPF: none client-ip=85.215.255.21; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --nextPart8924750.eFmWaWnqpD Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" In a QEMU user-mode environment (for various CPUs), the test-execute.sh and test-spawn-pipe.sh tests fail. This happens with qemu 6.1.0, but did not happen with qemu 4.1.0 and older versions. The reason is that when qemu is used to execute a program, the file descriptor 3 is open, referencing /dev/urandom. These two patches work around it. 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. * tests/test-execute-child.c: Include , qemu.h. (main): Under QEMU user-mode, allow fd 3 to be open. * modules/execute-tests (Files): Add qemu.h. (Depends-on): Add stdbool. --nextPart8924750.eFmWaWnqpD Content-Disposition: attachment; filename="0001-execute-Fix-test-failure-when-running-under-QEMU-use.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-execute-Fix-test-failure-when-running-under-QEMU-use.patch" >From 5d5eba1c0c43e4c9638cb857aa7f3c471ae0deba Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 30 Aug 2021 02:05:53 +0200 Subject: [PATCH 1/2] execute: Fix test failure when running under QEMU user-mode. * tests/test-execute-child.c: Include , 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 | 8 ++++++++ modules/execute-tests | 2 ++ tests/test-execute-child.c | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 511765e12..76562fea4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2021-08-29 Bruno Haible + + execute: Fix test failure when running under QEMU user-mode. + * tests/test-execute-child.c: Include , 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 posix_spawn_file_actions_addfchdir: Avoid test failure under QEMU. diff --git a/modules/execute-tests b/modules/execute-tests index 735f55c94..14d48676c 100644 --- a/modules/execute-tests +++ b/modules/execute-tests @@ -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 diff --git a/tests/test-execute-child.c b/tests/test-execute-child.c index dbaae1e96..481e50f34 100644 --- a/tests/test-execute-child.c +++ b/tests/test-execute-child.c @@ -41,6 +41,7 @@ is_device (int fd) /* Now include the other header files. */ #include #include +#include #include #include #include @@ -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); -- 2.25.1 --nextPart8924750.eFmWaWnqpD Content-Disposition: attachment; filename="0002-spawn-pipe-Fix-test-failure-when-running-under-QEMU-.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0002-spawn-pipe-Fix-test-failure-when-running-under-QEMU-.patch" >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 --nextPart8924750.eFmWaWnqpD--