// If there are multiple displays, this may get called // multiple times (once for each display), so we need to guard // against any problems that may cause. void initBOINCSaver() { diagnostics_init( BOINC_DIAG_PERUSERLOGFILES | BOINC_DIAG_REDIRECTSTDOUT | BOINC_DIAG_REDIRECTSTDERR | BOINC_DIAG_TRACETOSTDOUT, "stdoutscr", "stderrscr" ); if (gspScreensaver == NULL) { gspScreensaver = new CScreensaver(); } }
// Some dual-GPU laptops (e.g., Macbook Pro) don't power down // the more powerful GPU until all applications which used them exit. // To save battery life, the client launches a second instance // of the client as a child process to detect and get info // about the GPUs. // The child process writes the info to a temp file which our main // client then reads. // static void do_gpu_detection(int argc, char** argv) { vector<string> warnings; boinc_install_signal_handlers(); gstate.parse_cmdline(argc, argv); gstate.now = dtime(); int flags = BOINC_DIAG_DUMPCALLSTACKENABLED | BOINC_DIAG_HEAPCHECKENABLED | BOINC_DIAG_TRACETOSTDOUT | BOINC_DIAG_REDIRECTSTDERR | BOINC_DIAG_REDIRECTSTDOUT; diagnostics_init(flags, "stdoutgpudetect", "stderrgpudetect"); read_config_file(true); coprocs.detect_gpus(warnings); coprocs.write_coproc_info_file(warnings); warnings.clear(); }
static void init_core_client(int argc, char** argv) { setbuf(stdout, 0); setbuf(stderr, 0); cc_config.defaults(); gstate.parse_cmdline(argc, argv); gstate.now = dtime(); #ifdef _WIN32 if (!cc_config.allow_multiple_clients) { chdir_to_data_dir(); } #endif #ifndef _WIN32 if (g_use_sandbox) // Set file creation mask to be writable by both user and group and // world-executable but neither world-readable nor world-writable // Our umask will be inherited by all our child processes // umask (6); #endif // Initialize the BOINC Diagnostics Framework int flags = #ifdef _DEBUG BOINC_DIAG_MEMORYLEAKCHECKENABLED | #endif BOINC_DIAG_DUMPCALLSTACKENABLED | BOINC_DIAG_HEAPCHECKENABLED | BOINC_DIAG_TRACETOSTDOUT; if (gstate.redirect_io || gstate.executing_as_daemon || gstate.detach_console) { flags |= BOINC_DIAG_REDIRECTSTDERR | BOINC_DIAG_REDIRECTSTDOUT; } diagnostics_init(flags, "stdoutdae", "stderrdae"); #ifdef _WIN32 // Specify which allocation will cause a debugger to break. Use a previous // memory leak detection report which looks like this: // {650} normal block at 0x000000000070A6F0, 24 bytes long. // Data: < N P p > 80 1E 4E 00 00 00 00 00 50 AE 70 00 00 00 00 00 //_CrtSetBreakAlloc(650); //_CrtSetBreakAlloc(651); //_CrtSetBreakAlloc(652); //_CrtSetBreakAlloc(653); //_CrtSetBreakAlloc(654); #endif read_config_file(true); // Win32 - detach from console if requested #ifdef _WIN32 if (gstate.detach_console) { FreeConsole(); } #endif // Unix: install signal handlers #ifndef _WIN32 // Handle quit signals gracefully boinc_set_signal_handler(SIGHUP, (handler_t)signal_handler); boinc_set_signal_handler(SIGINT, (handler_t)signal_handler); boinc_set_signal_handler(SIGQUIT, (handler_t)signal_handler); boinc_set_signal_handler(SIGTERM, (handler_t)signal_handler); #ifdef SIGPWR boinc_set_signal_handler(SIGPWR, (handler_t)signal_handler); #endif #endif }
// initialize the graphic diagnostic environment. // int boinc_init_graphics_diagnostics(int _flags) { return diagnostics_init( BOINC_DIAG_BOINCAPPLICATION | _flags, BOINC_DIAG_GFX_STDOUT, BOINC_DIAG_GFX_STDERR ); }
bool CBOINCGUIApp::OnInit() { // Initialize globals #ifdef SANDBOX g_use_sandbox = true; #else g_use_sandbox = false; #endif s_bSkipExitConfirmation = false; m_bFilterEvents = false; m_bAboutDialogIsOpen = false; // Initialize class variables m_pLocale = NULL; m_pSkinManager = NULL; m_pFrame = NULL; m_pDocument = NULL; m_pTaskBarIcon = NULL; m_pEventLog = NULL; #ifdef __WXMAC__ m_pMacDockIcon = NULL; #endif m_strBOINCMGRExecutableName = wxEmptyString; m_strBOINCMGRRootDirectory = wxEmptyString; m_strBOINCMGRDataDirectory = wxEmptyString; m_strHostNameArg = wxEmptyString; m_strPasswordArg = wxEmptyString; m_iRPCPortArg = GUI_RPC_PORT; m_strBOINCArguments = wxEmptyString; m_bGUIVisible = true; m_bDebugSkins = false; m_bMultipleInstancesOK = false; m_bBOINCMGRAutoStarted = false; m_iBOINCMGRDisableAutoStart = 0; m_iShutdownCoreClient = 0; m_iDisplayExitDialog = 1; m_iGUISelected = BOINC_SIMPLEGUI; m_bSafeMessageBoxDisplayed = 0; #ifdef __WXMSW__ m_hClientLibraryDll = NULL; #endif // Initialize local variables int iErrorCode = 0; int iSelectedLanguage = 0; bool bOpenEventLog = false; wxString strDesiredSkinName = wxEmptyString; wxString strDialogMessage = wxEmptyString; bool success = false; // Configure wxWidgets platform specific code #ifdef __WXMSW__ wxSystemOptions::SetOption(wxT("msw.staticbox.optimized-paint"), 0); #endif #ifdef __WXMAC__ // In wxMac-2.8.7, default wxListCtrl::RefreshItem() does not work // so use traditional generic implementation. // This has been fixed in wxMac-2.8.8, but the Mac native implementation: // - takes 3 times the CPU time as the Mac generic version. // - seems to always redraw entire control even if asked to refresh only one row. // - causes major flicker of progress bars, (probably due to full redraws.) wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1); AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false ); // Cache the current process serial number GetCurrentProcess(&m_psnCurrentProcess); #endif // Commandline parsing is done in wxApp::OnInit() if (!wxApp::OnInit()) { return false; } if (g_use_sandbox) { wxCHANGE_UMASK(2); // Set file creation mask to be writable by both user and group // Our umask will be inherited by all our child processes } // Setup application and company information SetAppName(wxT("BOINC Manager")); SetVendorName(wxT("Space Sciences Laboratory, U.C. Berkeley")); // Initialize the configuration storage module m_pConfig = new wxConfig(GetAppName()); wxConfigBase::Set(m_pConfig); wxASSERT(m_pConfig); // Restore Application State m_pConfig->SetPath(wxT("/")); m_pConfig->Read(wxT("AutomaticallyShutdownClient"), &m_iShutdownCoreClient, 0L); m_pConfig->Read(wxT("DisplayShutdownClientDialog"), &m_iDisplayExitDialog, 1L); m_pConfig->Read(wxT("DisableAutoStart"), &m_iBOINCMGRDisableAutoStart, 0L); m_pConfig->Read(wxT("Language"), &iSelectedLanguage, 0L); m_pConfig->Read(wxT("GUISelection"), &m_iGUISelected, BOINC_SIMPLEGUI); m_pConfig->Read(wxT("EventLogOpen"), &bOpenEventLog); // Should we abort the BOINC Manager startup process? if (m_bBOINCMGRAutoStarted && m_iBOINCMGRDisableAutoStart) { return false; } // Detect where BOINC Manager executable name. DetectExecutableName(); // Detect where BOINC Manager was installed too. DetectRootDirectory(); // Detect where the BOINC Data files are. DetectDataDirectory(); // Switch the current directory to the BOINC Data directory if (!GetDataDirectory().IsEmpty()) { success = wxSetWorkingDirectory(GetDataDirectory()); if (!success) { if (!g_use_sandbox) { if (!wxDirExists(GetDataDirectory())) { success = wxMkdir(GetDataDirectory(), 0777); // Does nothing if dir exists } } } } if (!success) iErrorCode = -1016; // Initialize the BOINC Diagnostics Framework int dwDiagnosticsFlags = BOINC_DIAG_DUMPCALLSTACKENABLED | BOINC_DIAG_HEAPCHECKENABLED | BOINC_DIAG_MEMORYLEAKCHECKENABLED | #if defined(__WXMSW__) || defined(__WXMAC__) BOINC_DIAG_REDIRECTSTDERR | BOINC_DIAG_REDIRECTSTDOUT | #endif BOINC_DIAG_TRACETOSTDOUT; diagnostics_init( dwDiagnosticsFlags, "stdoutgui", "stderrgui" ); // Enable Logging and Trace Masks m_pLog = new wxLogBOINC(); wxLog::SetActiveTarget(m_pLog); m_pLog->AddTraceMask(wxT("Function Start/End")); m_pLog->AddTraceMask(wxT("Function Status")); // Initialize the internationalization module #ifdef __WXMSW__ // On Windows, set all locales for this thread on a per-thread basis _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); #endif m_pLocale = new wxLocale(); wxASSERT(m_pLocale); // Look for the localization files by absolute and relative locations. // preference given to the absolute location. m_pLocale->Init(iSelectedLanguage); if (!m_strBOINCMGRRootDirectory.IsEmpty()) { m_pLocale->AddCatalogLookupPathPrefix( wxString(m_strBOINCMGRRootDirectory + wxT("locale")) ); } m_pLocale->AddCatalogLookupPathPrefix(wxT("locale")); m_pLocale->AddCatalog(wxT("BOINC-Manager")); m_pLocale->AddCatalog(wxT("BOINC-Client")); m_pLocale->AddCatalog(wxT("BOINC-Web")); InitSupportedLanguages(); language = m_pLocale->GetCanonicalName(); // Note: JAWS for Windows will only speak the context-sensitive // help if you use this help provider: wxHelpProvider::Set(new wxHelpControllerHelpProvider()); // Enable known image types wxInitAllImageHandlers(); // Initialize the skin manager m_pSkinManager = new CSkinManager(m_bDebugSkins); wxASSERT(m_pSkinManager); // Load desired manager skin m_pConfig->Read(wxT("Skin"), &strDesiredSkinName, m_pSkinManager->GetDefaultSkinName()); m_pSkinManager->ReloadSkin(strDesiredSkinName); #ifdef SANDBOX // Make sure owners, groups and permissions are correct for the current setting of g_use_sandbox char path_to_error[MAXPATHLEN]; path_to_error[0] = '\0'; if (!iErrorCode) { #if (defined(__WXMAC__) && defined(_DEBUG)) // TODO: implement this for other platforms // GDB can't attach to applications which are running as a different user // or group, so fix up data with current user and group during debugging if (check_security(g_use_sandbox, true, NULL, 0)) { CreateBOINCUsersAndGroups(); SetBOINCDataOwnersGroupsAndPermissions(); SetBOINCAppOwnersGroupsAndPermissions(NULL); } #endif iErrorCode = check_security( g_use_sandbox, true, path_to_error, sizeof(path_to_error) ); } if (iErrorCode) { ShowApplication(true); if (iErrorCode == -1099) { strDialogMessage.Printf( _("You currently are not authorized to manage the client.\n\nTo run %s as this user, please:\n - reinstall %s answering \"Yes\" to the question about\n non-administrative users\n or\n - contact your administrator to add you to the 'boinc_master'\n user group."), m_pSkinManager->GetAdvanced()->GetApplicationShortName().c_str(), m_pSkinManager->GetAdvanced()->GetApplicationShortName().c_str() ); } else { strDialogMessage.Printf( _("%s ownership or permissions are not set properly; please reinstall %s.\n(Error code %d"), m_pSkinManager->GetAdvanced()->GetApplicationShortName().c_str(), m_pSkinManager->GetAdvanced()->GetApplicationShortName().c_str(), iErrorCode ); if (path_to_error[0]) { strDialogMessage += _(" at "); strDialogMessage += wxString::FromUTF8(path_to_error); } strDialogMessage += _(")"); fprintf(stderr, "%s\n", (const char*)strDialogMessage.utf8_str()); } wxMessageDialog* pDlg = new wxMessageDialog( NULL, strDialogMessage, m_pSkinManager->GetAdvanced()->GetApplicationName(), wxOK ); pDlg->ShowModal(); if (pDlg) pDlg->Destroy(); return false; } #endif // SANDBOX #ifdef __WXMSW__ // Perform any last minute checks that should keep the manager // from starting up. wxString strRebootPendingFile = GetRootDirectory() + wxFileName::GetPathSeparator() + wxT("RebootPending.txt"); if (wxFile::Exists(strRebootPendingFile)) { wxMessageDialog dialog( NULL, _("A reboot is required in order for BOINC to run properly.\nPlease reboot your computer and try again."), _("BOINC Manager"), wxOK|wxICON_ERROR ); dialog.ShowModal(); return false; } #endif // Detect if BOINC Manager is already running, if so, bring it into the // foreground and then exit. if (!m_bMultipleInstancesOK) { if (DetectDuplicateInstance()) { return false; } } // Initialize the main document m_pDocument = new CMainDocument(); wxASSERT(m_pDocument); m_pDocument->OnInit(); // Is there a condition in which the Simple GUI should not be used? if (BOINC_SIMPLEGUI == m_iGUISelected) { // Screen too small? if (wxGetDisplaySize().GetHeight() < 600) { m_iGUISelected = BOINC_ADVANCEDGUI; } } // Initialize the task bar icon m_pTaskBarIcon = new CTaskBarIcon( m_pSkinManager->GetAdvanced()->GetApplicationName(), m_pSkinManager->GetAdvanced()->GetApplicationIcon(), m_pSkinManager->GetAdvanced()->GetApplicationDisconnectedIcon(), m_pSkinManager->GetAdvanced()->GetApplicationSnoozeIcon() #ifdef __WXMAC__ , wxTBI_CUSTOM_STATUSITEM #endif ); #ifdef __WXMAC__ m_pMacDockIcon = new CTaskBarIcon( m_pSkinManager->GetAdvanced()->GetApplicationName(), m_pSkinManager->GetAdvanced()->GetApplicationIcon(), m_pSkinManager->GetAdvanced()->GetApplicationDisconnectedIcon(), m_pSkinManager->GetAdvanced()->GetApplicationSnoozeIcon() , wxTBI_DOCK ); wxASSERT(m_pMacDockIcon); #endif wxASSERT(m_pTaskBarIcon); // Startup the System Idle Detection code IdleTrackerAttach(); #ifdef __WXMAC__ ProcessSerialNumber psn; ProcessInfoRec pInfo; OSStatus err; memset(&pInfo, 0, sizeof(pInfo)); pInfo.processInfoLength = sizeof( ProcessInfoRec ); err = GetProcessInformation(&m_psnCurrentProcess, &pInfo); if (!err) { psn = pInfo.processLauncher; memset(&pInfo, 0, sizeof(pInfo)); pInfo.processInfoLength = sizeof( ProcessInfoRec ); err = GetProcessInformation(&psn, &pInfo); } // Don't open main window if we were started automatically at login if (pInfo.processSignature == 'lgnw') { // Login Window app m_bGUIVisible = false; // If the system was just started, we usually get a "Connection // failed" error if we try to connect too soon, so delay a bit. sleep(10); } #endif // Show the UI SetActiveGUI(m_iGUISelected, m_bGUIVisible); if (!m_bGUIVisible) { #ifdef __WXMAC__ // We don't call Hide() or Show(false) for the main frame // under wxCocoa 2.9.5 because it bounces the Dock icon // (as in notification.) We work around this by moving // the main window/frame off screen here. // The position will be restored in one of these methods: // CBOINCGUIApp::OnActivateApp(), CSimpleFrame::SaveState() // or CAdvancedFrame::SaveWindowDimensions(). if (m_pFrame) { m_pFrame->MoveFrameOffScreen(); m_pFrame->Show(); } #endif ShowApplication(false); } if (bOpenEventLog) { DisplayEventLog(m_bGUIVisible); if (m_bGUIVisible && m_pFrame) { m_pFrame->Raise(); } } return true; }