From: Marko Kreen Date: Thu, 4 Dec 2008 10:57:38 +0000 (+0000) Subject: win32: implement kill() X-Git-Tag: pgbouncer_1_3_rc1~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e157bea893c9d5afa20af02b26baf566f5eadb99;p=pgbouncer win32: implement kill() Patch by Hiroshi Saito, applied with some modifications. --- diff --git a/win32/compat_win32.h b/win32/compat_win32.h index 382a677..5f2dde7 100644 --- a/win32/compat_win32.h +++ b/win32/compat_win32.h @@ -169,10 +169,38 @@ static inline int getrlimit(int res, struct rlimit *dst) return 0; } -/* kill is only used to detect if process is running, be always successful */ +/* kill is only used to detect if process is running (ESRCH->not) */ static inline int kill(int pid, int sig) { - return (sig == 0) ? 0 : -1; + HANDLE hProcess; + DWORD exitCode; + int ret = 0; + + if (sig != 0) { + errno = EINVAL; + return -1; + } + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); + if (hProcess == NULL) { + if (GetLastError() == ERROR_INVALID_PARAMETER) + ret = ESRCH; + else + ret = EPERM; + } else { + /* OpenProcess may succed for exited processes */ + if (GetExitCodeProcess(hProcess, &exitCode)) { + if (exitCode != STILL_ACTIVE) + ret = ESRCH; + } + CloseHandle(hProcess); + } + + if (ret) { + errno = ret; + return -1; + } else + return 0; } /* sendmsg is not used */