- API: improve log messages when detect dead client

This commit is contained in:
David Anderson 2012-12-29 11:47:53 -08:00 committed by Oliver Bock
parent f57f32fd0b
commit e393203ff7
2 changed files with 27 additions and 8 deletions

View File

@ -379,28 +379,44 @@ static void handle_heartbeat_msg() {
}
static bool client_dead() {
bool dead;
if (aid.client_pid) {
// check every 10 sec
//
if (interrupt_count%(TIMERS_PER_SEC*10)) return false;
#ifdef _WIN32
// Windows doesn't have waitpid() :-(
// Windows lacks an easy way to check for process existence :-(
//
DWORD pids[4096], nb;
BOOL r = EnumProcesses(pids, sizeof(pids), &nb);
if (!r) return false;
int n = nb/sizeof(DWORD);
dead = true;
for (int i=0; i<n; i++) {
if (pids[i] == aid.client_pid) return false;
if (pids[i] == aid.client_pid) {
dead = false;
break;
}
}
return true;
#else
int retval = kill(aid.client_pid, 0);
return (retval == -1 && errno == ESRCH);
dead = (retval == -1 && errno == ESRCH);
#endif
} else {
return (interrupt_count > heartbeat_giveup_count);
dead = (interrupt_count > heartbeat_giveup_count);
}
if (dead) {
char buf[256];
boinc_msg_prefix(buf, sizeof(buf));
fputs(buf, stderr); // don't use fprintf() here
if (aid.client_pid) {
fputs(" BOINC client no longer exists - exiting\n", stderr);
} else {
fputs(" No heartbeat from client for 30 sec - exiting\n", stderr);
}
return true;
}
return false;
}
#ifndef _WIN32
@ -1207,9 +1223,6 @@ static void timer_handler() {
//
if (in_critical_section==0 && options.check_heartbeat) {
if (client_dead()) {
boinc_msg_prefix(buf, sizeof(buf));
fputs(buf, stderr); // don't use fprintf() here
fputs(" No heartbeat from client for 30 sec - exiting\n", stderr);
if (options.direct_process_action) {
exit_from_timer_thread(0);
} else {

View File

@ -7966,3 +7966,9 @@ Rom 28 Dec 2012
samples\vboxwrapper\
vbox.cpp
David 29 Dec 2012
- API: improve log messages when detect dead client
api/
boinc_api.cpp