diff options
author | Ron Yorston <rmy@pobox.com> | 2023-09-14 08:09:14 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-09-14 08:09:14 +0100 |
commit | 0475b7a649209487269e35cbe49662a33524e6ae (patch) | |
tree | 531237e1d8716e7c94fdcd0b2966e2e0cbfc0255 /shell/ash.c | |
parent | e3d50157ce21f990c33afdcf8dba8080308ce0f0 (diff) | |
download | busybox-w32-0475b7a649209487269e35cbe49662a33524e6ae.tar.gz busybox-w32-0475b7a649209487269e35cbe49662a33524e6ae.tar.bz2 busybox-w32-0475b7a649209487269e35cbe49662a33524e6ae.zip |
win32: convert exit codes
Add two utility functions to convert Windows process exit codes.
- exit_code_to_wait_status() converts to a POSIX wait status.
This is used in ash and the implementations of system(3) and
mingw_wait3().
- exit_code_to_posix() converts to a POSIX exit code. (Not that
POSIX has much to say about them.)
As a result it's possible for more applets to report when child
processes are killed as if by a signal. 'time', 'drop' and 'su -W',
for example.
Adds 64-80 bytes.
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/shell/ash.c b/shell/ash.c index dcc73031f..f0480f723 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -4960,7 +4960,7 @@ waitpid_child(int *status, int wait_flags) | |||
4960 | HANDLE *proclist; | 4960 | HANDLE *proclist; |
4961 | pid_t pid = -1; | 4961 | pid_t pid = -1; |
4962 | DWORD win_status, idx; | 4962 | DWORD win_status, idx; |
4963 | int i, sig; | 4963 | int i; |
4964 | 4964 | ||
4965 | for (jb = curjob; jb; jb = jb->prev_job) { | 4965 | for (jb = curjob; jb; jb = jb->prev_job) { |
4966 | if (jb->state != JOBDONE) | 4966 | if (jb->state != JOBDONE) |
@@ -4992,18 +4992,7 @@ waitpid_child(int *status, int wait_flags) | |||
4992 | wait_flags&WNOHANG ? 1 : INFINITE); | 4992 | wait_flags&WNOHANG ? 1 : INFINITE); |
4993 | if (idx < pid_nr) { | 4993 | if (idx < pid_nr) { |
4994 | GetExitCodeProcess(proclist[idx], &win_status); | 4994 | GetExitCodeProcess(proclist[idx], &win_status); |
4995 | if (win_status == 0xc0000005) | 4995 | *status = exit_code_to_wait_status(win_status); |
4996 | win_status = SIGSEGV << 24; | ||
4997 | else if (win_status == 0xc000013a) | ||
4998 | win_status = SIGINT << 24; | ||
4999 | |||
5000 | // When a process is terminated as if by a signal the exit | ||
5001 | // code is zero apart from the signal in its topmost byte. | ||
5002 | sig = win_status >> 24; | ||
5003 | if (sig != 0 && win_status == sig << 24 && is_valid_signal(sig)) | ||
5004 | *status = sig; | ||
5005 | else | ||
5006 | *status = (int)win_status << 8; | ||
5007 | pid = pidlist[idx]; | 4996 | pid = pidlist[idx]; |
5008 | } | 4997 | } |
5009 | done: | 4998 | done: |