diff options
author | Ron Yorston <rmy@pobox.com> | 2021-09-21 12:52:24 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-09-21 13:24:00 +0100 |
commit | df34f5e92b1d10f0bb858d2ea6e8c249e87ac593 (patch) | |
tree | f90208eb2d6f3710833958f67e6101fc2fa85806 | |
parent | 48ddce5e9a063d89689ffe4be1680767186e13ee (diff) | |
download | busybox-w32-df34f5e92b1d10f0bb858d2ea6e8c249e87ac593.tar.gz busybox-w32-df34f5e92b1d10f0bb858d2ea6e8c249e87ac593.tar.bz2 busybox-w32-df34f5e92b1d10f0bb858d2ea6e8c249e87ac593.zip |
ash: improve signal handling
Allow waitpid() to detect SIGTERM/SIGKILL by checking the (Windows)
status returned by GetExitCodeProcess() and updating the Unix
status to suit. This allows ash to detect when a process has been
'signalled'.
Provide our own implementation of strsignal(3) which returns
expanded text for SIGTERM/SIGKILL.
Costs 192 bytes.
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | include/platform.h | 1 | ||||
-rw-r--r-- | shell/ash.c | 2 | ||||
-rw-r--r-- | win32/mingw.c | 9 |
4 files changed, 12 insertions, 1 deletions
diff --git a/include/mingw.h b/include/mingw.h index d48ad3814..74a65116c 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -210,6 +210,7 @@ int unsetenv(const char *env); | |||
210 | */ | 210 | */ |
211 | char *strndup(char const *s, size_t n); | 211 | char *strndup(char const *s, size_t n); |
212 | char *mingw_strerror(int errnum); | 212 | char *mingw_strerror(int errnum); |
213 | char *strsignal(int sig); | ||
213 | 214 | ||
214 | #define strerror mingw_strerror | 215 | #define strerror mingw_strerror |
215 | 216 | ||
diff --git a/include/platform.h b/include/platform.h index 37e48dcc5..7bb39fd93 100644 --- a/include/platform.h +++ b/include/platform.h | |||
@@ -473,7 +473,6 @@ typedef unsigned smalluint; | |||
473 | # undef HAVE_STRCASESTR | 473 | # undef HAVE_STRCASESTR |
474 | # undef HAVE_STRCHRNUL | 474 | # undef HAVE_STRCHRNUL |
475 | # undef HAVE_STRSEP | 475 | # undef HAVE_STRSEP |
476 | # undef HAVE_STRSIGNAL | ||
477 | # undef HAVE_STRVERSCMP | 476 | # undef HAVE_STRVERSCMP |
478 | #if !defined(__MINGW64_VERSION_MAJOR) | 477 | #if !defined(__MINGW64_VERSION_MAJOR) |
479 | # undef HAVE_VASPRINTF | 478 | # undef HAVE_VASPRINTF |
diff --git a/shell/ash.c b/shell/ash.c index f91cd7e1f..613bb97a0 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4835,6 +4835,8 @@ waitpid_child(int *status, int wait_flags) | |||
4835 | if (idx < pid_nr) { | 4835 | if (idx < pid_nr) { |
4836 | GetExitCodeProcess(proclist[idx], &win_status); | 4836 | GetExitCodeProcess(proclist[idx], &win_status); |
4837 | *status = (int)win_status << 8; | 4837 | *status = (int)win_status << 8; |
4838 | if (win_status == 128 + SIGTERM || win_status == 128 + SIGKILL) | ||
4839 | *status += win_status - 128; | ||
4838 | pid = pidlist[idx]; | 4840 | pid = pidlist[idx]; |
4839 | } | 4841 | } |
4840 | done: | 4842 | done: |
diff --git a/win32/mingw.c b/win32/mingw.c index 40714296f..b8dd6a511 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -171,6 +171,15 @@ char *mingw_strerror(int errnum) | |||
171 | return strerror(errnum); | 171 | return strerror(errnum); |
172 | } | 172 | } |
173 | 173 | ||
174 | char *strsignal(int sig) | ||
175 | { | ||
176 | if (sig == SIGTERM) | ||
177 | return (char *)"Terminated"; | ||
178 | else if (sig == SIGKILL) | ||
179 | return (char *)"Killed"; | ||
180 | return (char *)get_signame(sig); | ||
181 | } | ||
182 | |||
174 | static int zero_fd = -1; | 183 | static int zero_fd = -1; |
175 | static int rand_fd = -1; | 184 | static int rand_fd = -1; |
176 | 185 | ||