From 4840ae8a06298e987374fa3cc6d7e4969fd19344 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 4 Sep 2011 15:28:03 +0200 Subject: lineedit: fix atomic replace of history file; hush: fix $HISTFILE handling Signed-off-by: Denys Vlasenko --- shell/ash.c | 2 +- shell/hush.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'shell') diff --git a/shell/ash.c b/shell/ash.c index d48cd016f..bf376bd0d 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13194,7 +13194,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) } if (sflag || minusc == NULL) { -#if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY +#if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY if (iflag) { const char *hp = lookupvar("HISTFILE"); if (hp) diff --git a/shell/hush.c b/shell/hush.c index e4138adf7..42143fd9e 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -7816,23 +7816,7 @@ int hush_main(int argc, char **argv) */ #if ENABLE_FEATURE_EDITING - G.line_input_state = new_line_input_t(FOR_SHELL); -# if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY - { - const char *hp = get_local_var_value("HISTFILE"); - if (!hp) { - hp = get_local_var_value("HOME"); - if (hp) { - G.line_input_state->hist_file = concat_path_file(hp, ".hush_history"); - //set_local_var(xasprintf("HISTFILE=%s", ...)); - } - } -# if ENABLE_FEATURE_SH_HISTFILESIZE - hp = get_local_var_value("HISTFILESIZE"); - G.line_input_state->max_history = size_from_HISTFILESIZE(hp); -# endif - } -# endif + G.line_input_state = new_line_input_t(FOR_SHELL & ~SAVE_HISTORY); #endif /* Initialize some more globals to non-zero values */ @@ -8104,6 +8088,28 @@ int hush_main(int argc, char **argv) /* -1 is special - makes xfuncs longjmp, not exit * (we reset die_sleep = 0 whereever we [v]fork) */ enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */ + +# if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 + { + const char *hp = get_local_var_value("HISTFILE"); + if (!hp) { + hp = get_local_var_value("HOME"); + if (hp) + hp = concat_path_file(hp, ".hush_history"); + } else { + hp = xstrdup(hp); + } + if (hp) { + G.line_input_state->hist_file = hp; + G.line_input_state->flags |= SAVE_HISTORY; + //set_local_var(xasprintf("HISTFILE=%s", ...)); + } +# if ENABLE_FEATURE_SH_HISTFILESIZE + hp = get_local_var_value("HISTFILESIZE"); + G.line_input_state->max_history = size_from_HISTFILESIZE(hp); +# endif + } +# endif } else { install_special_sighandlers(); } -- cgit v1.2.3