From patchwork Wed Mar 29 11:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 13192312 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 54605C6FD18 for ; Wed, 29 Mar 2023 11:05:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phTbp-0001b8-VU; Wed, 29 Mar 2023 07:04:53 -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 1phTbo-0001b0-HW for qemu-devel@nongnu.org; Wed, 29 Mar 2023 07:04:52 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phTbn-0000Ms-1l for qemu-devel@nongnu.org; Wed, 29 Mar 2023 07:04:52 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4D25C219D6; Wed, 29 Mar 2023 11:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680087888; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=WiM3UmdePLANmMnuEAyIQxJaRdnmeljqC8pnx1LFzMI=; b=HmG9dOGrkUuw/OiB5oKvg03llFDqFNldLTEFjojPj78++blA3dUiLBHrw/6dprzLZtbL18 3f1sDKvqFZ+9uAUCnkp+UD7DOzxsP7Io/eEQuw3JWTp4WWEOXtVH2BmnpgCrv/A18yK2si GAWMM47cWozFYwL+i2HLk/Ve1cXBhpo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680087888; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=WiM3UmdePLANmMnuEAyIQxJaRdnmeljqC8pnx1LFzMI=; b=rsjXGia8tCtzmItR08lPMD6PKxoe8XfvppTknqtLmRVLEE6lX1tv1HwGKF3dF3TDpfHMhf uNAL/RNvFE6/MYBw== Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id 239A42C141; Wed, 29 Mar 2023 11:04:48 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id 0AB4A4A0378; Wed, 29 Mar 2023 13:04:48 +0200 (CEST) From: Andreas Schwab To: Laurent Vivier Subject: [PATCH] linux-user: preserve incoming order of environment variables in the target CC: qemu-devel@nongnu.org X-Yow: Youth of today! Join me in a mass rally for traditional mental attitudes! Date: Wed, 29 Mar 2023 13:04:48 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Received-SPF: pass client-ip=195.135.220.28; envelope-from=schwab@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-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 Do not reverse the order of envionment 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 Reviewed-by: Philippe Mathieu-Daudé --- linux-user/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index 4b18461969..d0ede3f990 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -691,8 +691,13 @@ int main(int argc, char **argv, char **envp) envlist = envlist_create(); /* 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++) { - (void) envlist_setenv(envlist, *wrk); + continue; + } + while (wrk != environ) { + (void) envlist_setenv(envlist, *--wrk); } /* Read the stack limit from the kernel. If it's "unlimited",