Skip to contentSkip to conversation

linux-user: preserve incoming order of environment variables in the target

PATCH Superseded Andreas Schwab 4 participants 7 messages Mar 29, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 linux-user: preserve incoming order of environment variables in the target

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.

---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/main.c +6 -0
index 4b18461969..dbfd3ee8f1 100644
@@ -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);
     }
 
Signature · 7 lines
2.40.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#1 lore raw
Quoted 8 lines · Andreas Schwab

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.

---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Quoted 28 lines
linux-user/main.c +6 -0
index 4b18461969..dbfd3ee8f1 100644
@@ -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);
     }
 
Signature · 7 lines
2.40.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 21 lines · Daniel P. Berrangé
Quoted 8 lines · Andreas Schwab

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.

---
  linux-user/main.c | 6 ++++++
  1 file changed, 6 insertions(+)

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Quoted 8 lines
linux-user/main.c +0 -0
index 4b18461969..dbfd3ee8f1 100644
@@ -691,7 +691,13 @@ int main(int argc, char **argv, char **envp)
      envlist = envlist_create();
 
Quoted 3 lines

linux-user/main.c int main(int argc, char **argv, char **envp) · line 695

Quoted 3 lines
linux-user/main.c +2 -0
      /* add current environment into the list */
+    /* envlist_setenv adds to the front of the list; to preserve environ
+       order add from back to front */

Also, QEMU coding style now requires:

/*
* this comment form.
*/

;)

Quoted 20 lines
Quoted 17 lines
linux-user/main.c +4 -0
      for (wrk = environ; *wrk != NULL; wrk++) {
+        continue;
+    }
+    while (wrk != environ) {
+        wrk--;
          (void) envlist_setenv(envlist, *wrk);
      }
 
Signature · 7 lines
2.40.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

With regards,
Daniel

#3 lore raw
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Daniel P. Berrangé
Quoted 8 lines · Andreas Schwab

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.

---
  linux-user/main.c | 6 ++++++
  1 file changed, 6 insertions(+)

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Quoted 1 line
Quoted 9 lines

linux-user/main.c int main(int argc, char **argv, char **envp) · line 694

Quoted 9 lines
linux-user/main.c +2 -0
index 4b18461969..dbfd3ee8f1 100644
@@ -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 */

Also, QEMU coding style now requires:

Quoted 3 lines

/*
* this comment form.
*/

It's unfortunate that the next comment just below doesn't follow the correct style, so I didn't notice.

Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#4 lore raw
In reply to Daniel P. Berrangé
Quoted 5 lines · Daniel P. Berrangé
Quoted 4 lines · Andreas Schwab

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.

Quoted 7 lines
Quoted 4 lines
---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Yes, but I cannot test it, so I like to let someone else produce the patch.

Signature · 3 lines
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
#5 lore raw
Quoted 12 lines · Andreas Schwab
Quoted 10 lines · Daniel P. Berrangé
Quoted 8 lines · Andreas Schwab

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.

---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 5 lines
Quoted 2 lines

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Yes, but I cannot test it, so I like to let someone else produce the patch.

The code in this case is 100% identical, so I think it is reasonable to expect that patch to cover both of them regardless.

In terms of testing we don't require the contributors to test all platform combinations affected. Our FreeBSD CI jobs will test the build of bsd-user.

If so desired though, any contributor can easily test BSD changes too via our VM infra. eg "make vm-build-freebsd" (see make vm-help for further options)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw
In reply to Daniel P. Berrangé
Quoted 6 lines · Daniel P. Berrangé
Quoted 2 lines · Andreas Schwab

Do not reverse the order of environment variables in the target environ array relative to the incoming environ order. Some testsuites depend on

a

Quoted 2 lines

specific order, even though it is not defined by any standard.

Quoted 8 lines
Quoted 4 lines
---
 linux-user/main.c | 6 ++++++
 1 file changed, 6 insertions(+)

bsd-user/main.c appears to have an identical code pattern that will need the same fix

Agreed. I am finishing up a vacation but was going to check on this... I agree that bsd-user wants to do this too...

Warner

Quoted 41 lines
Quoted 23 lines
linux-user/main.c +6 -1
index 4b18461969..dbfd3ee8f1 100644
@@ -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);
     }
 
--

2.40.0

Quoted 5 lines

--
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."

With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|