hush: allocate line edit buffer only for interactive shell

function                                             old     new   delta
builtin_history                                       16      20      +4

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-05-19 18:24:52 +02:00
parent 9edd268bad
commit 76a4e8361a

View File

@ -2032,6 +2032,7 @@ static sighandler_t pick_sighandler(unsigned sig)
static void hush_exit(int exitcode) static void hush_exit(int exitcode)
{ {
#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
if (G.line_input_state)
save_history(G.line_input_state); save_history(G.line_input_state);
#endif #endif
@ -6412,6 +6413,8 @@ static NOINLINE int expand_one_var(o_string *output, int n,
* commands read but are not executed, * commands read but are not executed,
* so $- can not execute too, 'n' is never seen in $-. * so $- can not execute too, 'n' is never seen in $-.
*/ */
//TODO: show 'c' if executed via "hush -c 'CMDS'" (bash only, not ash)
//TODO: show 's' if executed via "hush -s ARG1 ARG2", or if there were no args except options (ash does this too)
*cp = '\0'; *cp = '\0';
break; break;
} }
@ -9955,9 +9958,6 @@ int hush_main(int argc, char **argv)
* PS4='+ ' * PS4='+ '
*/ */
#if ENABLE_FEATURE_EDITING
G.line_input_state = new_line_input_t(FOR_SHELL);
#endif
/* Initialize some more globals to non-zero values */ /* Initialize some more globals to non-zero values */
die_func = restore_ttypgrp_and__exit; die_func = restore_ttypgrp_and__exit;
@ -10245,6 +10245,9 @@ int hush_main(int argc, char **argv)
} }
enable_restore_tty_pgrp_on_exit(); enable_restore_tty_pgrp_on_exit();
# if ENABLE_FEATURE_EDITING
G.line_input_state = new_line_input_t(FOR_SHELL);
# endif
# if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0
{ {
const char *hp = get_local_var_value("HISTFILE"); const char *hp = get_local_var_value("HISTFILE");
@ -10372,6 +10375,7 @@ static int FAST_FUNC builtin_help(char **argv UNUSED_PARAM)
#if MAX_HISTORY && ENABLE_FEATURE_EDITING #if MAX_HISTORY && ENABLE_FEATURE_EDITING
static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM) static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM)
{ {
if (G.line_input_state)
show_history(G.line_input_state); show_history(G.line_input_state);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }