Esempio n. 1
0
	ProcessStatus POSIXProcess::getProcessStatus(){

		 int processStatus = 0;
		 int waitpidStatus = waitpid(processID(), &processStatus, WNOHANG);

		 if(waitpidStatus == 0)
			 return RUNNING;
		 if(waitpidStatus < 0){
			 std::ostringstream buf;
			 buf << processID();
			 POSIXUtils::printError("getProcessStatus", "waitpid", buf.str());
			 return UNKNOWN;
		 }
		 else{
			 if(WIFEXITED(processStatus))
				 return NORMAL_EXIT;
			 if(WIFSIGNALED(processStatus)){
				if((WTERMSIG(processStatus) == SIGKILL) || (WTERMSIG(processStatus) == SIGTERM))
					return KILLED;
				else
					return ABNORMAL_EXIT;
			 }
		 }

		 return UNKNOWN;
	}
Esempio n. 2
0
	int POSIXProcess::killProcess(){
	    int killStatus = kill(processID(), SIGTERM);
		if(killStatus != 0){
			POSIXUtils::printError("killProcess", "kill");
			std::ostringstream buf;
			buf << processID();
			throw SystemOperationException(errno, 
				"POSIXProcess::killProcess: could not kill process: " + buf.str() + ". Error description: " + strerror(errno));
		}
		return killStatus;
	}
// -----------------------------------------------------------------------------
// Function that starts the test process.
// -----------------------------------------------------------------------------
//
static void RunServerL( const TDesC &aParameter )
    {
    COMPONENT_TRACE( ( _L( "SenSrvTestProcess - RunServerL(name=%S)" ),&aParameter ) );
   
    TInt processID( 0 );
    TLex parameter( aParameter );
    parameter.Val( processID );   
    
    TTime now;        
    now.HomeTime();
    TBuf<50> processName;           
    processName.Format( KSensrvTestProcessName, now.Int64() ); 
    User::RenameProcess( processName );
   
   
    // Set process priority
    RProcess svrProcess;
    svrProcess.SetPriority( EPriorityHigh );
    
    // Create and install the active scheduler we need
    CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
    CleanupStack::PushL(scheduler);
              
    CActiveScheduler::Install( scheduler );
        
    CSensrvTestObserver* observer = CSensrvTestObserver::NewLC( processID );
    
    
    // Initialisation complete, now signal the client
    RProcess::Rendezvous(KErrNone);

    // Ready to run
    COMPONENT_TRACE( ( _L( "SenSrvTestProcess - RunServer() - Starting scheduler..." )) );
    CActiveScheduler::Start();
    
    COMPONENT_TRACE( ( _L( "SenSrvTestProcess - RunServer() - Scheduler stopped" )) );

    // Cleanup
    CleanupStack::PopAndDestroy(observer);
    CleanupStack::PopAndDestroy(scheduler);
    
    COMPONENT_TRACE( ( _L( "SenSrvTestProcess - RunServer() - return" )) );
    }
