// Terminate any screensaver graphics application // int CScreensaver::terminate_v6_screensaver(GFXAPP_ID& graphics_application) { int retval = 0; #ifdef __APPLE__ // Under sandbox security, use gfx_switcher to kill default gfx app // as user boinc_master and group boinc_master. The man page for // kill() says the user ID of the process sending the signal must // match that of the target process, though in practice that seems // not to be true on the Mac. char current_dir[PATH_MAX]; char gfx_pid[16]; pid_t thePID; int i; sprintf(gfx_pid, "%d", graphics_application); getcwd( current_dir, sizeof(current_dir)); char* argv[4]; argv[0] = "gfx_switcher"; argv[1] = "-kill_gfx"; argv[2] = gfx_pid; argv[3] = 0; retval = run_program( current_dir, m_gfx_Switcher_Path, 3, argv, 0, thePID ); for (i=0; i<200; i++) { boinc_sleep(0.01); // Wait 2 seconds max // Prevent gfx_switcher from becoming a zombie if (waitpid(thePID, 0, WNOHANG) == thePID) { break; } } #endif #ifdef _WIN32 HWND hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { CloseWindow(hBOINCGraphicsWindow); Sleep(1000); hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { kill_program(graphics_application); } } #endif // For safety, call kill_program even under Apple sandbox security kill_program(graphics_application); 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); }
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; } } }
// Terminate any screensaver graphics application // int CScreensaver::terminate_v6_screensaver(GFXAPP_ID& graphics_application) { int retval = 0; #ifdef __APPLE__ // Under sandbox security, use gfx_switcher to kill default gfx app // as user boinc_master and group boinc_master. The man page for // kill() says the user ID of the process sending the signal must // match that of the target process, though in practice that seems // not to be true on the Mac. char current_dir[PATH_MAX]; char gfx_pid[16]; pid_t thePID; int i; if (graphics_application == 0) return 0; // MUTEX may help prevent crashes when terminating an older gfx app which // we were displaying using CGWindowListCreateImage under OS X >= 10.13 // Also prevents reentry when called from our other thread pthread_mutex_lock(&saver_mutex); sprintf(gfx_pid, "%d", graphics_application); getcwd( current_dir, sizeof(current_dir)); char* argv[4]; argv[0] = "gfx_switcher"; argv[1] = "-kill_gfx"; argv[2] = gfx_pid; argv[3] = 0; retval = run_program( current_dir, m_gfx_Switcher_Path, 3, argv, 0, thePID ); if (graphics_application) { launchedGfxApp("", 0, -1); } for (i=0; i<200; i++) { boinc_sleep(0.01); // Wait 2 seconds max // Prevent gfx_switcher from becoming a zombie if (waitpid(thePID, 0, WNOHANG) == thePID) { break; } } pthread_mutex_unlock(&saver_mutex); #endif #ifdef _WIN32 HWND hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { CloseWindow(hBOINCGraphicsWindow); Sleep(1000); hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { kill_program(graphics_application); } } #endif // For safety, call kill_program even under Apple sandbox security kill_program(graphics_application); return retval; }