diff options
author | Denys Vlasenko | 2019-05-19 18:24:52 +0200 |
---|---|---|
committer | Denys Vlasenko | 2019-05-19 18:24:52 +0200 |
commit | 76a4e8361a84efca256d4286cf36561c42c14d64 (patch) | |
tree | 9c3b9f82e5d86a08d646d554d3d3800bd1404d79 /shell | |
parent | 9edd268bad93128bcadfbdde28bb978a4b4c5bab (diff) | |
download | busybox-76a4e8361a84efca256d4286cf36561c42c14d64.zip busybox-76a4e8361a84efca256d4286cf36561c42c14d64.tar.gz |
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>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 9dd893a..4dd9402 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -2032,7 +2032,8 @@ static sighandler_t pick_sighandler(unsigned sig) static void hush_exit(int exitcode) { #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT - save_history(G.line_input_state); + if (G.line_input_state) + save_history(G.line_input_state); #endif fflush_all(); @@ -6412,6 +6413,8 @@ static NOINLINE int expand_one_var(o_string *output, int n, * commands read but are not executed, * 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'; break; } @@ -9955,9 +9958,6 @@ int hush_main(int argc, char **argv) * PS4='+ ' */ -#if ENABLE_FEATURE_EDITING - G.line_input_state = new_line_input_t(FOR_SHELL); -#endif /* Initialize some more globals to non-zero values */ die_func = restore_ttypgrp_and__exit; @@ -10245,6 +10245,9 @@ int hush_main(int argc, char **argv) } 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 { const char *hp = get_local_var_value("HISTFILE"); @@ -10372,7 +10375,8 @@ static int FAST_FUNC builtin_help(char **argv UNUSED_PARAM) #if MAX_HISTORY && ENABLE_FEATURE_EDITING static int FAST_FUNC builtin_history(char **argv UNUSED_PARAM) { - show_history(G.line_input_state); + if (G.line_input_state) + show_history(G.line_input_state); return EXIT_SUCCESS; } #endif |