aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-12-25 18:49:29 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-12-25 18:49:29 +0100
commit46a71dc30c62dde71d4e6714790b40187d378e82 (patch)
tree9f590104bd48fcdcc28cd74312bae7847d75c55f /shell
parent6cfec7dd0269619add74ff654f724d3c5f89176b (diff)
downloadbusybox-46a71dc30c62dde71d4e6714790b40187d378e82.tar.gz
hush: if !EDITING, do not regenerate prompt for every input char
function old new delta fgetc_interactive 261 258 -3 pseudo_exec_argv 406 399 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index d3444c556..3bdbe26d8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -2640,11 +2640,14 @@ static const char *setup_prompt_string(void)
}
static int get_user_input(struct in_str *i)
{
+# if ENABLE_FEATURE_EDITING
+ /* In EDITING case, this function reads next input line,
+ * saves it in i->p, then returns 1st char of it.
+ */
int r;
const char *prompt_str;
prompt_str = setup_prompt_string();
-# if ENABLE_FEATURE_EDITING
for (;;) {
reinit_unicode_for_hush();
G.flag_SIGINT = 0;
@@ -2674,9 +2677,15 @@ static int get_user_input(struct in_str *i)
i->p = G.user_input_buf;
return (unsigned char)*i->p++;
# else
+ /* In !EDITING case, this function gets called for every char.
+ * Buffering happens deeper in the call chain, in hfgetc(i->file).
+ */
+ int r;
+
for (;;) {
G.flag_SIGINT = 0;
if (i->last_char == '\0' || i->last_char == '\n') {
+ const char *prompt_str = setup_prompt_string();
/* Why check_and_run_traps here? Try this interactively:
* $ trap 'echo INT' INT; (sleep 2; kill -INT $$) &
* $ <[enter], repeatedly...>
@@ -8171,7 +8180,6 @@ static void exec_function(char ***to_free,
/* On MMU, funcp->body is always non-NULL */
n = run_list(funcp->body);
- fflush_all();
_exit(n);
# else
//? close_saved_fds_and_FILE_fds();
@@ -8246,7 +8254,6 @@ static void exec_builtin(char ***to_free,
{
#if BB_MMU
int rcode;
- fflush_all();
//? close_saved_fds_and_FILE_fds();
rcode = x->b_function(argv);
fflush_all();
@@ -10039,8 +10046,8 @@ int hush_main(int argc, char **argv)
#endif
cached_getpid = getpid(); /* for tcsetpgrp() during init */
- G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */
- G.root_ppid = getppid(); /* for $$PPID (NOMMU can override) */
+ G.root_pid = cached_getpid; /* for $PID (NOMMU can override via -$HEXPID:HEXPPID:...) */
+ G.root_ppid = getppid(); /* for $PPID (NOMMU can override) */
/* Deal with HUSH_VERSION */
debug_printf_env("unsetenv '%s'\n", "HUSH_VERSION");