From patchwork Wed Mar 29 13:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 13192448 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 B0745C74A5B for ; Wed, 29 Mar 2023 13:56:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phWGk-0002hp-EY; Wed, 29 Mar 2023 09:55:18 -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 1phWGi-0002gd-P0 for qemu-devel@nongnu.org; Wed, 29 Mar 2023 09:55:16 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phWGh-0000Zp-C0 for qemu-devel@nongnu.org; Wed, 29 Mar 2023 09:55:16 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id DA042219EC; Wed, 29 Mar 2023 13:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680098113; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ne8hidr9sGfns9P9adlpv5Zz/cqof1nqsaMwstyy1Ks=; b=zpjgSpYALhSoagh4JTfS0FFEYNcqmZ8xdws3xoGeGz7T+wlmqzleWKwhOTrFl4eHOV4Ngf eI0EWZQsN3z6t+uIIKHkpJSjZL6lyD7JPGgkipbMZCnxG/U6S99rWIFXaiagoicaWJsRcv XtwQoXZh5f50azub7B4APh/6KQizWXg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680098113; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ne8hidr9sGfns9P9adlpv5Zz/cqof1nqsaMwstyy1Ks=; b=sfwiNr07t6+HkW6wEAPYQkwMX7lbhIXGlU5a2+MeFvHRqVy0AqPixlHjloz1VQ7qnKnZDL yBpveWbatXRhVHBw== Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id C83DA2C165; Wed, 29 Mar 2023 13:55:13 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id 9191C4A0378; Wed, 29 Mar 2023 15:55:13 +0200 (CEST) From: Andreas Schwab To: Laurent Vivier Subject: [PATCH v2] linux-user: preserve incoming order of environment variables in the target CC: qemu-devel@nongnu.org X-Yow: Concentrate on th'cute, li'l CARTOON GUYS! Remember the SERIAL NUMBERS!! Follow the WHIPPLE AVE EXIT!! Have a FREE PEPSI!! Turn LEFT at th'HOLIDAY INN!! JOIN the CREDIT WORLD!! MAKE me an OFFER!!! Date: Wed, 29 Mar 2023 15:55:13 +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=2001:67c:2178:6::1c; 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 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 --- linux-user/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/linux-user/main.c b/linux-user/main.c index 4b18461969..dbfd3ee8f1 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -691,7 +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++) { + continue; + } + while (wrk != environ) { + wrk--; (void) envlist_setenv(envlist, *wrk); }