ash: [VAR] Do not poplocalvars prematurely on regular utilities
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 26 Jul 2017 18:00:08 +0000 (20:00 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 26 Jul 2017 18:33:51 +0000 (20:33 +0200)
Upstream commit:

    Date: Thu, 27 May 2010 11:50:19 +0800
    [VAR] Do not poplocalvars prematurely on regular utilities

    The recent cmdenviron removal broke regular utilities by calling
    poplocalvars too early.  This patch fixes that by postponing the
    poplocalvars for regular utilities until they have completed.

    In order to ensure that local still works, it is now a special
    built-in.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c

index f7fc18f0d85e31bb6400fe86e32ef01ff5603b74..3604af4fc81517a070c42886525c87e1777c7ccb 100644 (file)
@@ -9539,7 +9539,7 @@ static const struct builtincmd builtintab[] = {
 #if ENABLE_FEATURE_SH_MATH
        { BUILTIN_NOSPEC        "let"     , letcmd     },
 #endif
-       { BUILTIN_ASSIGN        "local"   , localcmd   },
+       { BUILTIN_SPEC_REG_ASSG "local"   , localcmd   },
 #if ENABLE_ASH_PRINTF
        { BUILTIN_REGULAR       "printf"  , printfcmd  },
 #endif
@@ -9849,9 +9849,11 @@ evalcommand(union node *cmd, int flags)
                /* NOTREACHED */
        } /* default */
        case CMDBUILTIN:
-               poplocalvars(spclbltin > 0 || argc == 0);
-               if (cmd_is_exec && argc > 1)
-                       listsetvar(varlist.list, VEXPORT);
+               if (spclbltin > 0 || argc == 0) {
+                       poplocalvars(1);
+                       if (cmd_is_exec && argc > 1)
+                               listsetvar(varlist.list, VEXPORT);
+               }
 
                /* Tight loop with builtins only:
                 * "while kill -0 $child; do true; done"