aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-11-29 11:26:45 +0000
committerRon Yorston <rmy@pobox.com>2016-11-29 11:26:45 +0000
commitbb8d79eadbba1942dbdb9f9cee5c47833afe269f (patch)
treeb8c517e9ca895d60d7227aef7177b6291df5e2cd /shell
parent9fa1e4990e655a85025c9d270a1606983e375e47 (diff)
parent7d877fc9312a742b06125927bb1d34bd35398c6c (diff)
downloadbusybox-w32-bb8d79eadbba1942dbdb9f9cee5c47833afe269f.tar.gz
busybox-w32-bb8d79eadbba1942dbdb9f9cee5c47833afe269f.tar.bz2
busybox-w32-bb8d79eadbba1942dbdb9f9cee5c47833afe269f.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c9
-rw-r--r--shell/hush.c39
2 files changed, 36 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c
index d0ccfe982..2e7f68c05 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9724,9 +9724,9 @@ static const struct builtincmd builtintab[] = {
9724 { BUILTIN_SPEC_REG ":" , truecmd }, 9724 { BUILTIN_SPEC_REG ":" , truecmd },
9725#if ENABLE_ASH_BUILTIN_TEST 9725#if ENABLE_ASH_BUILTIN_TEST
9726 { BUILTIN_REGULAR "[" , testcmd }, 9726 { BUILTIN_REGULAR "[" , testcmd },
9727#if ENABLE_ASH_BASH_COMPAT 9727# if ENABLE_ASH_BASH_COMPAT
9728 { BUILTIN_REGULAR "[[" , testcmd }, 9728 { BUILTIN_REGULAR "[[" , testcmd },
9729#endif 9729# endif
9730#endif 9730#endif
9731#if ENABLE_ASH_ALIAS 9731#if ENABLE_ASH_ALIAS
9732 { BUILTIN_REG_ASSG "alias" , aliascmd }, 9732 { BUILTIN_REG_ASSG "alias" , aliascmd },
@@ -10334,13 +10334,16 @@ preadfd(void)
10334 reinit_unicode_for_ash(); 10334 reinit_unicode_for_ash();
10335 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); 10335 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout);
10336 if (nr == 0) { 10336 if (nr == 0) {
10337 /* Ctrl+C pressed */ 10337 /* ^C pressed, "convert" to SIGINT */
10338 write(STDOUT_FILENO, "^C", 2);
10338 if (trap[SIGINT]) { 10339 if (trap[SIGINT]) {
10339 buf[0] = '\n'; 10340 buf[0] = '\n';
10340 buf[1] = '\0'; 10341 buf[1] = '\0';
10341 raise(SIGINT); 10342 raise(SIGINT);
10342 return 1; 10343 return 1;
10343 } 10344 }
10345 exitstatus = 128 + SIGINT;
10346 bb_putchar('\n');
10344 goto retry; 10347 goto retry;
10345 } 10348 }
10346 if (nr < 0) { 10349 if (nr < 0) {
diff --git a/shell/hush.c b/shell/hush.c
index 2f07f4ac1..bcd4dffee 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1746,6 +1746,7 @@ static int check_and_run_traps(void)
1746 argv[2] = NULL; 1746 argv[2] = NULL;
1747 save_rcode = G.last_exitcode; 1747 save_rcode = G.last_exitcode;
1748 builtin_eval(argv); 1748 builtin_eval(argv);
1749//FIXME: shouldn't it be set to 128 + sig instead?
1749 G.last_exitcode = save_rcode; 1750 G.last_exitcode = save_rcode;
1750 last_sig = sig; 1751 last_sig = sig;
1751 } /* else: "" trap, ignoring signal */ 1752 } /* else: "" trap, ignoring signal */
@@ -1755,8 +1756,6 @@ static int check_and_run_traps(void)
1755 switch (sig) { 1756 switch (sig) {
1756 case SIGINT: 1757 case SIGINT:
1757 debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig); 1758 debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig);
1758 /* Builtin was ^C'ed, make it look prettier: */
1759 bb_putchar('\n');
1760 G.flag_SIGINT = 1; 1759 G.flag_SIGINT = 1;
1761 last_sig = sig; 1760 last_sig = sig;
1762 break; 1761 break;
@@ -2192,18 +2191,30 @@ static int get_user_input(struct in_str *i)
2192 2191
2193 prompt_str = setup_prompt_string(i->promptmode); 2192 prompt_str = setup_prompt_string(i->promptmode);
2194# if ENABLE_FEATURE_EDITING 2193# if ENABLE_FEATURE_EDITING
2195 do { 2194 for (;;) {
2196 reinit_unicode_for_hush(); 2195 reinit_unicode_for_hush();
2197 G.flag_SIGINT = 0; 2196 if (G.flag_SIGINT) {
2197 /* There was ^C'ed, make it look prettier: */
2198 bb_putchar('\n');
2199 G.flag_SIGINT = 0;
2200 }
2198 /* buglet: SIGINT will not make new prompt to appear _at once_, 2201 /* buglet: SIGINT will not make new prompt to appear _at once_,
2199 * only after <Enter>. (^C will work) */ 2202 * only after <Enter>. (^C works immediately) */
2200 r = read_line_input(G.line_input_state, prompt_str, 2203 r = read_line_input(G.line_input_state, prompt_str,
2201 G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, 2204 G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1,
2202 /*timeout*/ -1 2205 /*timeout*/ -1
2203 ); 2206 );
2204 /* catch *SIGINT* etc (^C is handled by read_line_input) */ 2207 /* read_line_input intercepts ^C, "convert" it to SIGINT */
2208 if (r == 0) {
2209 write(STDOUT_FILENO, "^C", 2);
2210 raise(SIGINT);
2211 }
2205 check_and_run_traps(); 2212 check_and_run_traps();
2206 } while (r == 0 || G.flag_SIGINT); /* repeat if ^C or SIGINT */ 2213 if (r != 0 && !G.flag_SIGINT)
2214 break;
2215 /* ^C or SIGINT: repeat */
2216 G.last_exitcode = 128 + SIGINT;
2217 }
2207 if (r < 0) { 2218 if (r < 0) {
2208 /* EOF/error detected */ 2219 /* EOF/error detected */
2209 i->p = NULL; 2220 i->p = NULL;
@@ -2213,7 +2224,7 @@ static int get_user_input(struct in_str *i)
2213 i->p = G.user_input_buf; 2224 i->p = G.user_input_buf;
2214 return (unsigned char)*i->p++; 2225 return (unsigned char)*i->p++;
2215# else 2226# else
2216 do { 2227 for (;;) {
2217 G.flag_SIGINT = 0; 2228 G.flag_SIGINT = 0;
2218 if (i->last_char == '\0' || i->last_char == '\n') { 2229 if (i->last_char == '\0' || i->last_char == '\n') {
2219 /* Why check_and_run_traps here? Try this interactively: 2230 /* Why check_and_run_traps here? Try this interactively:
@@ -2225,8 +2236,18 @@ static int get_user_input(struct in_str *i)
2225 fputs(prompt_str, stdout); 2236 fputs(prompt_str, stdout);
2226 } 2237 }
2227 fflush_all(); 2238 fflush_all();
2239//FIXME: here ^C or SIGINT will have effect only after <Enter>
2228 r = fgetc(i->file); 2240 r = fgetc(i->file);
2229 } while (G.flag_SIGINT || r == '\0'); 2241 /* In !ENABLE_FEATURE_EDITING we don't use read_line_input,
2242 * no ^C masking happens during fgetc, no special code for ^C:
2243 * it generates SIGINT as usual.
2244 */
2245 check_and_run_traps();
2246 if (G.flag_SIGINT)
2247 G.last_exitcode = 128 + SIGINT;
2248 if (r != '\0')
2249 break;
2250 }
2230 return r; 2251 return r;
2231# endif 2252# endif
2232} 2253}