diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-10-05 12:31:55 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2025-10-05 12:31:55 +0100 |
| commit | f7bcc977c49fe2e72a41e0e26c1f3204b85b5182 (patch) | |
| tree | b07ff7f826cff3213f7847e5b6a8a46aade3f742 /shell | |
| parent | 387d01161a086ae49af0f6522a25744a6623e4de (diff) | |
| download | busybox-w32-f7bcc977c49fe2e72a41e0e26c1f3204b85b5182.tar.gz busybox-w32-f7bcc977c49fe2e72a41e0e26c1f3204b85b5182.tar.bz2 busybox-w32-f7bcc977c49fe2e72a41e0e26c1f3204b85b5182.zip | |
ash: make ctrl-c trap handling closer to upstream
Commit 64c8f5f3d0 (ash: add support for INT trap) didn't follow
upstream behaviour. If a trap is supplied for SIGINT, upstream's
signal handler detects this and doesn't call raise_interrupt().
The busybox-w32 implementation called raise_interrupt() but had it
do nothing.
Modify the code to match upstream's behaviour.
Saves 16-36 bytes.
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index cafa41c23..62320568f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -937,17 +937,10 @@ raise_exception(int e) | |||
| 937 | * are held using the INTOFF macro. (The test for iflag is just | 937 | * are held using the INTOFF macro. (The test for iflag is just |
| 938 | * defensive programming.) | 938 | * defensive programming.) |
| 939 | */ | 939 | */ |
| 940 | static void raise_interrupt(void) IF_NOT_PLATFORM_MINGW32(NORETURN); | 940 | static void raise_interrupt(void) NORETURN; |
| 941 | static void | 941 | static void |
| 942 | raise_interrupt(void) | 942 | raise_interrupt(void) |
| 943 | { | 943 | { |
| 944 | #if ENABLE_PLATFORM_MINGW32 | ||
| 945 | /* Contrary to the comment above on Windows raise_interrupt() is | ||
| 946 | * called when SIGINT is trapped or ignored. We detect this here | ||
| 947 | * and return without doing anything. */ | ||
| 948 | if (trap[SIGINT]) | ||
| 949 | return; | ||
| 950 | #endif | ||
| 951 | pending_int = 0; | 944 | pending_int = 0; |
| 952 | #if !ENABLE_PLATFORM_MINGW32 | 945 | #if !ENABLE_PLATFORM_MINGW32 |
| 953 | /* Signal is not automatically unmasked after it is raised, | 946 | /* Signal is not automatically unmasked after it is raised, |
| @@ -5038,9 +5031,11 @@ static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) | |||
| 5038 | # if ENABLE_FEATURE_EDITING | 5031 | # if ENABLE_FEATURE_EDITING |
| 5039 | bb_got_signal = SIGINT; /* for read_line_input: "we got a signal" */ | 5032 | bb_got_signal = SIGINT; /* for read_line_input: "we got a signal" */ |
| 5040 | # endif | 5033 | # endif |
| 5041 | if (!suppress_int && !(rootshell && iflag)) | 5034 | if (!trap[SIGINT]) { |
| 5042 | raise_interrupt(); | 5035 | if (!suppress_int && !(rootshell && iflag)) |
| 5043 | pending_int = 1; | 5036 | raise_interrupt(); |
| 5037 | pending_int = 1; | ||
| 5038 | } | ||
| 5044 | return TRUE; | 5039 | return TRUE; |
| 5045 | } | 5040 | } |
| 5046 | return FALSE; | 5041 | return FALSE; |
| @@ -12341,7 +12336,6 @@ preadfd(void) | |||
| 12341 | * is SIG_IGNed on startup, it stays SIG_IGNed) | 12336 | * is SIG_IGNed on startup, it stays SIG_IGNed) |
| 12342 | */ | 12337 | */ |
| 12343 | # else | 12338 | # else |
| 12344 | raise_interrupt(); | ||
| 12345 | write(STDOUT_FILENO, "^C\n", 3); | 12339 | write(STDOUT_FILENO, "^C\n", 3); |
| 12346 | # endif | 12340 | # endif |
| 12347 | if (trap[SIGINT]) { | 12341 | if (trap[SIGINT]) { |
| @@ -12354,6 +12348,10 @@ preadfd(void) | |||
| 12354 | buf[1] = '\0'; | 12348 | buf[1] = '\0'; |
| 12355 | return 1; | 12349 | return 1; |
| 12356 | } | 12350 | } |
| 12351 | # if ENABLE_PLATFORM_MINGW32 | ||
| 12352 | else | ||
| 12353 | raise_interrupt(); | ||
| 12354 | # endif | ||
| 12357 | exitstatus = 128 + SIGINT; | 12355 | exitstatus = 128 + SIGINT; |
| 12358 | /* bash behavior on ^C + ignored SIGINT: */ | 12356 | /* bash behavior on ^C + ignored SIGINT: */ |
| 12359 | goto again; | 12357 | goto again; |
