diff --git a/lib/util.cpp b/lib/util.cpp index 1c8dce9ccb..1d0fe675ad 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -462,13 +462,13 @@ int run_program( #ifdef _WIN32 int kill_program(int pid, int exit_code) { - int retval = -1; + int retval; HANDLE h = OpenProcess(PROCESS_TERMINATE, false, pid); - if (h == NULL && GetLastError() == ERROR_ACCESS_DENIED) return ERR_OPEN; - if (h == NULL && GetLastError() == ERROR_INVALID_PARAMETER) return ERR_INVALID_PARAM; - if (h == NULL && GetLastError() == ERROR_FILE_NOT_FOUND) return ERR_NOT_FOUND; - if (h == NULL) return ERR_IO; + if (h == NULL && GetLastError() == ERROR_ACCESS_DENIED) return EPERM; + if (h == NULL && GetLastError() == ERROR_INVALID_PARAMETER) return EINVAL; + if (h == NULL && GetLastError() == ERROR_FILE_NOT_FOUND) return ESRCH; + if (h == NULL) return EIO; if (TerminateProcess(h, exit_code)) { retval = 0; } else { @@ -482,6 +482,14 @@ void kill_program(HANDLE pid) { TerminateProcess(pid, 0); } #else +void int kill_program(int pid, int exit_code) { + int retval; + retval = kill(pid, SIGKILL); + if (-1 = retval) { + retval = errno; + } + return retval; +} void kill_program(int pid) { kill(pid, SIGKILL); } diff --git a/lib/util.h b/lib/util.h index a74aad7c06..0db7588374 100644 --- a/lib/util.h +++ b/lib/util.h @@ -101,6 +101,7 @@ extern int run_program( const char* dir, const char* file, int argc, char *const argv[], double, int& ); extern void kill_program(int); +extern int kill_program(int, int); extern int get_exit_status(int); extern bool process_exists(int); #endif