Exemplo n.º 1
0
// wxProcess::Exists and wxKill are unimplemented in WxMac-2.6.0
void CBOINCClientManager::ShutdownBOINCCore() {
    CMainDocument*     pDoc = wxGetApp().GetDocument();
    wxInt32            iCount = 0;
    std::string        strPassword;

    wxASSERT(pDoc);
    wxASSERT(wxDynamicCast(pDoc, CMainDocument));

    if (m_bBOINCStartedByManager) {
        if (!pDoc->IsLocalClient()) {
            RPC_CLIENT rpc;
            if (!rpc.init("localhost")) {
                try {
                    strPassword = read_gui_rpc_password();
                } catch (...) {
                    // Ignore any errors here and set an empty password.
                    // This will happen if the manager does not find the
                    // GUI-RPC-password file in its working directory.
                }
                rpc.authorize(strPassword.c_str());
                if (ProcessExists(m_lBOINCCoreProcessId)) {
                    rpc.quit();
                    for (iCount = 0; iCount <= 10; iCount++) {
                        if (!ProcessExists(m_lBOINCCoreProcessId))
                            return;
                        ::wxSleep(1);
                    }
                }
            }
            rpc.close();
        } else {
            if (ProcessExists(m_lBOINCCoreProcessId)) {
                pDoc->CoreClientQuit();
                for (iCount = 0; iCount <= 10; iCount++) {
                    if (!ProcessExists(m_lBOINCCoreProcessId))
                        return;

                    ::wxSleep(1);
                }
            }
        }
        
        // Client did not quit after 10 seconds so kill it
        kill(m_lBOINCCoreProcessId, SIGKILL);
    }
    m_lBOINCCoreProcessId = 0;
}
TBool CAppFwkStartSafeTestStepProcStartMon::ProcessExists(const TDesC& aProcessName)
	{
	RProcess process;
	TBool result = EFalse;
	result = ProcessExists(aProcessName, process);
	process.Close(); //Closing a closed process handle, which would be the case if the process we wanted can't be found, is not an error, so no need to check if open
	return result;
	}
Exemplo n.º 3
0
bool install_util::WaitProcessExit(const TCHAR* szExeName, int nMilliseconds) {
  if (nMilliseconds <= 0)
    return !ProcessExists(szExeName);

  DWORD dwStartTime = ::GetTickCount();
  do {
    if (!ProcessExists(szExeName))
      return true;

    if (::GetTickCount() - dwStartTime >= (size_t)nMilliseconds)
      return false;

    ::Sleep(1);
  } while (1);

  assert(false && "NOTREACHE");
  return false;
}
TVerdict CAppFwkStartSafeTestStepProcStartMon::doTestStepL( void )
	{
	
	CStartSafe* startSafe = CStartSafe::NewL();	
	CleanupStack::PushL( startSafe );
	
	CStartupProperties* prop = CStartupProperties::NewL();
	CleanupStack::PushL( prop );

	RProcess proc;	
	CleanupClosePushL( proc );
	
	// KLaunchServerCommandLineOption makes the process listen for remote control connections
	prop->SetFileParamsL( KTestProcGood, KLaunchServerCommandLineOption ); 
	prop->SetStartupType( EStartProcess );
	prop->SetStartMethod( EWaitForStart ); // EFireAndForget is disallowed
	prop->SetMonitored( ETrue ); // the process death will be monitored
	prop->SetNoOfRetries( 1 );   // Must be non-zero in order to invoke a restart


		
	INFO_PRINTF1( _L("Starting the Test-process") );
		
	TInt tried = 0;	
		
	TRAPD( err, startSafe->StartAndMonitorL( *prop, proc, tried) );
	User::After( KPoliteInterval );

	// Produce the process-name search-term
	TPtrC namePtr( KTestProcGood() );
	namePtr.Set( namePtr.Ptr(), namePtr.Find(_L(".")) );


	// See if StartSafe thinks it's been successful _and that the process can be found. (if, line 73)
	// Then check to see that it has been restarted after being Kill()ed (if, line 85)
	if( (KErrNone == err) && ProcessExists(namePtr) )
		{
		
		INFO_PRINTF2( _L("Process \"%S\" started"), &namePtr );
		
			
		proc.Kill( KStartSafeTestKillCode );
		proc.Close();
		// Process should be restarted here
		User::After( KThrottleTime );
		
		
		if( ProcessExists( namePtr, proc ) )
			{
			INFO_PRINTF2( _L("Process \"%S\" REstarted successfully"), &namePtr );
			
			// RTestProcGoodSession is used to remotely control the process, allowing this process to cancel the monitoring of the target process, 
			// otherwise it keeps being restarted
			RTestProcGoodSession testProc;
			testProc.Connect();
			testProc.CancelMonitor();
			testProc.Close();
			
			proc.Kill( KStartSafeTestFinalKillCode );
		
			SetTestStepResult( EPass );	
			}
		else
			{
			ERR_PRINTF1( _L("Process was _not restarted") );
			
			SetTestStepResult( EFail );	
			}
			
		}
	else 
		{
		ERR_PRINTF2( _L("StartAndMonitorL left with"), err );	
		
		SetTestStepResult( EFail );
		}
		
		
	CleanupStack::PopAndDestroy( 3, startSafe ); // proc, prop, startSafe
	
	return TestStepResult();	
	}