From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4C455C74A5B for ; Thu, 30 Mar 2023 01:51:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phhRP-0007Hh-OI; Wed, 29 Mar 2023 21:51:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1phhRN-0007HR-9e for qemu-devel@nongnu.org; Wed, 29 Mar 2023 21:51:01 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phhRL-0001DM-4x for qemu-devel@nongnu.org; Wed, 29 Mar 2023 21:51:01 -0400 Received: by mail-ed1-x535.google.com with SMTP id h8so70650778ede.8 for ; Wed, 29 Mar 2023 18:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; t=1680141056; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ra96PTiyny2Ee9F/YwmLVZ9Zq3wtcIxjWq1aIXOTsAs=; b=ywtLuNK/sYnl/tWCIxq1DzWyCh82NrHXFkIQeKkO7Iwi2sY8t0lgNgG8uINnN/+Wyz W4PFN+/wzkByKsBn2LbJzg2fL7NxSAAs2hqY9MguyNFa3eJLoSAHTBA9Hde6hXX7PHTj 6GHGZ0MDha5NMI/K6xo9X1h6bs1qL+IKJ2YG6JhQ6Rw3XiQ2lRnhEN+aTlX4LAIg+p0B X/kzs3+i80nK/1L5IO0qyUdCWkWhUtjgm6CUWsSCVuJYKxlYKr6tReHH2QtwozmkpTxx RmKdpfrCbC21d2wzURMxoV8EdUjen4JgEfdi+8BM3ckQWozVVvLmKwOT9Zxe3Eb0ZRIX WoXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680141056; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ra96PTiyny2Ee9F/YwmLVZ9Zq3wtcIxjWq1aIXOTsAs=; b=58gBR+0snXJgXI75qV88Xdf/+qZFkyNUOfTfp5oN41pOVn86fYC1H9HdVpn+aMF6AT XDI3a6R4uHUgv3e5HoRv9AftB/S0VzQnbIfeql9rYeLEbqYi6pcSk2WanK+94P5mmxzn SYDgFqep4fDUQuFv9J+Le+ZEnIUhp/Vy/esAzd1mV0teCsXJekHYUzGy2oecmyMP/knY xv7WEmoUK9++PYoW9LrogyAe33vB/4U+K9fSaIJkIwqNe+HqQrQhrtar2RcrL5DeMXVs nKMUT/ch+hrDtkb6V/0PAPhVDVCSCbfrWjhVnQGHTtKBrNn5ZdwXgkDLsNBE44bn0REA F1sA== X-Gm-Message-State: AAQBX9fpXB+LruXIoNsOc3wukioHGZ+TNq+4tvx+357hfJa3kwxpKq8A K4bxS5PZMox15DEUE37Hq5eCnSUTFLkMOfgQVC0JDg== X-Google-Smtp-Source: AKy350byjnQt+A1z5A2gkI/gsESMsBBzXCcZb7oZFisFsyMeFywUpTkHKhm61hC66MNDeNOSS+CjHLRFiVUUaB7t+qE= X-Received: by 2002:a17:907:3e8b:b0:931:ce20:db6e with SMTP id hs11-20020a1709073e8b00b00931ce20db6emr11965385ejc.2.1680141055752; Wed, 29 Mar 2023 18:50:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Warner Losh Date: Wed, 29 Mar 2023 19:25:05 -0600 Message-ID: Subject: Re: [PATCH v3] linux-user,bsd-user: preserve incoming order of environment variables in the target To: Andreas Schwab Cc: Laurent Vivier , Kyle Evans , QEMU Developers Content-Type: multipart/alternative; boundary="000000000000cd0e4605f8145257" Received-SPF: none client-ip=2a00:1450:4864:20::535; envelope-from=wlosh@bsdimp.com; helo=mail-ed1-x535.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --000000000000cd0e4605f8145257 Content-Type: text/plain; charset="UTF-8" On Wed, Mar 29, 2023, 9:00 AM Andreas Schwab wrote: > Do not reverse the order of environment variables in the target environ > array relative to the incoming environ order. Some testsuites depend on a > specific order, even though it is not defined by any standard. > > Signed-off-by: Andreas Schwab > --- > bsd-user/main.c | 10 +++++++++- > linux-user/main.c | 10 +++++++++- > 2 files changed, 18 insertions(+), 2 deletions(-) > Reviewed-by: Warner Losh > diff --git a/bsd-user/main.c b/bsd-user/main.c > index 89f225dead..eff834e8d8 100644 > --- a/bsd-user/main.c > +++ b/bsd-user/main.c > @@ -298,8 +298,16 @@ int main(int argc, char **argv) > > envlist = envlist_create(); > > - /* add current environment into the list */ > + /* > + * add current environment into the list > + * envlist_setenv adds to the front of the list; to preserve environ > + * order add from back to front > + */ > for (wrk = environ; *wrk != NULL; wrk++) { > + continue; > + } > + while (wrk != environ) { > + wrk--; > (void) envlist_setenv(envlist, *wrk); > } > > diff --git a/linux-user/main.c b/linux-user/main.c > index 4b18461969..f0173ceefa 100644 > --- a/linux-user/main.c > +++ b/linux-user/main.c > @@ -690,8 +690,16 @@ int main(int argc, char **argv, char **envp) > > envlist = envlist_create(); > > - /* add current environment into the list */ > + /* > + * add current environment into the list > + * envlist_setenv adds to the front of the list; to preserve environ > + * order add from back to front > + */ > for (wrk = environ; *wrk != NULL; wrk++) { > + continue; > + } > + while (wrk != environ) { > + wrk--; > (void) envlist_setenv(envlist, *wrk); > } > > -- > 2.40.0 > > > -- > Andreas Schwab, SUSE Labs, schwab@suse.de > GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 > "And now for something completely different." > --000000000000cd0e4605f8145257 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Mar 29, 2023, 9:00 AM Andreas Schwab <schwab@suse.de> wrote:
Do not reverse the order of environment variables i= n the target environ
array relative to the incoming environ order.=C2=A0 Some testsuites depend = on a
specific order, even though it is not defined by any standard.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
=C2=A0bsd-user/main.c=C2=A0 =C2=A0| 10 +++++++++-
=C2=A0linux-user/main.c | 10 +++++++++-
=C2=A02 files changed, 18 insertions(+), 2 deletions(-)

