diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c index c2c1f2098..ddac42895 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2371,7 +2371,7 @@ static const struct { | |||
2371 | { VSTRFIXED|VTEXTFIXED|VUNSET, "HISTFILE" , NULL }, | 2371 | { VSTRFIXED|VTEXTFIXED|VUNSET, "HISTFILE" , NULL }, |
2372 | #endif | 2372 | #endif |
2373 | #if ENABLE_PLATFORM_MINGW32 | 2373 | #if ENABLE_PLATFORM_MINGW32 |
2374 | { VSTRFIXED|VTEXTFIXED|VUNSET, bb_skip_ansi_emulation, change_skip_ansi }, | 2374 | { VSTRFIXED|VTEXTFIXED|VUNSET, BB_SKIP_ANSI_EMULATION, change_skip_ansi }, |
2375 | #endif | 2375 | #endif |
2376 | }; | 2376 | }; |
2377 | 2377 | ||
@@ -2652,6 +2652,29 @@ fix_pathvar(const char *path, int len) | |||
2652 | } | 2652 | } |
2653 | return newpath; | 2653 | return newpath; |
2654 | } | 2654 | } |
2655 | |||
2656 | #define BB_VAR_EXACT 1 /* exact match for name */ | ||
2657 | #define BB_VAR_ASSIGN 2 /* matches name followed by '=' */ | ||
2658 | |||
2659 | /* Match variables that should be placed in the environment immediately | ||
2660 | * they're exported and removed immediately they're no longer exported */ | ||
2661 | static int | ||
2662 | is_bb_var(const char *s) | ||
2663 | { | ||
2664 | const char *p; | ||
2665 | int len; | ||
2666 | |||
2667 | for (p = bbvar; *p; p += len + 1) { | ||
2668 | len = strlen(p); | ||
2669 | if (strncmp(s, p, len) == 0) { | ||
2670 | if (s[len] == '\0') | ||
2671 | return BB_VAR_EXACT; | ||
2672 | else if (s[len] == '=') | ||
2673 | return BB_VAR_ASSIGN; | ||
2674 | } | ||
2675 | } | ||
2676 | return FALSE; | ||
2677 | } | ||
2655 | #endif | 2678 | #endif |
2656 | 2679 | ||
2657 | /* | 2680 | /* |
@@ -2711,6 +2734,11 @@ setvareq(char *s, int flags) | |||
2711 | if (!(vp->flags & (VTEXTFIXED|VSTACK))) | 2734 | if (!(vp->flags & (VTEXTFIXED|VSTACK))) |
2712 | free((char*)vp->var_text); | 2735 | free((char*)vp->var_text); |
2713 | 2736 | ||
2737 | #if ENABLE_PLATFORM_MINGW32 | ||
2738 | if ((flags & VUNSET) && (vp->flags & VEXPORT) && | ||
2739 | is_bb_var(s) == BB_VAR_EXACT) | ||
2740 | unsetenv(s); | ||
2741 | #endif | ||
2714 | if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) | (vp->flags & VSTRFIXED)) == VUNSET) { | 2742 | if (((flags & (VEXPORT|VREADONLY|VSTRFIXED|VUNSET)) | (vp->flags & VSTRFIXED)) == VUNSET) { |
2715 | *vpp = vp->next; | 2743 | *vpp = vp->next; |
2716 | free(vp); | 2744 | free(vp); |
@@ -2740,6 +2768,10 @@ setvareq(char *s, int flags) | |||
2740 | s = ckstrdup(s); | 2768 | s = ckstrdup(s); |
2741 | vp->var_text = s; | 2769 | vp->var_text = s; |
2742 | vp->flags = flags; | 2770 | vp->flags = flags; |
2771 | #if ENABLE_PLATFORM_MINGW32 | ||
2772 | if ((flags & VEXPORT) && is_bb_var(s) == BB_VAR_ASSIGN) | ||
2773 | putenv(s); | ||
2774 | #endif | ||
2743 | 2775 | ||
2744 | out: | 2776 | out: |
2745 | return vp; | 2777 | return vp; |
@@ -15028,6 +15060,14 @@ exportcmd(int argc UNUSED_PARAM, char **argv) | |||
15028 | } else { | 15060 | } else { |
15029 | vp = *findvar(hashvar(name), name); | 15061 | vp = *findvar(hashvar(name), name); |
15030 | if (vp) { | 15062 | if (vp) { |
15063 | #if ENABLE_PLATFORM_MINGW32 | ||
15064 | if (is_bb_var(name) == BB_VAR_EXACT) { | ||
15065 | if (flag_off == ~VEXPORT) | ||
15066 | unsetenv(name); | ||
15067 | else if (flag == VEXPORT && !(vp->flags & VUNSET)) | ||
15068 | putenv(vp->var_text); | ||
15069 | } | ||
15070 | #endif | ||
15031 | vp->flags = ((vp->flags | flag) & flag_off); | 15071 | vp->flags = ((vp->flags | flag) & flag_off); |
15032 | continue; | 15072 | continue; |
15033 | } | 15073 | } |