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_HI,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 259AA1F8C6 for ; Sat, 28 Aug 2021 17:19:48 +0000 (UTC) Received: from localhost ([::1]:52702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mK1ze-0008G0-RY for normalperson@yhbt.net; Sat, 28 Aug 2021 13:19:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mK1zb-0008Fn-Bq for bug-gnulib@gnu.org; Sat, 28 Aug 2021 13:19:43 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.160]:30361) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mK1zZ-0003Tg-1r for bug-gnulib@gnu.org; Sat, 28 Aug 2021 13:19:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1630171177; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=i4KAlrXKBhWdfDolPJeJJ8pj9icqX5Fqh656XCsTn1U=; b=iedHwRVKj1cBOVndZUDLAxHq49jxfTBT8/EUIx7RW8XcTYtETuwxb+85PZA+Utezlm TAd3D9NdqmnqXeFtdlGHLJN6/HCboDXNZ5Py2PKwxaxBJ4SMXUKHz+Oq/gPQtopFUsNd zq+uEhCWVAMI8VKk1rE02QX4kmM1zFE9/ZN8xVOPP6xkSJpf2UDbn9LGjOuoSdDmRZyq ADDFppqMssI7YI4Jkzo7/cBtETivV9TwrxLXkiQkaU4Bxk9F2MS82PCRglHfOYlgwcT3 iDKYlT7reu9Vtrkm9P2LXFaNWhuNBNZEZ095QkyqsN7qI8yTYNfv+6vDIMt3VPn+5BAW 1iuQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH0WWb0LN8XZoH94z26ll5ip689kRYCRMhNyaHrKtI3tZ9C5tre" X-RZG-CLASS-ID: mo00 Received: from omega.localnet by smtp.strato.de (RZmta 47.31.0 AUTH) with ESMTPSA id I0beb9x7SHJbnzl (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Sat, 28 Aug 2021 19:19:37 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: execle, execve, execvpe tests: Fix test failures under qemu user-mode Date: Sat, 28 Aug 2021 19:19:36 +0200 Message-ID: <13664133.EVyyLHbfrO@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.160; 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" In an environment where qemu (user-mode) is used to execute binaries, I'm seeing these test failures: $ cat test-execle.sh.log qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory FAIL test-execle.sh (exit status: 1) $ cat test-execve.sh.log qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory FAIL test-execve.sh (exit status: 1) $ cat test-execvpe.sh.log qemu-riscv64: Could not open '/lib/ld-linux-riscv64-lp64d.so.1': No such file or directory FAIL test-execvpe.sh (exit status: 1) The cause is that the QEMU_LD_PREFIX environment variable is not passed to the program to be executed. This patch fixes it. 2021-08-28 Bruno Haible execle, execve, execvpe tests: Fix test failures under qemu user-mode. * test-execle-main.c: Include . (get_environ_assignment, create_minimal_env): New functions. (main): Call create_minimal_env. * test-execve-main.c: Likewise. * test-execvpe-main.c: Likewise. diff --git a/tests/test-execle-main.c b/tests/test-execle-main.c index 2c085f630..f738293c3 100644 --- a/tests/test-execle-main.c +++ b/tests/test-execle-main.c @@ -25,22 +25,53 @@ SIGNATURE_CHECK (execle, int, (const char *, const char *, ...)); #include +#include + +/* Looks up the NAME=VALUE assignment among the environment variables. + Returns it, or NULL if not found. */ +static const char * +get_environ_assignment (const char *name) +{ + size_t name_len = strlen (name); + char **p; + for (p = environ; *p != NULL; p++) + { + const char *assignment = *p; + if (strncmp (assignment, name, name_len) == 0 + && assignment[name_len] == '=') + return assignment; + } + return NULL; +} + +/* Creates a minimal environment. */ +static void +create_minimal_env (const char *env[5]) +{ + const char **p = env; + *p++ = + #ifdef __CYGWIN__ + /* The Cygwin DLLs needed by the program are in /bin. */ + "PATH=.:/bin"; + #else + "PATH=."; + #endif + *p = get_environ_assignment ("QEMU_LD_PREFIX"); + if (*p != NULL) + p++; + *p = get_environ_assignment ("QEMU_CPU"); + if (*p != NULL) + p++; + *p++ = "Hommingberg=Gepardenforelle"; + *p = NULL; +} int main () { const char *progname = "./test-exec-child"; - const char *env[3] = - { - #ifdef __CYGWIN__ - /* The Cygwin DLLs needed by the program are in /bin. */ - "PATH=.:/bin", - #else - "PATH=.", - #endif - "Hommingberg=Gepardenforelle", - NULL - }; + const char *env[5]; + create_minimal_env (env); execle (progname, progname, "abc def", diff --git a/tests/test-execve-main.c b/tests/test-execve-main.c index 970372da1..6199a7d50 100644 --- a/tests/test-execve-main.c +++ b/tests/test-execve-main.c @@ -25,22 +25,51 @@ SIGNATURE_CHECK (execve, int, (const char *, char * const *, char * const *)); #include +#include + +/* Looks up the NAME=VALUE assignment among the environment variables. + Returns it, or NULL if not found. */ +static const char * +get_environ_assignment (const char *name) +{ + size_t name_len = strlen (name); + char **p; + for (p = environ; *p != NULL; p++) + { + const char *assignment = *p; + if (strncmp (assignment, name, name_len) == 0 + && assignment[name_len] == '=') + return assignment; + } + return NULL; +} + +/* Creates a minimal environment. */ +static void +create_minimal_env (const char *env[5]) +{ + const char **p = env; + *p++ = + #ifdef __CYGWIN__ + /* The Cygwin DLLs needed by the program are in /bin. */ + "PATH=.:/bin"; + #else + "PATH=."; + #endif + *p = get_environ_assignment ("QEMU_LD_PREFIX"); + if (*p != NULL) + p++; + *p = get_environ_assignment ("QEMU_CPU"); + if (*p != NULL) + p++; + *p++ = "Hommingberg=Gepardenforelle"; + *p = NULL; +} int main () { const char *progname = "./test-exec-child"; - const char *env[3] = - { - #ifdef __CYGWIN__ - /* The Cygwin DLLs needed by the program are in /bin. */ - "PATH=.:/bin", - #else - "PATH=.", - #endif - "Hommingberg=Gepardenforelle", - NULL - }; const char *argv[12] = { progname, @@ -56,6 +85,8 @@ main () "", NULL }; + const char *env[5]; + create_minimal_env (env); execve (progname, (char * const *) argv, (char * const *) env); perror ("execve"); diff --git a/tests/test-execvpe-main.c b/tests/test-execvpe-main.c index 560ae8e69..c7aa0a3a2 100644 --- a/tests/test-execvpe-main.c +++ b/tests/test-execvpe-main.c @@ -25,22 +25,51 @@ SIGNATURE_CHECK (execvpe, int, (const char *, char * const *, char * const *)); #include +#include + +/* Looks up the NAME=VALUE assignment among the environment variables. + Returns it, or NULL if not found. */ +static const char * +get_environ_assignment (const char *name) +{ + size_t name_len = strlen (name); + char **p; + for (p = environ; *p != NULL; p++) + { + const char *assignment = *p; + if (strncmp (assignment, name, name_len) == 0 + && assignment[name_len] == '=') + return assignment; + } + return NULL; +} + +/* Creates a minimal environment. */ +static void +create_minimal_env (const char *env[5]) +{ + const char **p = env; + *p++ = + #ifdef __CYGWIN__ + /* The Cygwin DLLs needed by the program are in /bin. */ + "PATH=.:/bin"; + #else + "PATH=."; + #endif + *p = get_environ_assignment ("QEMU_LD_PREFIX"); + if (*p != NULL) + p++; + *p = get_environ_assignment ("QEMU_CPU"); + if (*p != NULL) + p++; + *p++ = "Hommingberg=Gepardenforelle"; + *p = NULL; +} int main () { const char *progname = "test-exec-child"; - const char *env[3] = - { - #ifdef __CYGWIN__ - /* The Cygwin DLLs needed by the program are in /bin. */ - "PATH=.:/bin", - #else - "PATH=.", - #endif - "Hommingberg=Gepardenforelle", - NULL - }; const char *argv[12] = { progname, @@ -56,6 +85,8 @@ main () "", NULL }; + const char *env[5]; + create_minimal_env (env); execvpe (progname, (char * const *) argv, (char * const *) env); perror ("execvpe");