Hi,

Environment variables don't get set for sub-applications when ash is
built in standalone mode.

For example, build ls colors in as default, start up busybox ash and
run

$ export LS_COLORS=none
$ ls

and you can see the colors still come out (we found the issue with
TZ).

The problem is that the sub-application is calling getenv(), but the
variable has never been set in the shell environment.

Suggested patch below.  This doesn't fix the 'LS_COLORS=none ls' case,
but makes 'export' work as expected.

-i

Index: shell/ash.c
===================================================================
--- shell/ash.c (revision 23678)
+++ shell/ash.c (working copy)
@@ -12103,6 +12103,20 @@
                        do {
                                p = strchr(name, '=');
                                if (p != NULL) {
+#if ENABLE_FEATURE_SH_STANDALONE
+                                       /* If in standalone mode we
+                                        * need to make sure that
+                                        * sub-applications that call
+                                        * getenv() see this variable
+                                        * as being set, as they are
+                                        * executed right in our
+                                        * process. */
+                                       char *evar = xasprintf("%s", name);
+                                       char *eval = &evar[p - name + 1];
+                                       evar[p - name] = '\0';
+                                       setenv(evar, eval, 1);
+                                       free(evar);
+#endif
                                        p++;
                                } else {
                                        vp = *findvar(hashvar(name), name);
@@ -12152,6 +12166,11 @@
 
        for (ap = argptr; *ap; ap++) {
                if (flag != 'f') {
+#if ENABLE_FEATURE_SH_STANDALONE
+                       /* Make sure this no longer appears if
+                        * sub-apps do getenv() */
+                       unsetenv(*ap);
+#endif
                        i = unsetvar(*ap);
                        ret |= i;
                        if (!(i & 2))
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to