qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: preserve incoming order of environment variables in the target
@ 2023-03-29 11:04 Andreas Schwab
  2023-03-29 12:19 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2023-03-29 11:04 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: qemu-devel

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 <schwab@suse.de>
---
 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",
-- 
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."


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] linux-user: preserve incoming order of environment variables in the target
  2023-03-29 11:04 [PATCH] linux-user: preserve incoming order of environment variables in the target Andreas Schwab
@ 2023-03-29 12:19 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-03-29 12:19 UTC (permalink / raw)
  To: Andreas Schwab, Laurent Vivier; +Cc: qemu-devel

On 29/3/23 13:04, Andreas Schwab wrote:
> Do not reverse the order of envionment variables in the target environ

"environment"

> 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 <schwab@suse.de>
> ---
>   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);
>       }

Preferably using a dumber form (easier to review IMHO):

         while (wrk != environ) {
            wrk--;
            (void) envlist_setenv(envlist, *wrk);
         }

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-29 12:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-29 11:04 [PATCH] linux-user: preserve incoming order of environment variables in the target Andreas Schwab
2023-03-29 12:19 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).