aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-24 17:44:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-24 17:44:02 +0100
commit8660aeb3127416a53e0b2e43bb1a82907f468692 (patch)
tree3797b0012e544ff040993b43b31ccb58f6e43a6f
parent2e4ef38743c3d4aef109b5cc04429ec1f0e2f6c8 (diff)
downloadbusybox-w32-8660aeb3127416a53e0b2e43bb1a82907f468692.tar.gz
busybox-w32-8660aeb3127416a53e0b2e43bb1a82907f468692.tar.bz2
busybox-w32-8660aeb3127416a53e0b2e43bb1a82907f468692.zip
ash,hush: ^C from command line should set $? to 128+SIGINT
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c1
-rw-r--r--shell/hush.c26
2 files changed, 22 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 15246f55f..3e5a3b3e9 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -9876,6 +9876,7 @@ preadfd(void)
9876 raise(SIGINT); 9876 raise(SIGINT);
9877 return 1; 9877 return 1;
9878 } 9878 }
9879 exitstatus = 128 + SIGINT;
9879 goto retry; 9880 goto retry;
9880 } 9881 }
9881 if (nr < 0) { 9882 if (nr < 0) {
diff --git a/shell/hush.c b/shell/hush.c
index 2f07f4ac1..5b720ce98 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 */
@@ -2192,7 +2193,7 @@ static int get_user_input(struct in_str *i)
2192 2193
2193 prompt_str = setup_prompt_string(i->promptmode); 2194 prompt_str = setup_prompt_string(i->promptmode);
2194# if ENABLE_FEATURE_EDITING 2195# if ENABLE_FEATURE_EDITING
2195 do { 2196 for (;;) {
2196 reinit_unicode_for_hush(); 2197 reinit_unicode_for_hush();
2197 G.flag_SIGINT = 0; 2198 G.flag_SIGINT = 0;
2198 /* buglet: SIGINT will not make new prompt to appear _at once_, 2199 /* buglet: SIGINT will not make new prompt to appear _at once_,
@@ -2201,9 +2202,15 @@ static int get_user_input(struct in_str *i)
2201 G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, 2202 G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1,
2202 /*timeout*/ -1 2203 /*timeout*/ -1
2203 ); 2204 );
2204 /* catch *SIGINT* etc (^C is handled by read_line_input) */ 2205 /* read_line_input intercepts ^C, "convert" it into SIGINT */
2206 if (r == 0)
2207 raise(SIGINT);
2205 check_and_run_traps(); 2208 check_and_run_traps();
2206 } while (r == 0 || G.flag_SIGINT); /* repeat if ^C or SIGINT */ 2209 if (r != 0 && !G.flag_SIGINT)
2210 break;
2211 /* ^C or SIGINT: repeat */
2212 G.last_exitcode = 128 + SIGINT;
2213 }
2207 if (r < 0) { 2214 if (r < 0) {
2208 /* EOF/error detected */ 2215 /* EOF/error detected */
2209 i->p = NULL; 2216 i->p = NULL;
@@ -2213,7 +2220,7 @@ static int get_user_input(struct in_str *i)
2213 i->p = G.user_input_buf; 2220 i->p = G.user_input_buf;
2214 return (unsigned char)*i->p++; 2221 return (unsigned char)*i->p++;
2215# else 2222# else
2216 do { 2223 for (;;) {
2217 G.flag_SIGINT = 0; 2224 G.flag_SIGINT = 0;
2218 if (i->last_char == '\0' || i->last_char == '\n') { 2225 if (i->last_char == '\0' || i->last_char == '\n') {
2219 /* Why check_and_run_traps here? Try this interactively: 2226 /* Why check_and_run_traps here? Try this interactively:
@@ -2226,7 +2233,16 @@ static int get_user_input(struct in_str *i)
2226 } 2233 }
2227 fflush_all(); 2234 fflush_all();
2228 r = fgetc(i->file); 2235 r = fgetc(i->file);
2229 } while (G.flag_SIGINT || r == '\0'); 2236 /* In !ENABLE_FEATURE_EDITING we don't use read_line_input,
2237 * no ^C masking happens during fgetc, no special code for ^C:
2238 * it generates SIGINT as usual.
2239 */
2240 check_and_run_traps();
2241 if (G.flag_SIGINT)
2242 G.last_exitcode = 128 + SIGINT;
2243 if (r != '\0')
2244 break;
2245 }
2230 return r; 2246 return r;
2231# endif 2247# endif
2232} 2248}