From 3a372c75fb3af1a8eb4add73f2cd21f3ea1179dc Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Thu, 8 Dec 2011 20:12:00 -0500 Subject: [PATCH] commit bash-20090702 snapshot --- CWRU/CWRU.chlog | 27 +++++++++++++++++++++++++++ builtins/command.def | 41 +++++++++++++++++++++++------------------ builtins/read.def | 5 ++++- variables.c | 26 ++++++++++++++++++++++++-- 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 4ed24ffb8..9b75bc0f8 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -8170,3 +8170,30 @@ lib/sh/getcwd.c configure.in - add -D_ALL_SOURCE to interix CFLAGS for struct timezone definition. Bug and fix from John Gatewood Ham + + 6/29 + ---- +variables.c + - change initialize_shell_variables to add environment variables with + invalid names to the variables hash table, but marking them as + invisible and imported + - new function, export_environment_candidate. Used when creating the + export environment for commands to include variables with invalid + names inherited from the initial environment. Apparently this + behavior is widespread + - change make_var_export_array to use export_environment_candidate + rather than visible_and_exported to test variables for inclusion + in the export environment + + 7/1 + --- +builtins/read.def + - fix a memory leak where the number of fields is not the same as + the number of variables passed to `read'. Bug report from + werner@suse.de + +builtins/command.def + - move section of code that sets PATH from -p option before the + verbose-handling section, so command -v and command -V honor + the PATH set by command -p. Bug and fix from + ohki@gssm.otsuka.tsukuba.ac.jp diff --git a/builtins/command.def b/builtins/command.def index 77f91268b..184527994 100644 --- a/builtins/command.def +++ b/builtins/command.def @@ -100,22 +100,6 @@ command_builtin (list) if (list == 0) return (EXECUTION_SUCCESS); - if (verbose) - { - int found, any_found; - - for (any_found = 0; list; list = list->next) - { - found = describe_command (list->word->word, verbose); - - if (found == 0 && verbose != CDESC_REUSABLE) - sh_notfound (list->word->word); - - any_found += found; - } - return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE); - } - #if defined (RESTRICTED_SHELL) if (use_standard_path && restricted) { @@ -126,8 +110,6 @@ command_builtin (list) begin_unwind_frame ("command_builtin"); - /* We don't want this to be reparsed (consider command echo 'foo &'), so - just make a simple_command structure and call execute_command with it. */ if (use_standard_path) { old_path = get_string_value ("PATH"); @@ -139,11 +121,32 @@ command_builtin (list) standard_path = get_standard_path (); bind_variable ("PATH", standard_path ? standard_path : "", 0); + stupidly_hack_special_variables ("PATH"); FREE (standard_path); } + if (verbose) + { + int found, any_found; + + for (any_found = 0; list; list = list->next) + { + found = describe_command (list->word->word, verbose); + + if (found == 0 && verbose != CDESC_REUSABLE) + sh_notfound (list->word->word); + + any_found += found; + } + + run_unwind_frame ("command_builtin"); + return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE); + } + #define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN) + /* We don't want this to be reparsed (consider command echo 'foo &'), so + just make a simple_command structure and call execute_command with it. */ command = make_bare_simple_command (); command->value.Simple->words = (WORD_LIST *)copy_word_list (list); command->value.Simple->redirects = (REDIRECT *)NULL; @@ -182,6 +185,8 @@ restore_path (var) } else unbind_variable ("PATH"); + + stupidly_hack_special_variables ("PATH"); } /* Return a value for PATH that is guaranteed to find all of the standard diff --git a/builtins/read.def b/builtins/read.def index ce486569d..75fd2371a 100644 --- a/builtins/read.def +++ b/builtins/read.def @@ -763,7 +763,10 @@ assign_vars: if (*input_string == 0) tofree = input_string = t; else - input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape); + { + input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape); + tofree = t; + } } #endif diff --git a/variables.c b/variables.c index 263934b51..e0179df10 100644 --- a/variables.c +++ b/variables.c @@ -254,6 +254,7 @@ static SHELL_VAR **fapply __P((sh_var_map_func_t *)); static int visible_var __P((SHELL_VAR *)); static int visible_and_exported __P((SHELL_VAR *)); +static int export_environment_candidate __P((SHELL_VAR *)); static int local_and_exported __P((SHELL_VAR *)); static int variable_in_context __P((SHELL_VAR *)); #if defined (ARRAY_VARS) @@ -377,10 +378,17 @@ initialize_shell_variables (env, privmode) } # endif #endif +#if 0 else if (legal_identifier (name)) +#else + else +#endif { temp_var = bind_variable (name, string, 0); - VSETATTR (temp_var, (att_exported | att_imported)); + if (legal_identifier (name)) + VSETATTR (temp_var, (att_exported | att_imported)); + else + VSETATTR (temp_var, (att_exported | att_imported | att_invisible)); array_needs_making = 1; } @@ -3089,6 +3097,16 @@ visible_and_exported (var) return (invisible_p (var) == 0 && exported_p (var)); } +/* Candidate variables for the export environment are either valid variables + with the export attribute or invalid variables inherited from the initial + environment and simply passed through. */ +static int +export_environment_candidate (var) + SHELL_VAR *var; +{ + return (exported_p (var) && (invisible_p (var) == 0 || imported_p (var))); +} + /* Return non-zero if VAR is a local variable in the current context and is exported. */ static int @@ -3445,7 +3463,11 @@ make_var_export_array (vcxt) char **list; SHELL_VAR **vars; +#if 0 vars = map_over (visible_and_exported, vcxt); +#else + vars = map_over (export_environment_candidate, vcxt); +#endif if (vars == 0) return (char **)NULL; @@ -3594,7 +3616,7 @@ maybe_make_export_env () } export_env[export_env_index = 0] = (char *)NULL; - /* Make a dummy variable context from the temporary_env, stick it on + /* Make a dummy variable context from the temporary_env, stick it on the front of shell_variables, call make_var_export_array on the whole thing to flatten it, and convert the list of SHELL_VAR *s to the form needed by the environment. */ -- 2.47.3