2009-06-12 00:42:09 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "BOINCClientManager.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
2013-06-07 01:22:51 +00:00
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
#include "diagnostics.h"
|
2010-07-14 11:54:20 +00:00
|
|
|
#include "miofile.h"
|
2013-06-07 01:22:51 +00:00
|
|
|
#include "str_replace.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
#include "LogBOINC.h"
|
|
|
|
#include "BOINCGUIApp.h"
|
2010-07-14 11:54:20 +00:00
|
|
|
#include "SkinManager.h"
|
2009-06-12 00:42:09 +00:00
|
|
|
#include "MainDocument.h"
|
|
|
|
#include "BOINCBaseFrame.h"
|
|
|
|
#include "AdvancedFrame.h"
|
|
|
|
#include "BOINCClientManager.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "procinfo.h"
|
|
|
|
#include "filesys.h"
|
2009-11-13 21:23:15 +00:00
|
|
|
#include "daemonmgt.h"
|
2010-07-14 11:54:20 +00:00
|
|
|
#include "Events.h"
|
2010-07-14 19:46:27 +00:00
|
|
|
#include "version.h"
|
2010-07-14 11:54:20 +00:00
|
|
|
|
|
|
|
// Alert user if Client crashes 3 times in 30 minutes
|
|
|
|
#define CLIENT_3_CRASH_MAX_TIME 30
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2017-02-25 12:56:36 +00:00
|
|
|
#include "mac_util.h"
|
2009-06-12 00:42:09 +00:00
|
|
|
enum {
|
|
|
|
NewStyleDaemon = 1,
|
|
|
|
OldStyleDaemon
|
|
|
|
};
|
|
|
|
|
2009-08-27 01:46:20 +00:00
|
|
|
#elif defined(__WXMSW__)
|
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
#include "win_util.h"
|
|
|
|
#include "diagnostics_win.h"
|
|
|
|
|
|
|
|
extern int diagnostics_get_process_information(PVOID* ppBuffer, PULONG pcbBuffer);
|
2009-08-27 01:46:20 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <sys/wait.h>
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
CBOINCClientManager::CBOINCClientManager() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::CBOINCClientManager - Function Begin"));
|
|
|
|
|
|
|
|
m_bBOINCStartedByManager = false;
|
|
|
|
m_lBOINCCoreProcessId = 0;
|
2010-07-14 11:54:20 +00:00
|
|
|
m_fAutoRestart1Time = 0;
|
|
|
|
m_fAutoRestart2Time = 0;
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
m_hBOINCCoreProcess = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::CBOINCClientManager - Function End"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBOINCClientManager::~CBOINCClientManager() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::~CBOINCClientManager - Function Begin"));
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::~CBOINCClientManager - Function End"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCClientManager::AutoRestart() {
|
2010-07-14 11:54:20 +00:00
|
|
|
double timeNow, timeDiff;
|
2009-06-12 00:42:09 +00:00
|
|
|
if (IsBOINCCoreRunning()) return true;
|
2010-07-14 11:54:20 +00:00
|
|
|
#if ! (defined(__WXMAC__) || defined(__WXMSW__))
|
|
|
|
// Mac and Windows can restart Client as a daemon, but
|
|
|
|
// Linux may not know Client's location if it didn't start the Client
|
2009-11-13 21:23:15 +00:00
|
|
|
if (!m_bBOINCStartedByManager) return false;
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
2010-07-14 11:54:20 +00:00
|
|
|
// Alert user if Client crashes 3 times in CLIENT_3_CRASH_MAX_TIME
|
|
|
|
timeNow = dtime();
|
|
|
|
timeDiff = timeNow - m_fAutoRestart1Time;
|
|
|
|
if ((timeDiff) < (CLIENT_3_CRASH_MAX_TIME * 60)) {
|
|
|
|
int response;
|
|
|
|
ClientCrashDlg *dlg = new ClientCrashDlg(timeDiff);
|
|
|
|
if (dlg) {
|
|
|
|
CBOINCBaseFrame* pFrame = wxGetApp().GetFrame();
|
|
|
|
if (!pFrame->IsShown()) {
|
|
|
|
pFrame->Show();
|
|
|
|
}
|
|
|
|
response = dlg->ShowModal();
|
|
|
|
dlg->Destroy();
|
|
|
|
if (response == wxID_CANCEL) return false;
|
|
|
|
timeNow = 0;
|
|
|
|
m_fAutoRestart1Time = 0;
|
|
|
|
m_fAutoRestart2Time = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 00:42:09 +00:00
|
|
|
m_lBOINCCoreProcessId = 0;
|
2010-07-14 11:54:20 +00:00
|
|
|
m_fAutoRestart1Time = m_fAutoRestart2Time;
|
|
|
|
m_fAutoRestart2Time = timeNow;
|
2009-06-12 00:42:09 +00:00
|
|
|
StartupBOINCCore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCClientManager::IsSystemBooting() {
|
|
|
|
bool bReturnValue = false;
|
|
|
|
#if defined(__WXMSW__)
|
|
|
|
if (GetTickCount() < (1000*60*5)) bReturnValue = true; // If system has been up for less than 5 minutes
|
|
|
|
#elif defined(__WXMAC__)
|
2017-02-25 12:56:36 +00:00
|
|
|
if (getTimeSinceBoot() < (120)) bReturnValue = true; // If system has been up for less than 2 minutes
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
|
|
|
return bReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CBOINCClientManager::IsBOINCConfiguredAsDaemon() {
|
|
|
|
bool bReturnValue = false;
|
|
|
|
#if defined(__WXMSW__)
|
2009-11-13 21:23:15 +00:00
|
|
|
if (is_daemon_installed()) bReturnValue = 1;
|
2009-06-12 00:42:09 +00:00
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
if ( boinc_file_exists("/Library/LaunchDaemons/edu.berkeley.boinc.plist")) {
|
|
|
|
bReturnValue = NewStyleDaemon; // New-style daemon uses launchd
|
|
|
|
}
|
|
|
|
if (boinc_file_exists("/Library/StartupItems/boinc/boinc") ) {
|
|
|
|
bReturnValue = OldStyleDaemon; // Old-style daemon uses StartupItem
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return bReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCClientManager::IsBOINCCoreRunning() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function Begin"));
|
|
|
|
bool running = false;
|
|
|
|
|
2011-09-02 17:45:29 +00:00
|
|
|
PROC_MAP pm;
|
2009-08-26 07:47:49 +00:00
|
|
|
int retval;
|
|
|
|
|
2015-08-24 08:25:23 +00:00
|
|
|
#ifndef __WXMSW__
|
2009-08-27 01:46:20 +00:00
|
|
|
if (m_lBOINCCoreProcessId) {
|
|
|
|
// Prevent client from being a zombie
|
|
|
|
if (waitpid(m_lBOINCCoreProcessId, 0, WNOHANG) == m_lBOINCCoreProcessId) {
|
|
|
|
m_lBOINCCoreProcessId = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 08:25:23 +00:00
|
|
|
#endif
|
2009-08-27 01:46:20 +00:00
|
|
|
|
2009-08-26 07:47:49 +00:00
|
|
|
// Look for BOINC Client in list of all running processes
|
2011-09-02 17:45:29 +00:00
|
|
|
retval = procinfo_setup(pm);
|
2009-08-26 07:47:49 +00:00
|
|
|
if (retval) return false; // Should never happen
|
|
|
|
|
2011-09-02 17:45:29 +00:00
|
|
|
PROC_MAP::iterator i;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (i=pm.begin(); i!=pm.end(); ++i) {
|
2011-09-02 17:45:29 +00:00
|
|
|
PROCINFO& pi = i->second;
|
2015-08-24 08:25:23 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
if (!strcmp(pi.command, "boinc.exe"))
|
|
|
|
#else
|
|
|
|
if (!strcmp(pi.command, "boinc"))
|
|
|
|
#endif
|
|
|
|
{
|
2009-08-26 07:47:49 +00:00
|
|
|
running = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!strcmp(pi.command, "boinc_client")) {
|
|
|
|
running = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 08:25:23 +00:00
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Returning '%d'"), (int)running);
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::IsBOINCCoreRunning - Function End"));
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCClientManager::StartupBOINCCore() {
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::StartupBOINCCore - Function Begin"));
|
|
|
|
|
|
|
|
bool bReturnValue = false;
|
|
|
|
wxString strExecute = wxEmptyString;
|
2012-11-20 10:55:13 +00:00
|
|
|
wxString strDataDir = wxEmptyString;
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
if (IsBOINCCoreRunning()) return true;
|
|
|
|
|
2009-11-13 21:23:15 +00:00
|
|
|
#if defined(__WXMSW__)
|
2012-10-19 19:36:46 +00:00
|
|
|
const char* pszExecute = NULL;
|
|
|
|
const char* pszDataDirectory = NULL;
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
if (IsBOINCConfiguredAsDaemon()) {
|
2009-11-13 21:23:15 +00:00
|
|
|
start_daemon_via_daemonctrl();
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
m_bBOINCStartedByManager = true;
|
|
|
|
bReturnValue = IsBOINCCoreRunning();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
|
|
|
strExecute.Printf(
|
2012-11-20 10:55:13 +00:00
|
|
|
wxT("\"%sboinc.exe\" --redirectio --launched_by_manager %s"),
|
2009-06-12 00:42:09 +00:00
|
|
|
wxGetApp().GetRootDirectory().c_str(),
|
|
|
|
wxGetApp().GetArguments().c_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
PROCESS_INFORMATION pi;
|
2012-10-19 19:36:46 +00:00
|
|
|
STARTUPINFOA si;
|
2009-06-12 00:42:09 +00:00
|
|
|
BOOL bProcessStarted;
|
|
|
|
|
|
|
|
memset(&pi, 0, sizeof(pi));
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
|
2012-10-19 19:36:46 +00:00
|
|
|
pszExecute = (const char*)strExecute.mb_str();
|
2009-06-12 00:42:09 +00:00
|
|
|
if (wxGetApp().GetDataDirectory().empty()) {
|
2012-10-19 19:36:46 +00:00
|
|
|
pszDataDirectory = NULL;
|
2009-06-12 00:42:09 +00:00
|
|
|
} else {
|
2012-11-20 10:55:13 +00:00
|
|
|
strDataDir = wxGetApp().GetDataDirectory();
|
|
|
|
pszDataDirectory = (const char*)strDataDir.mb_str();
|
2009-06-12 00:42:09 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 19:36:46 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::StartupBOINCCore - pszExecute '%s'\n"), pszExecute);
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::StartupBOINCCore - pszDataDirectory '%s'\n"), pszDataDirectory);
|
2009-06-12 00:42:09 +00:00
|
|
|
|
2012-10-19 19:36:46 +00:00
|
|
|
bProcessStarted = CreateProcessA(
|
2009-06-12 00:42:09 +00:00
|
|
|
NULL,
|
2012-10-19 19:36:46 +00:00
|
|
|
(LPSTR)pszExecute,
|
2009-06-12 00:42:09 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW,
|
|
|
|
NULL,
|
2012-10-19 19:36:46 +00:00
|
|
|
(LPSTR)pszDataDirectory,
|
2009-06-12 00:42:09 +00:00
|
|
|
&si,
|
|
|
|
&pi
|
|
|
|
);
|
|
|
|
|
|
|
|
if (bProcessStarted) {
|
|
|
|
m_lBOINCCoreProcessId = pi.dwProcessId;
|
|
|
|
m_hBOINCCoreProcess = pi.hProcess;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
|
|
|
|
char buf[1024];
|
|
|
|
char *argv[5];
|
|
|
|
|
|
|
|
if (IsBOINCConfiguredAsDaemon() == NewStyleDaemon) {
|
|
|
|
system ("launchctl load /Library/LaunchDaemons/edu.berkeley.boinc.plist");
|
|
|
|
system ("launchctl start edu.berkeley.boinc");
|
2012-01-11 11:33:03 +00:00
|
|
|
for (int i=0; i<100; i++) { // Wait up to 1 seccond in 10 ms increments
|
|
|
|
boinc_sleep(0.01);
|
|
|
|
if (IsBOINCCoreRunning()) {
|
|
|
|
bReturnValue = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 00:42:09 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Get the full path to core client inside this application's bundle
|
2017-02-25 12:56:36 +00:00
|
|
|
getPathToThisApp(buf, sizeof(buf));
|
2009-06-12 00:42:09 +00:00
|
|
|
#if 0 // The Mac version of wxExecute(wxString& ...) crashes if there is a space in the path
|
2017-02-25 12:56:36 +00:00
|
|
|
strExecute = wxT("\"");
|
|
|
|
strExecute += wxT(buf);
|
|
|
|
strExecute += wxT("/Contents/Resources/boinc\" --redirectio --launched_by_manager");
|
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(strExecute);
|
2009-06-12 00:42:09 +00:00
|
|
|
#else // Use wxExecute(wxChar **argv ...) instead of wxExecute(wxString& ...)
|
2017-02-25 12:56:36 +00:00
|
|
|
strcat(buf, "/Contents/Resources/boinc");
|
|
|
|
argv[0] = buf;
|
|
|
|
argv[1] = "--redirectio";
|
|
|
|
argv[2] = "--launched_by_manager";
|
|
|
|
argv[3] = NULL;
|
2009-06-12 00:42:09 +00:00
|
|
|
#ifdef SANDBOX
|
2017-02-25 12:56:36 +00:00
|
|
|
if (!g_use_sandbox) {
|
|
|
|
argv[3] = "--insecure";
|
|
|
|
argv[4] = NULL;
|
|
|
|
}
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
2017-02-25 12:56:36 +00:00
|
|
|
// Under wxMac-2.8.0, wxExecute starts a separate thread
|
|
|
|
// to wait for child's termination.
|
|
|
|
// That wxProcessTerminationThread uses a huge amount of processor
|
|
|
|
// time (about 11% of one CPU on 2GHz Intel Dual-Core Mac).
|
2009-06-12 00:42:09 +00:00
|
|
|
// m_lBOINCCoreProcessId = ::wxExecute(argv);
|
2017-02-25 12:56:36 +00:00
|
|
|
run_program(
|
|
|
|
"/Library/Application Support/BOINC Data",
|
|
|
|
buf, argv[3] ? 4 : 3, argv, 0.0, m_lBOINCCoreProcessId
|
|
|
|
);
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // Unix based systems
|
2009-08-26 07:47:49 +00:00
|
|
|
wxString savedWD = ::wxGetCwd();
|
|
|
|
|
2009-08-26 11:53:51 +00:00
|
|
|
wxSetWorkingDirectory(wxGetApp().GetDataDirectory());
|
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
2009-08-26 11:53:51 +00:00
|
|
|
strExecute = wxGetApp().GetRootDirectory() + wxT("boinc --redirectio --launched_by_manager");
|
2009-06-12 00:42:09 +00:00
|
|
|
#ifdef SANDBOX
|
|
|
|
if (!g_use_sandbox) {
|
|
|
|
strExecute += wxT(" --insecure");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::StartupBOINCCore - szExecute '%s'\n"), strExecute.c_str());
|
2009-08-26 11:53:51 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CMainDocument::StartupBOINCCore - szDataDirectory '%s'\n"), wxGetApp().GetDataDirectory().c_str());
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(strExecute);
|
|
|
|
|
2009-08-26 07:47:49 +00:00
|
|
|
wxSetWorkingDirectory(savedWD);
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (0 != m_lBOINCCoreProcessId) {
|
|
|
|
m_bBOINCStartedByManager = true;
|
|
|
|
bReturnValue = true;
|
|
|
|
// Allow time for daemon to start up so we don't keep relaunching it
|
|
|
|
for (int i=0; i<100; i++) { // Wait up to 1 seccond in 10 ms increments
|
|
|
|
boinc_sleep(0.01);
|
|
|
|
if (IsBOINCCoreRunning()) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::StartupBOINCCore - Function End"));
|
|
|
|
return bReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
static tstring downcase_string(tstring& orig) {
|
|
|
|
tstring retval = orig;
|
|
|
|
for (size_t i=0; i < retval.length(); i++) {
|
|
|
|
retval[i] = tolower(retval[i]);
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBOINCClientManager::KillClient() {
|
|
|
|
ULONG cbBuffer = 128*1024; // 128k initial buffer
|
|
|
|
PVOID pBuffer = NULL;
|
|
|
|
PSYSTEM_PROCESSES pProcesses = NULL;
|
|
|
|
|
|
|
|
if (m_hBOINCCoreProcess != NULL) {
|
|
|
|
kill_program(m_hBOINCCoreProcess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a snapshot of the process and thread information.
|
|
|
|
diagnostics_get_process_information(&pBuffer, &cbBuffer);
|
|
|
|
|
|
|
|
// Lets start walking the structures to find the good stuff.
|
|
|
|
pProcesses = (PSYSTEM_PROCESSES)pBuffer;
|
|
|
|
do {
|
|
|
|
if (pProcesses->ProcessId) {
|
|
|
|
tstring strProcessName = pProcesses->ProcessName.Buffer;
|
|
|
|
if (downcase_string(strProcessName) == tstring(_T("boinc.exe"))) {
|
|
|
|
TerminateProcessById(pProcesses->ProcessId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the next structure if one exists
|
|
|
|
if (!pProcesses->NextEntryDelta) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pProcesses = (PSYSTEM_PROCESSES)(((LPBYTE)pProcesses) + pProcesses->NextEntryDelta);
|
|
|
|
} while (pProcesses);
|
|
|
|
|
|
|
|
// Release resources
|
|
|
|
if (pBuffer) HeapFree(GetProcessHeap(), NULL, pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void CBOINCClientManager::KillClient() {
|
2011-09-02 17:45:29 +00:00
|
|
|
PROC_MAP pm;
|
2009-06-12 00:42:09 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (m_lBOINCCoreProcessId) {
|
|
|
|
kill_program(m_lBOINCCoreProcessId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-02 17:45:29 +00:00
|
|
|
retval = procinfo_setup(pm);
|
2009-06-12 00:42:09 +00:00
|
|
|
if (retval) return; // Should never happen
|
|
|
|
|
2011-09-02 17:45:29 +00:00
|
|
|
PROC_MAP::iterator i;
|
2015-01-14 20:18:29 +00:00
|
|
|
for (i=pm.begin(); i!=pm.end(); ++i) {
|
2013-07-29 08:31:09 +00:00
|
|
|
PROCINFO& procinfo = i->second;
|
|
|
|
if (!strcmp(procinfo.command, "boinc")) {
|
|
|
|
kill_program(procinfo.id);
|
2009-06-12 00:42:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-11-03 02:35:04 +00:00
|
|
|
void CBOINCClientManager::ShutdownBOINCCore(bool ShuttingDownManager) {
|
2009-06-12 00:42:09 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function Begin"));
|
|
|
|
|
2011-11-03 02:35:04 +00:00
|
|
|
CMainDocument* pDoc = wxGetApp().GetDocument();
|
|
|
|
wxInt32 iCount = 0;
|
|
|
|
bool bClientQuit = false;
|
|
|
|
wxString strConnectedCompter = wxEmptyString;
|
|
|
|
wxString strPassword = wxEmptyString;
|
|
|
|
double startTime = 0;
|
|
|
|
wxDateTime zeroTime = wxDateTime((time_t)0);
|
|
|
|
wxDateTime rpcCompletionTime = zeroTime;
|
|
|
|
ASYNC_RPC_REQUEST request;
|
|
|
|
int quit_result;
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
wxASSERT(pDoc);
|
|
|
|
wxASSERT(wxDynamicCast(pDoc, CMainDocument));
|
|
|
|
|
2015-09-28 07:04:29 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Mac Manager shuts down client only if Manager started client
|
2010-08-24 01:45:12 +00:00
|
|
|
if (!m_bBOINCStartedByManager) return;
|
2015-09-28 07:04:29 +00:00
|
|
|
#endif
|
2010-08-24 01:45:12 +00:00
|
|
|
|
2009-06-12 00:42:09 +00:00
|
|
|
#ifdef __WXMSW__
|
2010-08-24 01:45:12 +00:00
|
|
|
if (IsBOINCConfiguredAsDaemon()) {
|
|
|
|
stop_daemon_via_daemonctrl();
|
|
|
|
bClientQuit = true;
|
|
|
|
} else
|
2009-06-12 00:42:09 +00:00
|
|
|
#endif
|
2010-08-24 01:45:12 +00:00
|
|
|
{
|
|
|
|
pDoc->GetConnectedComputerName(strConnectedCompter);
|
|
|
|
if (!pDoc->IsComputerNameLocal(strConnectedCompter)) {
|
|
|
|
RPC_CLIENT rpc;
|
|
|
|
if (!rpc.init("localhost")) {
|
|
|
|
pDoc->m_pNetworkConnection->GetLocalPassword(strPassword);
|
|
|
|
rpc.authorize((const char*)strPassword.mb_str());
|
2009-06-12 00:42:09 +00:00
|
|
|
if (IsBOINCCoreRunning()) {
|
2010-08-24 01:45:12 +00:00
|
|
|
rpc.quit();
|
2009-06-12 00:42:09 +00:00
|
|
|
for (iCount = 0; iCount <= 10; iCount++) {
|
|
|
|
if (!bClientQuit && !IsBOINCCoreRunning()) {
|
2010-08-24 01:45:12 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit Detected"));
|
2009-06-12 00:42:09 +00:00
|
|
|
bClientQuit = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-24 01:45:12 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - (localhost) Application Exit NOT Detected, Sleeping..."));
|
2009-06-12 00:42:09 +00:00
|
|
|
::wxSleep(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bClientQuit = true;
|
|
|
|
}
|
|
|
|
}
|
2010-08-24 01:45:12 +00:00
|
|
|
rpc.close();
|
|
|
|
} else {
|
|
|
|
if (IsBOINCCoreRunning()) {
|
2011-11-03 02:35:04 +00:00
|
|
|
if (ShuttingDownManager) {
|
|
|
|
// Set event filtering to allow RPC completion
|
|
|
|
// events but not events which start new RPCs
|
|
|
|
wxGetApp().SetEventFiltering(true);
|
|
|
|
}
|
|
|
|
quit_result = -1;
|
|
|
|
request.clear();
|
|
|
|
request.which_rpc = RPC_QUIT;
|
|
|
|
request.rpcType = RPC_TYPE_ASYNC_NO_REFRESH;
|
|
|
|
request.completionTime = &rpcCompletionTime;
|
|
|
|
request.resultPtr = &quit_result;
|
|
|
|
pDoc->RequestRPC(request); // Issue an asynchronous Quit RPC
|
|
|
|
|
|
|
|
// Client needs time to shut down project applications, so don't wait
|
|
|
|
// for it to shut down; assume it will exit OK if Quit RPC succeeds.
|
|
|
|
startTime = dtime();
|
|
|
|
while ((dtime() - startTime) < 10.0) { // Allow 10 seconds
|
|
|
|
boinc_sleep(0.25); // Check 4 times per second
|
|
|
|
wxSafeYield(NULL, true); // To allow handling RPC completion events
|
|
|
|
if (!bClientQuit && (rpcCompletionTime != zeroTime)) {
|
|
|
|
// If Quit RPC finished, check its returned value
|
|
|
|
if (quit_result) {
|
|
|
|
break; // Quit RPC returned an error
|
|
|
|
}
|
2010-08-24 01:45:12 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit Detected"));
|
|
|
|
bClientQuit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCClientManager::ShutdownBOINCCore - Application Exit NOT Detected, Sleeping..."));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bClientQuit = true;
|
|
|
|
}
|
2009-06-12 00:42:09 +00:00
|
|
|
}
|
2010-08-24 01:45:12 +00:00
|
|
|
}
|
2009-06-12 00:42:09 +00:00
|
|
|
|
2010-08-24 01:45:12 +00:00
|
|
|
if (!bClientQuit) {
|
|
|
|
KillClient();
|
2009-06-12 00:42:09 +00:00
|
|
|
}
|
2010-08-24 01:45:12 +00:00
|
|
|
m_lBOINCCoreProcessId = 0;
|
2009-06-12 00:42:09 +00:00
|
|
|
|
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCClientManager::ShutdownBOINCCore - Function End"));
|
|
|
|
}
|
2010-07-14 11:54:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(ClientCrashDlg, wxDialog)
|
|
|
|
EVT_BUTTON(wxID_HELP, ClientCrashDlg::OnHelp)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS(ClientCrashDlg, wxDialog)
|
|
|
|
|
|
|
|
ClientCrashDlg::ClientCrashDlg(double timeDiff) : wxDialog( NULL, wxID_ANY, wxT(""), wxDefaultPosition ) {
|
|
|
|
wxString strDialogTitle = wxEmptyString;
|
|
|
|
wxString strDialogMessage = wxEmptyString;
|
2010-07-14 19:46:27 +00:00
|
|
|
int minutes = wxMax((int)((timeDiff + 59.) / 60.), 2);
|
2010-07-14 11:54:20 +00:00
|
|
|
CSkinAdvanced* pSkinAdvanced = wxGetApp().GetSkinManager()->GetAdvanced();
|
|
|
|
wxASSERT(pSkinAdvanced);
|
|
|
|
|
|
|
|
// %s is the application name
|
|
|
|
// i.e. 'BOINC Manager', 'GridRepublic Manager'
|
|
|
|
strDialogTitle.Printf(
|
|
|
|
_("%s - Unexpected Exit"),
|
|
|
|
pSkinAdvanced->GetApplicationName().c_str()
|
|
|
|
);
|
|
|
|
SetTitle(strDialogTitle.c_str());
|
|
|
|
|
|
|
|
// 1st %s is the application name
|
|
|
|
// i.e. 'BOINC Manager', 'GridRepublic Manager'
|
|
|
|
// 2st %s is the project name
|
|
|
|
// i.e. 'BOINC', 'GridRepublic'
|
|
|
|
strDialogMessage.Printf(
|
2010-07-14 23:52:15 +00:00
|
|
|
_("The %s client has exited unexpectedly 3 times within the last %d minutes.\nWould you like to restart it again?"),
|
2010-07-14 11:54:20 +00:00
|
|
|
pSkinAdvanced->GetApplicationShortName().c_str(),
|
|
|
|
minutes
|
|
|
|
);
|
|
|
|
|
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
icon_text->Add( CreateTextSizer( strDialogMessage ), 0, wxALIGN_CENTER | wxLEFT, 10 );
|
|
|
|
topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
|
|
|
|
|
|
|
|
wxStdDialogButtonSizer *sizerBtn = CreateStdDialogButtonSizer(wxYES | wxNO | wxHELP);
|
|
|
|
SetEscapeId(wxID_NO); // Changes return value of NO button to wxID_CANCEL
|
|
|
|
|
|
|
|
if ( sizerBtn )
|
|
|
|
topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
|
|
|
|
|
|
|
|
SetAutoLayout( true );
|
|
|
|
SetSizer( topsizer );
|
|
|
|
|
|
|
|
topsizer->SetSizeHints( this );
|
|
|
|
topsizer->Fit( this );
|
|
|
|
wxSize size( GetSize() );
|
|
|
|
if (size.x < size.y*3/2)
|
|
|
|
{
|
|
|
|
size.x = size.y*3/2;
|
|
|
|
SetSize( size );
|
|
|
|
}
|
|
|
|
|
|
|
|
Centre( wxBOTH | wxCENTER_FRAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ClientCrashDlg::OnHelp(wxCommandEvent& WXUNUSED(eventUnused)) {
|
|
|
|
wxString strURL = wxGetApp().GetSkinManager()->GetAdvanced()->GetOrganizationHelpUrl();
|
|
|
|
|
|
|
|
wxString wxurl;
|
|
|
|
wxurl.Printf(
|
2010-07-14 19:46:27 +00:00
|
|
|
wxT("%s?target=crash_detection&version=%s&controlid=%d"),
|
2010-07-14 11:54:20 +00:00
|
|
|
strURL.c_str(),
|
|
|
|
wxString(BOINC_VERSION_STRING, wxConvUTF8).c_str(),
|
|
|
|
ID_HELPBOINC
|
|
|
|
);
|
|
|
|
wxLaunchDefaultBrowser(wxurl);
|
|
|
|
}
|