Esempio n. 4
0
int main( int argc, char * argv[] )
{
	int result=0;

#ifdef Q_OS_WIN
	hMutex = CreateMutex( NULL, true, L"FreezerSingleProcessMutex");
	if (hMutex == NULL) {
		LOG_5( "Error: Couldn't create mutex, exiting" );
		return false;
	}
	if( GetLastError() == ERROR_ALREADY_EXISTS ) {
		LOG_5( "Error: Another process owns the mutex, exiting" );
		QList<int> pids;
		if( pidsByName( "freezer.exe", &pids ) ) {
			int otherProcessId = pids[0];
			if( otherProcessId == processID() ) {
				if( pids.size() < 2 )
					return false;
				otherProcessId = pids[1];
			}
			LOG_5( "Trying to find window with process pid of " + QString::number( otherProcessId ) );
			EnumWindows( AFEnumWindowsProc, LPARAM(otherProcessId) );
		}
		return false;
	}

	QLibrary excdll( "exchndl.dll" );
	if( !excdll.load() ) {
		qWarning( excdll.errorString().toLatin1().constData() );
	}
	disableWindowsErrorReporting( "assburner.exe" );

#endif

    signal(SIGSEGV, oops_handler);
    signal(SIGABRT, oops_handler);
	QApplication a(argc, argv);

    if( !initConfig( "freezer.ini" ) ) {
#ifndef Q_OS_WIN
        // Fallback if the config file does not exist in the current folder
        if( !initConfig( "/etc/ab/freezer.ini" ) )
#endif
        return -1;
    }

#ifdef Q_OS_WIN
	QString cp = "h:/public/" + getUserName() + "/Blur";
	if( !QDir( cp ).exists() )
		cp = "C:/Documents and Settings/" + getUserName();
	initUserConfig( cp + "/freezer.ini" );
#else
	initUserConfig( QDir::homePath() + "/.freezer" );
#endif

    initStone( argc, argv );
    classes_loader();
    initStoneGui();
	{
		JobList showJobs;
		bool showTime = false;
        QString currentView;
        QStringList loadViewFiles;

		for( int i = 1; i<argc; i++ ){
			QString arg( argv[i] );
			if( arg == "-h" || arg == "--help" )
			{
				LOG_1( QString("Freezer v") + VERSION );
				LOG_1( "Options:" );
				LOG_1( "-current-render" );
				LOG_1( "\tShow the current job that is rendering on this machine\n" );
				LOG_1( "-show-time" );
				LOG_1( "\tOutputs summary of time executed for all sql statement at program close\n" );
				LOG_1( "-user USER" );
				LOG_1( "\tSet the logged in user to USER: Requires Admin Privs" );
				LOG_1( "-current-view VIEWNAME" );
				LOG_1( "\tMake VIEWNAME the active view, once they are all loaded" );
				LOG_1( "-load-view FILE" );
				LOG_1( "\tRead a saved view config from FILE" );
				LOG_1( stoneOptionsHelp() );
				return 0;
			}
			else if( arg.endsWith("-show-time") )
				showTime = true;
			else if( arg.endsWith( "-current-render" ) ) {
				showJobs = Host::currentHost().activeAssignments().jobs();
			}
			else if( arg.endsWith("-user") && (i+1 < argc) ) {
				QString impersonate( argv[++i] );
				if( User::hasPerms( "User", true ) ) // If you can edit users, you can login as anyone
					User::setCurrentUser( impersonate );
			}
            else if( arg.endsWith("-current-view") && (i+1 < argc) ) {
				currentView = QString( argv[++i] );
            }
            else if( arg.endsWith("-load-view") && (i+1 < argc) ) {
                loadViewFiles << QString(argv[++i]);
            }
		}

		// Share the database across threads, each with their own connection
		FreezerCore::setDatabaseForThread( classesDb(), Connection::createFromIni( config(), "Database" ) );
		
		{
            loadPythonPlugins();
			MainWindow m;
			IniConfig & cfg = userConfig();
			cfg.pushSection( "MainWindow" );
			QStringList fg = cfg.readString( "FrameGeometry", "" ).split(',');
			cfg.popSection();
			if( fg.size()==4 ) {
				m.resize( QSize( fg[2].toInt(), fg[3].toInt() ) );
				m.move( QPoint( fg[0].toInt(), fg[1].toInt() ) );
			}
			if( showJobs.size() )
				m.jobPage()->setJobList( showJobs );
            foreach( QString viewFile, loadViewFiles )
                m.loadViewFromFile( viewFile );
            if( !currentView.isEmpty() )
                m.setCurrentView( currentView );
			m.show();
			result = a.exec();
			if( showTime ){
				Database * tm = Database::current();
				LOG_5( 			"                  Sql Time Elapsed" );
				LOG_5(			"|   Select  |   Update  |  Insert  |  Delete  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1    |     %2    |    %3    |    %4    |    %5   |\n")
					.arg( tm->elapsedSqlTime( Table::SqlSelect ) )
					.arg( tm->elapsedSqlTime( Table::SqlUpdate ) )
					.arg( tm->elapsedSqlTime( Table::SqlInsert ) )
					.arg( tm->elapsedSqlTime( Table::SqlDelete ) )
					.arg( tm->elapsedSqlTime() )
				);
				LOG_5( 			"                  Index Time Elapsed" );
				LOG_5(			"|   Added  |   Updated  |  Incoming  |  Deleted  |  Search  |  Total  |" );
				LOG_5( 			"-----------------------------------------------" );
				LOG_5( QString(	"|     %1     |     %2    |    %3    |    %4   |    %5    |   %6    |\n")
					.arg( tm->elapsedIndexTime( Table::IndexAdded ) )
					.arg( tm->elapsedIndexTime( Table::IndexUpdated ) )
					.arg( tm->elapsedIndexTime( Table::IndexIncoming ) )
					.arg( tm->elapsedIndexTime( Table::IndexRemoved ) )
					.arg( tm->elapsedIndexTime( Table::IndexSearch ) )
					.arg( tm->elapsedIndexTime() )
				);
				tm->printStats();
			}
		}
	}
	shutdown();
#ifdef Q_OS_WIN
	CloseHandle( hMutex );
#endif
	return result;
}