client: always show task_debug message if kill_program() fails

... but change kill_program() so it's not a failure if the process doesn't exit.
This is to help debug a possible "zombie process" bug
This commit is contained in:
David Anderson 2015-06-29 22:05:48 -07:00
parent 80a084d8d6
commit b78c842cf9
2 changed files with 19 additions and 15 deletions

View File

@ -225,33 +225,34 @@ int ACTIVE_TASK::request_abort() {
}
#ifdef _WIN32
static void kill_app_process(int pid, bool will_restart, bool show_errors) {
static void kill_app_process(int pid, bool will_restart) {
int retval = 0;
retval = kill_program(pid, will_restart?0:EXIT_ABORTED_BY_CLIENT);
if (retval && log_flags.task_debug && show_errors) {
if (retval && log_flags.task_debug) {
msg_printf(0, MSG_INFO,
"[task] kill_app_process() failed: %s",
strerror(retval)
"[task] kill_program(%d) failed: %s",
pid, boincerror(retval)
);
}
}
#else
static void kill_app_process(int pid, bool, bool show_errors) {
static void kill_app_process(int pid, bool) {
int retval = 0;
if (g_use_sandbox) {
retval = kill_via_switcher(pid);
if (retval && log_flags.task_debug && show_errors) {
if (retval && log_flags.task_debug) {
msg_printf(0, MSG_INFO,
"[task] kill_via_switcher() failed: %s (%d)",
"[task] kill_via_switcher(%d) failed: %s (%d)",
pid,
(retval>=0) ? strerror(errno) : boincerror(retval), retval
);
}
} else {
retval = kill(pid, SIGKILL);
if (retval && log_flags.task_debug && show_errors) {
retval = kill_program(pid);
if (retval && log_flags.task_debug) {
msg_printf(0, MSG_INFO,
"[task] kill() failed: %s",
strerror(errno)
"[task] kill_program(%d) failed: %s",
pid, strerror(errno)
);
}
}
@ -263,7 +264,7 @@ static void kill_app_process(int pid, bool, bool show_errors) {
// will be cleaned up after it exits, by cleanup_task();
//
int ACTIVE_TASK::kill_running_task(bool will_restart) {
kill_app_process(pid, will_restart, true);
kill_app_process(pid, will_restart);
return 0;
}
@ -277,10 +278,10 @@ int ACTIVE_TASK::kill_running_task(bool will_restart) {
int ACTIVE_TASK::kill_subsidiary_processes() {
unsigned int i;
for (i=0; i<other_pids.size(); i++) {
kill_app_process(other_pids[i], false, false);
kill_app_process(other_pids[i], false);
}
for (i=0; i<descendants.size(); i++) {
kill_app_process(descendants[i], false, false);
kill_app_process(descendants[i], false);
}
return 0;
}

View File

@ -468,7 +468,9 @@ int kill_program(int pid, int exit_code) {
int retval;
HANDLE h = OpenProcess(PROCESS_TERMINATE, false, pid);
if (h == NULL) return ERR_NOT_FOUND;
if (h == NULL) return 0;
// process isn't there, so no error
if (TerminateProcess(h, exit_code)) {
retval = 0;
} else {
@ -486,6 +488,7 @@ int kill_program(HANDLE pid) {
#else
int kill_program(int pid) {
if (kill(pid, SIGKILL)) {
if (errno == ESRCH) return 0;
return ERR_KILL;
}
return 0;