From 934c10d8e572524a7cdfd224baae17a159bbc24c Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Sun, 27 Jul 2014 14:10:48 -0400 Subject: [PATCH] lib: Normalize 'int kill_program()' around the error codes returned by errno. --- lib/util.cpp | 18 +++++++++++++----- lib/util.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) 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