Reviewed-by: Warner = Losh <imp@bsdimp.com>


diff --git a/bsd-user/main.c b/bsd-user/main.c
index 89f225dead..eff834e8d8 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -298,8 +298,16 @@ int main(int argc, char **argv)

=C2=A0 =C2=A0 =C2=A0envlist =3D envlist_create();

-=C2=A0 =C2=A0 /* add current environment into the list */
+=C2=A0 =C2=A0 /*
+=C2=A0 =C2=A0 =C2=A0* add current environment into the list
+=C2=A0 =C2=A0 =C2=A0* envlist_setenv adds to the front of the list; to pre= serve environ
+=C2=A0 =C2=A0 =C2=A0* order add from back to front
+=C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0for (wrk =3D environ; *wrk !=3D NULL; wrk++) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 while (wrk !=3D environ) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 wrk--;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(void) envlist_setenv(envlist, *wrk);
=C2=A0 =C2=A0 =C2=A0}

diff --git a/linux-user/main.c b/linux-user/main.c
index 4b18461969..f0173ceefa 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -690,8 +690,16 @@ int main(int argc, char **argv, char **envp)

=C2=A0 =C2=A0 =C2=A0envlist =3D envlist_create();

-=C2=A0 =C2=A0 /* add current environment into the list */
+=C2=A0 =C2=A0 /*
+=C2=A0 =C2=A0 =C2=A0* add current environment into the list
+=C2=A0 =C2=A0 =C2=A0* envlist_setenv adds to the front of the list; to pre= serve environ
+=C2=A0 =C2=A0 =C2=A0* order add from back to front
+=C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0for (wrk =3D environ; *wrk !=3D NULL; wrk++) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 continue;
+=C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 while (wrk !=3D environ) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 wrk--;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(void) envlist_setenv(envlist, *wrk);
=C2=A0 =C2=A0 =C2=A0}

--
2.40.0


--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint =3D 0196 BAD8 1CE9 1970 F4BE=C2=A0 1748 E4D4 88E3 0EEA = B9D7
"And now for something completely different."
--000000000000cd0e4605f8145257--