From 7f750efcaa86dad4d0b748f27b82c2c066b5435b Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Wed, 29 Mar 2023 17:00:06 +0200 Subject: linux-user, bsd-user: Preserve incoming order of environment variables in the target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Message-Id: Signed-off-by: Philippe Mathieu-Daudé --- linux-user/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'linux-user/main.c') diff --git a/linux-user/main.c b/linux-user/main.c index 5e6b2e1714..dba67ffa36 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -692,8 +692,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); } -- cgit v1.2.3