lib: Normalize 'int kill_program()' around the error codes returned by errno.

This commit is contained in:
Rom Walton 2014-07-27 14:10:48 -04:00
parent 37fd62bd95
commit 934c10d8e5
2 changed files with 14 additions and 5 deletions

View File

@ -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);
}

View File

@ -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