From 85ce92a584b8ca1a5c33828faf66ad304689e71f Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 29 May 2015 14:25:17 +0100 Subject: mingw: tidy up implementation of kill(2) --- include/mingw.h | 2 ++ win32/mingw.c | 2 +- win32/process.c | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index bf8cd0c4c..7224ba50a 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -461,3 +461,5 @@ const char *get_busybox_exec_path(void); void init_winsock(void); char *file_is_win32_executable(const char *p); + +int err_win_to_posix(DWORD winerr); diff --git a/win32/mingw.c b/win32/mingw.c index bb08647a6..4ea18960e 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -24,7 +24,7 @@ unsigned int _CRT_fmode = _O_BINARY; smallint bb_got_signal; -static int err_win_to_posix(DWORD winerr) +int err_win_to_posix(DWORD winerr) { int error = ENOSYS; switch(winerr) { diff --git a/win32/process.c b/win32/process.c index e9db5311e..318515375 100644 --- a/win32/process.c +++ b/win32/process.c @@ -376,15 +376,19 @@ int kill(pid_t pid, int sig) { HANDLE h; - if (sig != SIGTERM) { - bb_error_msg("kill only supports SIGTERM"); - errno = EINVAL; + if (pid > 0 && sig == SIGTERM) { + if ((h=OpenProcess(PROCESS_TERMINATE, FALSE, pid)) != NULL && + TerminateProcess(h, 0)) { + CloseHandle(h); + return 0; + } + + errno = err_win_to_posix(GetLastError()); + if (h != NULL) + CloseHandle(h); return -1; } - h = OpenProcess(PROCESS_TERMINATE, FALSE, pid); - if (h == NULL) - return -1; - if (TerminateProcess(h, 0) == 0) - return -1; - return 0; + + errno = EINVAL; + return -1; } -- cgit v1.2.3-55-g6feb