From cf5110978ba25002ec5cb46aaae2472eb66001ac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 18 Jul 2017 15:58:02 +0200 Subject: [PATCH] hush: fix readonly2.tests failure Signed-off-by: Denys Vlasenko --- shell/hush.c | 11 +++++++++++ shell/hush_test/hush-vars/readonly2.right | 1 + shell/hush_test/hush-vars/readonly2.tests | 1 + 3 files changed, 13 insertions(+) diff --git a/shell/hush.c b/shell/hush.c index 55e581e16..f6da826d3 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -2287,7 +2287,18 @@ static struct variable *set_vars_and_save_old(char **strings) if (var_pp) { var_p = *var_pp; if (var_p->flg_read_only) { + char **p; bb_error_msg("%s: readonly variable", *s); + /* + * "VAR=V BLTIN" unsets VARs after BLTIN completes. + * If VAR is readonly, leaving it in the list + * after asssignment error (msg above) + * causes doubled error message later, on unset. + */ + debug_printf_env("removing/freeing '%s' element\n", *s); + free(*s); + p = s; + do { *p = p[1]; p++; } while (*p); goto next; } /* Remove variable from global linked list */ diff --git a/shell/hush_test/hush-vars/readonly2.right b/shell/hush_test/hush-vars/readonly2.right index 5b02ddfe8..38551d4ad 100644 --- a/shell/hush_test/hush-vars/readonly2.right +++ b/shell/hush_test/hush-vars/readonly2.right @@ -1,4 +1,5 @@ hush: a=Z: readonly variable Visible:42 + hush: a=Z: readonly variable Visible:42 diff --git a/shell/hush_test/hush-vars/readonly2.tests b/shell/hush_test/hush-vars/readonly2.tests index d9d178edd..b758d9602 100755 --- a/shell/hush_test/hush-vars/readonly2.tests +++ b/shell/hush_test/hush-vars/readonly2.tests @@ -3,4 +3,5 @@ readonly a=A # external commands and builtins should behave the same: (exit 42); a=Z echo "Visible:$?" +echo (exit 42); a=Z env echo "Visible:$?" -- 2.25.1