diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-23 23:44:55 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-23 23:44:55 +0100 |
commit | 521220ed1aa63e53e2f30042ae8f00f683e2254d (patch) | |
tree | b3e8e0925b2826dfad4b47e93f022cd192308742 | |
parent | 18bcaf374cc8eb7bb1db22a1163dc7d38ee6c7c0 (diff) | |
download | busybox-w32-521220ed1aa63e53e2f30042ae8f00f683e2254d.tar.gz busybox-w32-521220ed1aa63e53e2f30042ae8f00f683e2254d.tar.bz2 busybox-w32-521220ed1aa63e53e2f30042ae8f00f683e2254d.zip |
hush: fix ^C in INTERACTIVE, !EDITING config
function old new delta
refill_HFILE_and_getc 88 170 +82
fgetc_interactive 226 250 +24
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 106/0) Total: 106 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/shell/hush.c b/shell/hush.c index e0b519217..d3444c556 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1649,6 +1649,26 @@ static int refill_HFILE_and_getc(HFILE *fp) | |||
1649 | /* Already saw EOF */ | 1649 | /* Already saw EOF */ |
1650 | return EOF; | 1650 | return EOF; |
1651 | } | 1651 | } |
1652 | #if ENABLE_HUSH_INTERACTIVE && !ENABLE_FEATURE_EDITING | ||
1653 | /* If user presses ^C, read() restarts after SIGINT (we use SA_RESTART). | ||
1654 | * IOW: ^C will not immediately stop line input. | ||
1655 | * But poll() is different: it does NOT restart after signals. | ||
1656 | */ | ||
1657 | if (fp == G.HFILE_stdin) { | ||
1658 | struct pollfd pfd[1]; | ||
1659 | pfd[0].fd = fp->fd; | ||
1660 | pfd[0].events = POLLIN; | ||
1661 | n = poll(pfd, 1, -1); | ||
1662 | if (n < 0 | ||
1663 | /*&& errno == EINTR - assumed true */ | ||
1664 | && sigismember(&G.pending_set, SIGINT) | ||
1665 | ) { | ||
1666 | return '\0'; | ||
1667 | } | ||
1668 | } | ||
1669 | #else | ||
1670 | /* if FEATURE_EDITING=y, we do not use this routine for interactive input */ | ||
1671 | #endif | ||
1652 | /* Try to buffer more input */ | 1672 | /* Try to buffer more input */ |
1653 | n = safe_read(fp->fd, fp->buf, sizeof(fp->buf)); | 1673 | n = safe_read(fp->fd, fp->buf, sizeof(fp->buf)); |
1654 | if (n < 0) { | 1674 | if (n < 0) { |
@@ -2090,7 +2110,6 @@ static void hush_exit(int exitcode) | |||
2090 | #endif | 2110 | #endif |
2091 | } | 2111 | } |
2092 | 2112 | ||
2093 | |||
2094 | //TODO: return a mask of ALL handled sigs? | 2113 | //TODO: return a mask of ALL handled sigs? |
2095 | static int check_and_run_traps(void) | 2114 | static int check_and_run_traps(void) |
2096 | { | 2115 | { |
@@ -2665,19 +2684,23 @@ static int get_user_input(struct in_str *i) | |||
2665 | */ | 2684 | */ |
2666 | check_and_run_traps(); | 2685 | check_and_run_traps(); |
2667 | fputs(prompt_str, stdout); | 2686 | fputs(prompt_str, stdout); |
2687 | fflush_all(); | ||
2668 | } | 2688 | } |
2669 | fflush_all(); | ||
2670 | //FIXME: here ^C or SIGINT will have effect only after <Enter> | ||
2671 | r = hfgetc(i->file); | 2689 | r = hfgetc(i->file); |
2672 | /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, | 2690 | /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, |
2673 | * no ^C masking happens during fgetc, no special code for ^C: | 2691 | * no ^C masking happens during fgetc, no special code for ^C: |
2674 | * it generates SIGINT as usual. | 2692 | * it generates SIGINT as usual. |
2675 | */ | 2693 | */ |
2676 | check_and_run_traps(); | 2694 | check_and_run_traps(); |
2677 | if (G.flag_SIGINT) | 2695 | if (r != '\0' && !G.flag_SIGINT) |
2678 | G.last_exitcode = 128 | SIGINT; | ||
2679 | if (r != '\0') | ||
2680 | break; | 2696 | break; |
2697 | if (G.flag_SIGINT) { | ||
2698 | /* ^C or SIGINT: repeat */ | ||
2699 | /* bash prints ^C even on real SIGINT (non-kbd generated) */ | ||
2700 | /* kernel prints "^C" itself, just print newline: */ | ||
2701 | write(STDOUT_FILENO, "\n", 1); | ||
2702 | G.last_exitcode = 128 | SIGINT; | ||
2703 | } | ||
2681 | } | 2704 | } |
2682 | return r; | 2705 | return r; |
2683 | # endif | 2706 | # endif |