/// /// Determines if another instance of BOINC Manager is running. /// /// @return /// true if another instance of BOINC Manager is running, otherwise false. /// /// Note: will always return false on Win95, Win98, WinME /// int CBOINCGUIApp::IsAnotherInstanceRunning() { PROC_MAP pm; int retval; char myName[256]; int otherInstanceID = 0; int myPid; // Look for BOINC Manager in list of all running processes retval = procinfo_setup(pm); if (retval) return false; // Should never happen #ifdef _WIN32 myPid = (int)GetCurrentProcessId(); #else myPid = getpid(); #endif // Get the name of this Application myName[0] = 0; PROC_MAP::iterator i; for (i=pm.begin(); i!=pm.end(); i++) { PROCINFO& procinfo = i->second; if (procinfo.id == myPid) { strncpy(myName, procinfo.command, sizeof(myName)); break; } } if (myName[0] == 0) { return false; // Should never happen } // Search process list for other applications with same name for (i=pm.begin(); i!=pm.end(); i++) { PROCINFO& procinfo = i->second; if (procinfo.id == myPid) continue; if (!strcmp(procinfo.command, myName)) { otherInstanceID = procinfo.id; break; } } return otherInstanceID; }
bool CBOINCClientManager::IsBOINCCoreRunning() { wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin")); bool running = false; PROC_MAP pm; int retval; #ifndef __WXMSW__ if (m_lBOINCCoreProcessId) { // Prevent client from being a zombie if (waitpid(m_lBOINCCoreProcessId, 0, WNOHANG) == m_lBOINCCoreProcessId) { m_lBOINCCoreProcessId = 0; } } #endif // Look for BOINC Client in list of all running processes retval = procinfo_setup(pm); if (retval) return false; // Should never happen PROC_MAP::iterator i; for (i=pm.begin(); i!=pm.end(); ++i) { PROCINFO& pi = i->second; #ifdef __WXMSW__ if (!strcmp(pi.command, "boinc.exe")) #else if (!strcmp(pi.command, "boinc")) #endif { running = true; break; } if (!strcmp(pi.command, "boinc_client")) { running = true; break; } } wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), (int)running); wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End")); return running; }
void CBOINCClientManager::KillClient() { PROC_MAP pm; int retval; if (m_lBOINCCoreProcessId) { kill_program(m_lBOINCCoreProcessId); return; } retval = procinfo_setup(pm); if (retval) return; // Should never happen PROC_MAP::iterator i; for (i=pm.begin(); i!=pm.end(); i++) { PROCINFO& procinfo = i->second; if (!strcmp(procinfo.command, "boinc")) { kill_program(procinfo.id); break; } } }
static void setup(void) { char *fname = NULL; uint64_t intvl; if (atexit(teardown) != 0) { log_stderr("cannot register teardown procedure with atexit()"); exit(EX_OSERR); /* only failure comes from NOMEM */ } /* Setup logging first */ log_setup(&stats.log); if (debug_setup(&setting.debug) != CC_OK) { log_stderr("debug log setup failed"); exit(EX_CONFIG); } /* setup top-level application options */ if (option_bool(&setting.ds.daemonize)) { daemonize(); } fname = option_str(&setting.ds.pid_filename); if (fname != NULL) { /* to get the correct pid, call create_pidfile after daemonize */ create_pidfile(fname); } /* setup library modules */ buf_setup(&setting.buf, &stats.buf); dbuf_setup(&setting.dbuf, &stats.dbuf); event_setup(&stats.event); sockio_setup(&setting.sockio, &stats.sockio); tcp_setup(&setting.tcp, &stats.tcp); timing_wheel_setup(&stats.timing_wheel); /* setup pelikan modules */ time_setup(&setting.time); procinfo_setup(&stats.procinfo); request_setup(&setting.request, &stats.request); response_setup(&setting.response, &stats.response); parse_setup(&stats.parse_req, NULL); compose_setup(NULL, &stats.compose_rsp); slab_setup(&setting.slab, &stats.slab); process_setup(&setting.process, &stats.process); admin_process_setup(); core_admin_setup(&setting.admin); core_server_setup(&setting.server, &stats.server); core_worker_setup(&setting.worker, &stats.worker); /* adding recurring events to maintenance/admin thread */ intvl = option_uint(&setting.ds.dlog_intvl); if (core_admin_register(intvl, debug_log_flush, NULL) == NULL) { log_stderr("Could not register timed event to flush debug log"); goto error; } return; error: if (fname != NULL) { remove_pidfile(fname); } /* since we registered teardown with atexit, it'll be called upon exit */ exit(EX_CONFIG); }
bool CBOINCClientManager::IsBOINCCoreRunning() { wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin")); bool running = false; #ifdef __WXMSW__ char buf[MAX_PATH] = ""; if (is_daemon_installed()) { running = (FALSE != is_daemon_starting()) || (FALSE != is_daemon_running()); } else { // Global mutex on Win2k and later // safe_strcpy(buf, "Global\\"); strcat( buf, RUN_MUTEX); HANDLE h = CreateMutexA(NULL, true, buf); DWORD err = GetLastError(); if ((h==0) || (err == ERROR_ALREADY_EXISTS)) { running = true; } if (h) { CloseHandle(h); } } #elif defined(__WXMAC__) char path[1024]; static FILE_LOCK file_lock; sprintf(path, "%s/%s", (const char *)wxGetApp().GetDataDirectory().mb_str(), LOCK_FILE_NAME); if (boinc_file_exists(path)) { // If there is no lock file, core is not running if (file_lock.lock(path)) { running = true; } else { file_lock.unlock(path); } } #else PROC_MAP pm; int retval; if (m_lBOINCCoreProcessId) { // Prevent client from being a zombie if (waitpid(m_lBOINCCoreProcessId, 0, WNOHANG) == m_lBOINCCoreProcessId) { m_lBOINCCoreProcessId = 0; } } // Look for BOINC Client in list of all running processes retval = procinfo_setup(pm); if (retval) return false; // Should never happen PROC_MAP::iterator i; for (i=pm.begin(); i!=pm.end(); i++) { PROCINFO& pi = i->second; if (!strcmp(pi.command, "boinc")) { running = true; break; } if (!strcmp(pi.command, "boinc_client")) { running = true; break; } } #endif wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), (int)running); wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End")); return running; }