mirror of https://github.com/BOINC/boinc.git
lib: Normalize 'int kill_program()' around the error codes returned by errno.
This commit is contained in:
parent
37fd62bd95
commit
934c10d8e5
18
lib/util.cpp
18
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue