Esempio n. 1
0
// ==========================================================================
// METHOD:  Initialize
//
// DESIGN:  
// ==========================================================================
TBool CDebugLogTlsData::Initialize()
    {
    TInt returnValue = ( iFs.Connect() == KErrNone );
    
    if( returnValue )
        {
        // Request notification of directory adds/deletes in the logs directory.
        iFs.NotifyChange( ENotifyDir, iStatus, KDebugLogsBaseDirectory );        
        SetActive();
        
    	// Dynamically create the name of the log files based on the application name
    	// and thread ID.  This will eliminate multiple processes/thread usage of
    	// this debug logging infrastructure from scribbling each others traces.
	    RProcess thisProcess;
   	    RThread  thisThread;

	    // The file name is the process name followed by the thread ID.
    	TParsePtrC fileNameParser( thisProcess.FileName() );
    	iFileName.Copy( fileNameParser.Name() );
    	iFileName.Append( KUnderscore );
    	iFileName.Append( thisThread.Name() );    	    	
    	iFileName.Append( KDebugLogFileExt );    	       
        
        } // end if
        
    return returnValue;        

    } // END Initialize
Esempio n. 2
0
/**
 *	Load the initial contents of the setting items.  By default,
 *	the setting items are populated with the default values from
 * 	the design.  You can override those values here.
 *	<p>
 *	Note: this call alone does not update the UI.
 *	LoadSettingsL() must be called afterwards.
 */
void CSymbian_ua_guiSettingItemList::LoadSettingValuesL()
{
    // load values into iSettings

    TFileName path;
    TFileName pathWithoutDrive;
    CEikonEnv::Static()->FsSession().PrivatePath( pathWithoutDrive );

    // Extract drive letter into appDrive:
#ifdef __WINS__
    path.Copy( _L("c:") );
#else
    RProcess process;
    path.Copy( process.FileName().Left(2) );
#endif

    path.Append( pathWithoutDrive );
    path.Append( KtxDicFileName );

    TFindFile AufFolder(CCoeEnv::Static()->FsSession());
    if(KErrNone == AufFolder.FindByDir(path, KNullDesC))
    {
        CDictionaryFileStore* MyDStore = CDictionaryFileStore::OpenLC(CCoeEnv::Static()->FsSession(),AufFolder.File(), TUid::Uid(1));
        TUid FileUid;

        FileUid.iUid = KRegistrar;
        if(MyDStore->IsPresentL(FileUid))
        {
            RDictionaryReadStream in;
            in.OpenLC(*MyDStore,FileUid);
            in >> iSettings.Ed_registrar();
            CleanupStack::PopAndDestroy(1);// in
        }
static TDriveUnit exeDrive()
{
    RProcess me;
    TFileName processFileName = me.FileName();
    TDriveUnit drive(processFileName);
    return drive;
}
Esempio n. 4
0
/**
 * @brief Completes the second phase of Symbian object construction.
 * Put initialization code that could leave here.
 */
void Csymbian_ua_guiAppUi::ConstructL()
{
    // [[[ begin generated region: do not modify [Generated Contents]
    BaseConstructL (EAknEnableSkin);
    InitializeContainersL();
    // ]]] end generated region [Generated Contents]

    // Create private folder
    RProcess process;
    TFileName path;

    path.Copy (process.FileName().Left (2));

    if (path.Compare (_L ("c")) || path.Compare (_L ("C")))
        CEikonEnv::Static()->FsSession().CreatePrivatePath (EDriveC);
    else if (path.Compare (_L ("e")) || path.Compare (_L ("E")))
        CEikonEnv::Static()->FsSession().CreatePrivatePath (EDriveE);

    // Init PJSUA
    if (symbian_ua_init() != 0) {
        symbian_ua_destroy();
        Exit();
    }

    ExecuteDlg_wait_initLD();

    CTimer::ConstructL();
    CActiveScheduler::Add (this);
    After (4000000);
}
Esempio n. 5
0
/*
	Static factory constructor. Uses two phase construction and leaves nothing on the 
	CleanupStack. Creates a CTestPnP object.
	@param  None
	@return Instance of the test server
 */
CTestPnP* CTestPnP::NewL()
	{
	CTestPnP *	server = new (ELeave) CTestPnP();
	CleanupStack::PushL(server);
	// CServer base class call
	RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	server->ConstructL(serverName.Name());
	CleanupStack::Pop(server);
	return server;
	}
Esempio n. 6
0
void CListsStep::ListExecutables()
/**
 * @return void
 * This tests we can succesfully list the executables and that the returned values make sense
 */
	{
	INFO_PRINTF1(_L("Lists Test Suite: ListExecutables") );

	if (TestStepResult()==EPass)
		{

		RExecutablePointerList execList;

		TRAPD( err, iSess.GetExecutablesL( execList ) );

		if(err != KErrNone)
			{
			SetTestStepResult(EFail);
			INFO_PRINTF2(_L("Error %d from iSess.GetExecutablesL()/n"), err);
			return;
			}

		if( execList.Count() == 0 )
			{
			SetTestStepResult(EFail);
			INFO_PRINTF1(_L("Error : GetExecutablesL() returned empty list/n") );
			return;
			}
		else
			{
			RProcess thisProc;
			TInt i;
			for( i=0; i < execList.Count(); i++ )
				{
				if( execList[i]->Name() == thisProc.FileName() )
					{
					break;
					}
				}

			if( i == execList.Count() )
				{
				SetTestStepResult(EFail);
				INFO_PRINTF1(_L("Error : This executable could not be found in GetExecutablesL() list/n") );
				return;
				}
			}

		execList.ResetAndDestroy();
		execList.Close();

		}
	}
/**
Same code for Secure and non-secure variants
Called inside the MainL() function to create and start the
CTestServer derived server.

@return - Instance of the test server
*/
CTe_graphicsperformanceSuite* CTe_graphicsperformanceSuite::NewL()
	{
	CTe_graphicsperformanceSuite * server = new (ELeave) CTe_graphicsperformanceSuite();
	CleanupStack::PushL(server);

	// Get server name from process so we can use SetCap to change the capabilites and use this server with a different filename
	RProcess handle = RProcess();
	TParsePtrC serverName(handle.FileName());

	server->ConstructL(serverName.Name());
	CleanupStack::Pop(server);
	return server;
	}
Esempio n. 8
0
 ~QSymbianPrintExitInfo()
 {
     RProcess myProc;
     TFullName fullName = myProc.FileName();
     TInt cells = User::CountAllocCells();
     TInt processHandleCount=0;
     TInt threadHandleCount=0;
     RThread().HandleCount(processHandleCount, threadHandleCount);
     RDebug::Print(_L("%S exiting with %d allocated cells, %d handles"),
                   &fullName,
                   cells - initCells,
                   (processHandleCount + threadHandleCount) - (initProcessHandleCount + initThreadHandleCount));
 }
CcapsignalTestServer* CcapsignalTestServer::NewL()
	{
	CcapsignalTestServer *server = new(ELeave) CcapsignalTestServer();
	CleanupStack::PushL(server);
	//server->ConstructL(KServerName);
RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	server->StartL(serverName.Name());


	CleanupStack::Pop(server);
	return server;
	}
TVerdict CAppFwkStartSafeTestStepAppTimeout::doTestStepL( void )
	{
	
	CStartSafe *startSafe = CStartSafe::NewL();	
	CleanupStack::PushL( startSafe );
	
	CStartupProperties *prop = CStartupProperties::NewL();
	CleanupStack::PushL( prop );
	
	RProcess proc;
	CleanupClosePushL( proc );
	
	prop->SetFileParamsL( KTestAppSlow, KNullDesC );
	prop->SetStartupType( EStartApp );
	prop->SetStartMethod( EWaitForStart );
	prop->SetNoOfRetries( 0 );
	prop->SetTimeout( KWaitTime );
	

	TInt tried = 0;
			
	
	INFO_PRINTF2( _L("Start the app and wait for %d milliseconds"), KWaitTime );	

	TRAPD( err, startSafe->StartL(*prop, proc, tried) );
	
	if ( KErrTimedOut == err )
		{
		SetTestStepResult( EPass );
		INFO_PRINTF1( _L("Timed out - Test passed") );
		}
	else
		{
		SetTestStepResult( EFail );
		ERR_PRINTF1( _L("No time-out - Test failed") );
		
		TPtrC procNamePtr = proc.FileName().Right( KTestAppSlow().Length() );
		// Check that the process is the app we think it is.
		if( 0 == procNamePtr.Compare( KTestAppSlow()) )
			{
			proc.Kill( KErrNone );	
			}
			
		}
		
		
	CleanupStack::PopAndDestroy( 3, startSafe );

	return TestStepResult();	
	}
	EXPORT_C void KillExeL(const TDesC& aProcessName)
	{
		//DebugMsg(_L("finding processes"), aDebugLog);
		TFindProcess f(_L("*"));
		TFullName *tp=new (ELeave) TFullName;
		CleanupStack::PushL(tp);
		TFullName& t=*tp;
		RProcess r;
		TInt len=aProcessName.Length();
		if (len==0) User::Leave(KErrArgument);
		while (f.Next(t)==KErrNone) {
			r.Open(t);
			CleanupClosePushL(r);
			if (r.FileName().Length()>=len && 
				r.FileName().Left(1).CompareF(_L("z"))!=0 && 
				r.FileName().Mid(1).CompareF(aProcessName.Mid(1))==0) {
				//DebugMsg(_L("killing"), aDebugLog);
				r.Kill(2003);
			}
			CleanupStack::PopAndDestroy();
		}
		CleanupStack::PopAndDestroy();
	}
CSimTestServer* CSimTestServer::NewL()
/**
 * @return - Instance of the test server
 * Same code for Secure and non-secure variants
 * Called inside the MainL() function to create and start the
 * CTestServer derived server.
 */
	{
	CSimTestServer * testServer = new (ELeave) CSimTestServer();
	CleanupStack::PushL(testServer);
	RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	testServer->ConstructL(serverName.Name());
	CleanupStack::Pop(testServer);
	return testServer;
	}
CTestHtmlToCrtConverterSuite* CTestHtmlToCrtConverterSuite::NewL()
/**
 * @return - Instance of the test server
 * Same code for Secure and non-secure variants
 * Called inside the MainL() function to create and start the
 * CTestServer derived server.
 */
	{
	CTestHtmlToCrtConverterSuite *	server = new (ELeave) CTestHtmlToCrtConverterSuite();
	CleanupStack::PushL(server);
	// CServer base class call
	RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	server->ConstructL(serverName.Name());
	CleanupStack::Pop(server);
	return server;
	}
Esempio n. 14
0
void CCommandLineArguments::ConstructL()
	{
	// allocate args array
	iArgs=new (ELeave) CArrayFixFlat<TPtrC> (10);
	RProcess me;
	// get raw command line
	User::CommandLine(iCommandLine);
	iFileName=me.FileName();
	// scan for each argument
	TText* out=(TText*) iCommandLine.Ptr();
	const TText* scan=iCommandLine.Ptr();
	const TText* end=scan+iCommandLine.Length();
	while (scan < end) // scan one argument
		{
		while (scan < end && *scan==' ') // skip leading space
			scan++;
		if (scan == end) // ignore if blank
			break;
		TBool quoted=*scan=='\"'; // note leading quote
		if (quoted)
			scan++;
		TText* start=out; // note start in output
		if (!quoted) // if not quoted, scan for blank
			{
			while (scan < end && *scan!=' ')
				*out++ = *scan++;
			}
		else // quoted, scan for quote
			{
			for (;;) // one quote-or-double sequence
				{
				while (scan < end && *scan!='\"') // all up to quote
					*out++ = *scan++;
				if (scan < end) // skip quote
					scan++;
				if (scan < end && *scan=='\"') // transfer if quote is doubled
					*out++ = *scan++;
				else // finished this arg
					break;
				}
			}
		TPtrC arg(start, out-start);
		iArgs->AppendL(arg);
		}
	}
Esempio n. 15
0
LOCAL_C void OverrideEShell(void)
//
// Copies the executable file as the eshell so that it is automatically run
//
    {
    test.Next(_L("OverideEShell"));
    RProcess myProc;
    if (myProc.FileName().CompareF(StartupExeName) == 0)
        test.Printf(_L("OverrideEShell: running as eshell\n"));
    else
        {
        RFile logFile;
        TInt r;
        TFileName tempDirName=_L("");
        // Copy over this executable and create a progress file.
        test.Printf(_L("Copying %S to %S\n"), &TestExeName, &StartupExeName);
        if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
            tempDirName = _L("?:\\SYS\\BIN\\");
        else
            tempDirName = _L("?:\\SYSTEM\\BIN\\");
        tempDirName[0] = gSessionPath[0];
        r=TheFs.MkDirAll(tempDirName);
        test_Value(r, r == KErrNone||r==KErrAlreadyExists);
        CFileMan* fileMan=NULL;
        TRAP(r,fileMan = CFileMan::NewL(TheFs));
        test_KErrNone(r);
        //Copy the test from Z drive.
        TFileName temp=_L("Z:\\SYS\\BIN\\T_SCN32DR3.EXE");
        r = fileMan->Copy(temp, TestExeName, CFileMan::EOverWrite);
        test_KErrNone(r);
        r = fileMan->Copy(TestExeName, StartupExeName, CFileMan::EOverWrite);
        test_KErrNone(r);
        //Mask read attribute. Fix for DEF081323
        r = fileMan->Attribs(StartupExeName, 0, KEntryAttReadOnly, 0);
        test_KErrNone(r);
        r = fileMan->Attribs(TestExeName, 0, KEntryAttReadOnly, 0);
        test_KErrNone(r);
        r = logFile.Replace(TheFs,LogFileName,EFileShareExclusive|EFileWrite);
        test_KErrNone(r);
        logFile.Close();
        delete fileMan;
        }
    }
Esempio n. 16
0
CTFntStoreServer* CTFntStoreServer::NewL()
/**
   @return - Instance of the test server
   Same code for Secure and non-secure variants
   Called inside the MainL() function to create and start the
   CTestServer derived server.
 */
	{
	CTFntStoreServer * server = new (ELeave) CTFntStoreServer();
	CleanupStack::PushL(server);
	
	// Get server name from process so we can use SetCap to change the capabilites and use this server with a different filename
	RProcess handle = RProcess();
	TParsePtrC serverName(handle.FileName());
	
	// CServer base class call
	server->StartL(serverName.Name());
		
	CleanupStack::Pop(server);
	return server;
	}
Esempio n. 17
0
/*
-----------------------------------------------------------------------------
----------------------------------------------------------------------------
*/
TBool CMainContainer::IsServerOn(const TDesC& aName)
{
	TBool Ret(EFalse);
	
	TFileName res;
	TFindProcess find;
  	while(find.Next(res) == KErrNone)
    {
    	RProcess ph;
	  	ph.Open(res);
	  	  			
		if(ph.FileName().Find(aName) != KErrNotFound)
	 	{
	  		Ret = ETrue;
	  		break;
	  	}
	  	
	  	ph.Close();
    }
 
    return Ret;
}
Esempio n. 18
0
void CIpUpsDialog::ResolveClientNameL(const TSecureId& aSid)
/**
Generates a human readable name for the client process. In order of 
preference the following data is returned

- The AppArc caption name.
- The localized package name that owns this SID.
- A value from a lookup table.
- The filename for the client process executable.

@param aSid	The secure id of the client process.
*/
   {
   TBool found = EFalse;
	
   // Although the client name from AppArc takes precedance the SIS
   // registry is always invoked in order to retrieve the vendor name
   found |= ResolveClientNameFromSisRegistryL(aSid);
   found |= ResolveClientNameFromAppArcL(aSid);
			
   // A lookup that maps secure-ids to application names could
   // be used here.

   // Fall back to the filename of the client process
   // The original thread may have exited so the process handle is used instead.
   // because the client-side object e.g. RSocket may be shared between threads.

   // If the process has exited then it's o.k. to leave.
   if (! found)
      {			
      RProcess clientProcess;
      User::LeaveIfError(clientProcess.Open(iRequest->ClientProcessId()));
      CleanupClosePushL(clientProcess);
      iPromptData->iClientName.Create(clientProcess.FileName());		
      CleanupStack::PopAndDestroy(&clientProcess); 
      }
   }
void CIAUpdateXmlParser::SetPrivateDriveL( 
    RFs& aFs,
    const TDesC& aFileName ) const
    {
    IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() begin: %S", 
                     &aFileName);
    
    // This will set the correct drive and private path 
    // for the file server session.    

    // First try to find the file from the private directory
    // of the drive where the process exists.
    RProcess process;

    // Set the session private path according to 
    // the process file name drive.
    TInt driveNum( 
        SetSessionPrivatePathL( aFs, process.FileName() ) );

    // Get the session path that was set above.
    IAUPDATE_TRACE_1("[IAUPDATE] Find file: %d", driveNum);
    TFileName sessionPath;
    User::LeaveIfError( aFs.SessionPath( sessionPath ) );
    IAUPDATE_TRACE_1("[IAUPDATE] Session path: %S", &sessionPath);

    // Use the file finder to check if the file actually exists 
    // in the given drive path. If it does not, the file finder 
    // will automatically check from other drives. So, here we 
    // should always find the file if any exists.
    TFindFile finder( aFs );
    User::LeaveIfError( finder.FindByDir( aFileName, sessionPath ) );

    // The drive may have changed if the file was not found from
    // the first suggested drive. So, be sure to have the correct
    // private path.
    driveNum = SetSessionPrivatePathL( aFs, finder.File() );

    // Use the drive info to check if the drive is ROM drive.
    // We prefer non ROM drives. But, accept ROM if nothing else is
    // available.
    IAUPDATE_TRACE_1("[IAUPDATE] Check ROM info: %d", driveNum);
    TDriveInfo info;
    User::LeaveIfError( aFs.Drive( info, driveNum ) );
    TBool isRomDrive( info.iDriveAtt & KDriveAttRom );
    if ( !isRomDrive )
        {
        // The current file is not in ROM drive so use that.
        IAUPDATE_TRACE("[IAUPDATE] First file search done. Non ROM found.");
        IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
        return;
        }

    // Because previous finding was ROM file, try to find a non ROM file.
    IAUPDATE_TRACE("[IAUPDATE] Try to find non ROM file.");
    TInt findErrorCode( finder.Find() );
    if ( findErrorCode == KErrNotFound )
        {
        // Because no new file is found, use the current settings.
        IAUPDATE_TRACE("[IAUPDATE] Second search done. No file found.");
        IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
        return;
        }
    User::LeaveIfError( findErrorCode );

    IAUPDATE_TRACE("[IAUPDATE] New file found. Use that.");
    // Update the session path for the correct file.
    SetSessionPrivatePathL( aFs, finder.File() );

    IAUPDATE_TRACE("[IAUPDATE] CIAUpdateXmlParser::SetPrivateDriveL() end");
    }
TVerdict CAppFwkStartSafeTestStepAppStartRvError::doTestStepL()
	{
	TInt threadHandles_Before;
	TInt processHandles_Before;
	TInt threadHandles_After;
	TInt processHandles_After;
		
	RThread().HandleCount(processHandles_Before, threadHandles_Before);
	
	CStartSafe *startSafe = CStartSafe::NewL();	
	CleanupStack::PushL( startSafe );
	
	CStartupProperties *prop = CStartupProperties::NewL();
	CleanupStack::PushL( prop );
	
	RProcess proc;
	CleanupClosePushL( proc );
	
	prop->SetFileParamsL( KTestAppRvError, KNullDesC );
	prop->SetStartupType( EStartApp );
	prop->SetStartMethod( EWaitForStart );
	prop->SetNoOfRetries( KStartSafeAppStartRvErrorRetries );
	prop->SetTimeout( KStartSafeAppStartErrorNominalTimeout ); 

	TInt tried = 0;
	
	INFO_PRINTF1( _L("Start the Test Application") );
	TRAPD( err, startSafe->StartL(*prop, proc, tried) );

	// Ensure that the process-name of the test-app is not extant.
	TPtrC procNamePtr = proc.FileName().Right( KTestAppRvError().Length() );
	TInt nameComparison = procNamePtr.Compare( KTestAppRvError() );
		
	if ( (0 == nameComparison) )
		{
		ERR_PRINTF2( _L("Application whose process-name is\"%S\" was found, but should not have been"), &procNamePtr );
		
		// Dispose of the erroneously extant test-app.
		proc.Kill( KErrNone );
		SetTestStepResult( EFail );
		
		ERR_PRINTF1( _L("Test failed") );
		}
	else if( (KStartSafeAppStartRvErrorRetries +1) != tried )
		{
		ERR_PRINTF1( _L("Process-name (correctly) not found, but...") );
		ERR_PRINTF3( _L("Total tries = %d  should have been %d"), tried, (KStartSafeAppStartRvErrorRetries +1) );	
		
		SetTestStepResult( EFail );
		}
	else
		{
		INFO_PRINTF1( _L("Process was (correctly) not found") );
		INFO_PRINTF2( _L("Error code %d"), err );
		
		// The 'erroneous' rendezvous code
		TESTE( KErrGeneral, err );		
		}	


	CleanupStack::PopAndDestroy( 3, startSafe ); 
	
	RThread().HandleCount(processHandles_After, threadHandles_After);
	TEST(processHandles_After == processHandles_Before);
	TEST(threadHandles_After == threadHandles_Before);
	
	return TestStepResult();	
	}
void CTWServScreenConstructServer::ConstructL()
	{
	RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	CTestServer::ConstructL(serverName.Name());
	}
Esempio n. 22
0
//
// LtkUtils::W32CrackL
// loads the autometric logging engine, dlogev.dll, into wserv
// enabling Autometric to monitor events from within wserv - key/pointer events, text drawn to screen etc
//
EXPORT_C void LtkUtils::W32CrackL()
{
#ifndef FSHELL_WSERV_SUPPORT
    User::Leave(KErrNotSupported);
#else

    // Check if P&S says it's already enabled, if so no need to do anything
    if (W32CrackIsEnabled()) return;

    _LIT(KWsIniFile, "z:\\system\\data\\wsini.ini");
    _LIT(KCWsIniFile,"c:\\system\\data\\wsini.ini");
    _LIT(KLogEv, "LOG EV\r\n");

    // Open z file
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFile file;
    User::LeaveIfError(file.Open(fs, KWsIniFile, EFileRead));
    CleanupClosePushL(file);

    TInt size;
    User::LeaveIfError(file.Size(size));

    RBuf8 buf;
    buf.CreateL(size + KLogEv().Size());
    CleanupClosePushL(buf);
    User::LeaveIfError(file.Read(buf));
    TPtrC16 wptr((TUint16*)buf.Ptr(), buf.Size()/2);
    buf.Insert(2, TPtrC8((TUint8*)KLogEv().Ptr(), KLogEv().Size())); // +2 to get past the BOM
    TInt err = KErrNone;
    err = fs.MkDirAll(KCWsIniFile); // mkdir c:\system\data\ in case it is not exist
    if((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }
    User::LeaveIfError(file.Replace(fs, KCWsIniFile, EFileWrite));
    User::LeaveIfError(file.Write(buf));
    CleanupStack::PopAndDestroy(2, &file); // file, buf

    err = RMemoryAccess::LoadDriver();
    if ((err != KErrNone) && (err != KErrAlreadyExists))
    {
        User::Leave(err);
    }

    RMemoryAccess memAccess;
    User::LeaveIfError(memAccess.Open());
    CleanupClosePushL(memAccess);

    RWsSession ws;
    User::LeaveIfError(ws.Connect(fs));
    CleanupClosePushL(ws);

#ifdef __WINS__
    // On wins the binary isn't renamed
    _LIT(KWservMatch, "wserv*.exe*");
#else
    _LIT(KWservMatch, "EwSrv.exe*");
#endif
    TFindProcess find(KWservMatch);
    TFullName name;
    User::LeaveIfError(find.Next(name));

    RProcess wservProc;
    User::LeaveIfError(wservProc.Open(find));
    if (wservProc.ExitType() != EExitPending)
    {
        // in case wserv kicks off the preferred implementation in a new process then kills itself
        // (is one retry enough or should we be looping here?)
        wservProc.Close();
        User::LeaveIfError(find.Next(name));
        User::LeaveIfError(wservProc.Open(find));
    }
    CleanupClosePushL(wservProc);
    name = wservProc.FileName();
    name[0] = 'c';
    TPtrC8 narrowName = name.Collapse();
    User::LeaveIfError(memAccess.InPlaceSetProcessFileName(wservProc, narrowName));

    // Now tell wserv to reload its wsini.ini and enable logging
    ws.LogCommand(RWsSession::ELoggingEnable);
    ws.Flush();

    // cleanup
    CleanupStack::PopAndDestroy(4, &fs);

#endif // FSHELL_WSERV_SUPPORT
}
void CT_WServRateLimiterTestServer::ConstructL()
	{
	RProcess	handle = RProcess();
	TParsePtrC	serverName(handle.FileName());
	CTestServer::ConstructL(serverName.Name());
	}
TVerdict CAppFwkStartSafeTestStepAppStartAppArcInit::doTestStepL( void )
	{
	
	CStartSafe* startSafe = CStartSafe::NewL();	
	CleanupStack::PushL( startSafe );
	
	CStartupProperties* prop = CStartupProperties::NewL();
	CleanupStack::PushL( prop );
	
	RProcess proc;
	CleanupClosePushL( proc );
	
	prop->SetFileParamsL( KTestAppGood, KNullDesC );
	prop->SetStartupType( EStartApp );
	prop->SetStartMethod( EDeferredWaitForStart );
	

	TRequestStatus startupTRS;
	TRequestStatus apparcSessionTRS;
	
	INFO_PRINTF1(_L("Starting the Test-App process asynchronously"));
	
	startSafe->StartL( *prop, proc, startupTRS );	

	User::WaitForRequest( startupTRS );
	INFO_PRINTF2( _L("Rendezvous completed with %d"), startupTRS.Int() );	
	
	// StartL should have left if it was unsuccessful, 
	// but ensure that the process's name is that of the test-app.
	TPtrC procNamePtr = proc.FileName().Right( KTestAppGood().Length() );
	TInt nameComparison = procNamePtr.Compare( KTestAppGood() );
	
	if( 0 == nameComparison )
		{
		INFO_PRINTF2( _L("Application \"%S\" started correctly"), &procNamePtr );	
		}
	else
		{
		ERR_PRINTF1( _L("Application-start unsuccessful. Test not completed") );
		
		SetTestStepResult( EFail );
		return TestStepResult();
		}
	
	startSafe->InitAppArcServer( apparcSessionTRS ); // try to initiate apparc, to see if that causes any problems
	User::WaitForRequest( apparcSessionTRS );
	

	if ( ( startupTRS == KErrNone) && ( apparcSessionTRS == KErrNone) )
		{
		SetTestStepResult( EPass );
		INFO_PRINTF1( _L("Test passed") );
		// Dispose of the test-app
		proc.Kill( KErrNone );		
		}
	else
		{
		SetTestStepResult( EFail );
		ERR_PRINTF3( _L("Test failed.startupTRS = %d apparcSessionTRS = %d "), startupTRS.Int(), apparcSessionTRS.Int() );				
		}
	
		
	CleanupStack::PopAndDestroy( 3, startSafe );

	return TestStepResult();	
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::GetRunningProcessesL
// ----------------------------------------------------------------------------------------
CBufFlat* CTerminalControlServer::GetRunningProcessesL( )
{
    RDEBUG("CTerminalControlServer::GetRunningProcessesL");

    TFullName    processName;
    TFindProcess findProcess;
    CBufFlat *buffer = CBufFlat::NewL(128);
    iProcessInfoArray->Reset();

    while( KErrNone == findProcess.Next( processName ) )
    {
        TTcProcessInfo info;
        RProcess process;

        if( KErrNone == process.Open( findProcess ) )
        {
            //
            // Add process information to local array
            //
            info.iProcessName = processName;
            info.iFileName    = process.FileName();

            info.iHandle      = process.Handle();
            info.iId          = process.Id();
            info.iSecureId    = process.SecureId();

            info.iProtected   = EFalse;

            process.GetMemoryInfo( info.iMemoryInfo );

            User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            if( !info.iCodeInRom )
            {
                User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            }

            iProcessInfoArray->AppendL( info );

            //
            // Add process also to return buffer
            //
            /*
            TInt appendPosition = buffer->Size();
            if(iProcessInfoArray->Count() >= 2)
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, proName);
                }
            else
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, proName);
                }
            }

            */

            // Enumerate names from 1
            TInt appendPosition = buffer->Size();
            TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
            TBuf8<sizeof(KFormatProcessNamePrefix)+20> nameBuf;

            numBuf.Num(iProcessInfoArray->Count());
            nameBuf.Zero();
            nameBuf.Append(KFormatProcessNamePrefix);
            nameBuf.Append(numBuf);

            if(iProcessInfoArray->Count() >= 2)
            {
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, nameBuf);
            }
            else
            {
                buffer->InsertL(appendPosition, nameBuf);
            }
        }
    }
    /*
    	TUint32 flags = Exec::ProcessFlags(KCurrentProcessHandle);
    	if (flags & KProcessFlagSystemPermanent)
    		return ESystemPermanent;
    	if (flags & KProcessFlagSystemCritical)
    		return ESystemCritical;
    	if (flags & KThreadFlagProcessPermanent)
    		return EAllThreadsCritical;
    	return ENotCritical;
    */
    return buffer;
}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::StopProcessByFullNameL
// ----------------------------------------------------------------------------------------
void CTerminalControlServer::StopProcessByFullNameL(const TDesC8& aName) {
    RDEBUG("[CTerminalControlServer]-> StopProcessByFullNameL() >>>");


    TInt rounds = 5;
    TFileName lMatchStr;
    lMatchStr.Copy(aName);
    lMatchStr.LowerCase();

    TBool lIsAbsolute = EFalse;
    if(lMatchStr.LocateReverse(TChar('\\')) != KErrNotFound) {
        lIsAbsolute = ETrue;
    }
    while(rounds--) {
        TInt ret = KErrNone;
        TFullName processName;
        TFindProcess findProcess;

        while(KErrNone == (ret = findProcess.Next(processName))) {
            RProcess process;

            if(KErrNone == (ret = process.Open(findProcess))) {
                RDEBUG("[CTerminalControlServer]-> Process.Open() returned");

                TFileName lStrSource(process.FileName());
                lStrSource.LowerCase();
                if(lIsAbsolute) {
                    RDEBUG("[CTerminalControlServer]-> INFO: The input was specified as an absolute path...");
                    if(lStrSource.Compare(lMatchStr) == 0) {
                        RDEBUG("[CTerminalControlServer]-> Process with correct Filename found => Kill(0) ");
                        process.Kill(0);
                    }
                }
                else {
                    RDEBUG("[CTerminalControlServer]-> INFO: The input was specified as an application name...");
                    TInt lLastDirSepIndex = lStrSource.LocateReverse('\\');
                    TInt lExeIndex = lStrSource.Find(_L(".exe"));
                    if(lLastDirSepIndex < lExeIndex) {
                        TInt lAppNameIndex = lStrSource.Find(lMatchStr);

                        /*
                         * The logic works like this, if the value of lStrSource was 'z:\sys\bin\calendar.exe', lMatchStr would contain calendar
                         * the values of the variables will be as follows
                         * lLastDirSepIndex = 10
                         * lAppNameIndex = 11
                         * lExeIndex = 19
                         *
                         * The below logic would make sure that the right process is killed
                         */
                        if((lAppNameIndex == (lLastDirSepIndex + 1)) && ((lAppNameIndex + lMatchStr.Length()) == lExeIndex)) {
                            RDEBUG("[CTerminalControlServer]-> Process with correct Filename found => Kill(0)");
                            process.Kill(0);
                        }
                    }
                }
            }
            else {
                RDEBUG_2("[CTerminalControlServer]-> Process.Open() returned %d", ret);
            }
        }
        if(KErrNone != ret) {
            RDEBUG_2("[CTerminalControlServer]-> findProcess.Next() returned %d", ret);
        }
    }
    RDEBUG("[CTerminalControlServer]-> StopProcessByFullNameL() <<<");
}