[PATCH v2 07/14] mingw: add kill emulation
- From
Erik Faye-Lund <kusmabite@googlemail.com>
- Date
- Jan 15, 2010, 21:30 UTC
- Message-ID
- <1263591033-4992-8-git-send-email-kusmabite@gmail.com>
- In-Reply-To
- <1263591033-4992-1-git-send-email-kusmabite@gmail.com>
This is a quite limited kill-emulation; it can only handle SIGTERM on positive pids. However, it's enough for git-daemon.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> --- compat/mingw.c | 19 +++++++++++++++++++ compat/mingw.h | 3 +++ 2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c index ce4f829..89b9b89 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -829,6 +829,25 @@ void mingw_execvp(const char *cmd, char *const *argv) free_path_split(path); } +int mingw_kill(pid_t pid, int sig) +{ + if (pid > 0 && sig == SIGTERM) { + HANDLE h = OpenProcess(PROCESS_TERMINATE, FALSE, pid); + + if (TerminateProcess(h, -1)) { + CloseHandle(h); + return 0; + } + + CloseHandle(h); + errno = err_win_to_posix(GetLastError()); + return -1; + } + + errno = EINVAL; + return -1; +} + static char **copy_environ(void) { char **env; diff --git a/compat/mingw.h b/compat/mingw.h index ff4a76b..e72c2ee 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -176,6 +176,9 @@ static inline int waitpid(pid_t pid, int *status, unsigned options) return -1; } +#define kill mingw_kill +int mingw_kill(pid_t pid, int sig); + #ifndef NO_OPENSSL #include <openssl/ssl.h> static inline int mingw_SSL_set_fd(SSL *ssl, int fd)
-- 1.6.6.211.g26720