diff options
author | Ron Yorston <rmy@pobox.com> | 2023-05-23 10:57:56 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-05-23 10:57:56 +0100 |
commit | 89aa9d783c535670c6aed1d32c8740b7474cca00 (patch) | |
tree | 52a494ad5f8a89fbdb5ad2a6155a62d7d3a6a024 /win32 | |
parent | c2c0cfbeb6f07fa3257a60760d5c8a5382cee6e9 (diff) | |
download | busybox-w32-89aa9d783c535670c6aed1d32c8740b7474cca00.tar.gz busybox-w32-89aa9d783c535670c6aed1d32c8740b7474cca00.tar.bz2 busybox-w32-89aa9d783c535670c6aed1d32c8740b7474cca00.zip |
win32: changes to signal handling
Use an exit code of the form (signal << 24) when a process exits
due to a signal. This replaces the previous use of (signal + 128).
This makes it easier to distinguish exit codes from signals.
Allow kill(2) to handle all defined signals, not just EXIT, TERM
and KILL.
The kill and timeout applets now accept any defined signals.
Convert certain Windows status codes Unix-style signal codes.
In ash:
- Exit as if with SIGINT in raise_interrupt() rather than call
raise(SIGINT). The latter returns an exit code of 3.
- Detect if a child process exits as if with SIGINT. If not and if
the parent is an interactive top-level shell, reset pending_int.
This prevents the parent from seeing an INT if the child hasn't
reported it exited due to INT. (Probably due to it being an
interactive shell.)
Costs 132-136 bytes.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/process.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/win32/process.c b/win32/process.c index 228b0b30e..ebc006d4e 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -705,14 +705,14 @@ static inline int process_architecture_matches_current(HANDLE process) | |||
705 | * http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547 | 705 | * http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547 |
706 | * | 706 | * |
707 | */ | 707 | */ |
708 | int kill_SIGTERM_by_handle(HANDLE process) | 708 | int kill_signal_by_handle(HANDLE process, int sig) |
709 | { | 709 | { |
710 | DWORD code; | 710 | DWORD code; |
711 | int ret = 0; | 711 | int ret = 0; |
712 | 712 | ||
713 | if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) { | 713 | if (GetExitCodeProcess(process, &code) && code == STILL_ACTIVE) { |
714 | DECLARE_PROC_ADDR(DWORD, ExitProcess, LPVOID); | 714 | DECLARE_PROC_ADDR(DWORD, ExitProcess, LPVOID); |
715 | PVOID arg = (PVOID)(intptr_t)(128 + SIGTERM); | 715 | PVOID arg = (PVOID)(intptr_t)(sig << 24); |
716 | DWORD thread_id; | 716 | DWORD thread_id; |
717 | HANDLE thread; | 717 | HANDLE thread; |
718 | 718 | ||
@@ -734,7 +734,7 @@ int kill_SIGTERM_by_handle(HANDLE process) | |||
734 | return ret; | 734 | return ret; |
735 | } | 735 | } |
736 | 736 | ||
737 | static int kill_SIGTERM(pid_t pid, int sig UNUSED_PARAM) | 737 | static int kill_signal(pid_t pid, int sig) |
738 | { | 738 | { |
739 | HANDLE process; | 739 | HANDLE process; |
740 | 740 | ||
@@ -745,7 +745,7 @@ static int kill_SIGTERM(pid_t pid, int sig UNUSED_PARAM) | |||
745 | return -1; | 745 | return -1; |
746 | } | 746 | } |
747 | 747 | ||
748 | return kill_SIGTERM_by_handle(process); | 748 | return kill_signal_by_handle(process, sig); |
749 | } | 749 | } |
750 | 750 | ||
751 | /* | 751 | /* |
@@ -765,18 +765,23 @@ static int kill_SIGKILL(pid_t pid, int sig) | |||
765 | } | 765 | } |
766 | 766 | ||
767 | if (sig == SIGKILL) | 767 | if (sig == SIGKILL) |
768 | ret = !TerminateProcess(process, 128 + SIGKILL); | 768 | ret = !TerminateProcess(process, SIGKILL << 24); |
769 | CloseHandle(process); | 769 | CloseHandle(process); |
770 | 770 | ||
771 | return ret; | 771 | return ret; |
772 | } | 772 | } |
773 | 773 | ||
774 | int FAST_FUNC is_valid_signal(int number) | ||
775 | { | ||
776 | return isalpha(*get_signame(number)); | ||
777 | } | ||
778 | |||
774 | int kill(pid_t pid, int sig) | 779 | int kill(pid_t pid, int sig) |
775 | { | 780 | { |
776 | if (sig == SIGTERM) | 781 | if (sig == SIGKILL || sig == 0) |
777 | return kill_pids(pid, sig, kill_SIGTERM); | ||
778 | else if (sig == SIGKILL || sig == 0) | ||
779 | return kill_pids(pid, sig, kill_SIGKILL); | 782 | return kill_pids(pid, sig, kill_SIGKILL); |
783 | else if (is_valid_signal(sig)) | ||
784 | return kill_pids(pid, sig, kill_signal); | ||
780 | 785 | ||
781 | errno = EINVAL; | 786 | errno = EINVAL; |
782 | return -1; | 787 | return -1; |