Exemple #1
0
int System::runAsRoot( QStringList & S, MyProcess * Prc ) {
    char * usr = getenv("USER");

    if( S.count() == 0 ) {
      // close loophole to start shell
      return 8888;
    }
    if( usr == 0 || strcmp( usr, "root" ) ) {
      // unknown or non-root user -> use SUDO
      S.prepend( "sudo" );
    }

    if( getenv( "NS2TESTMODE" ) ) {
      odebug << "TESTMODE !!! execute "
            << S.join( " ")
            << oendl;
    } else {
      MyProcess * P;

      if( Prc ) {
        P = Prc;
      } else {
        P = new MyProcess();
        emit processEvent( tr("Command : ") + S.join( " " ) );

        connect( P,
                 SIGNAL( stdoutLine( const QString & ) ),
                 this,
                 SIGNAL( stdoutLine( const QString & ) ) );

        connect( P,
                 SIGNAL( stderrLine( const QString & ) ),
                 this,
                 SIGNAL( stderrLine( const QString & ) ) );

        connect( P,
                 SIGNAL(processExited(MyProcess*) ),
                 this, SLOT
                 (SLOT_ProcessExited(MyProcess*) ) );
      }

      P->process() << S;

      Log(("Executing %s\n", S.join( " " ).latin1() ));

      if( ! P->process().start( OProcess::DontCare,
                      OProcess::AllOutput ) ) {
        odebug << "Error starting " << S << oendl;
        if( ! Prc )
          delete P;
        // error starting app
        return 0;
      }
      odebug << "Started " << S << oendl;
    }

    // all is fine
    return 1;
}
Exemple #2
0
MyProcess* Git::runAsync(SCRef runCmd, QObject* receiver, SCRef buf) {

	MyProcess* p = new MyProcess(parent(), this, workDir, errorReportingEnabled);
	if (!p->runAsync(runCmd, receiver, buf)) {
		delete p;
		p = NULL;
	}
	return p; // auto-deleted when done
}
int                     main()
{
    MyProcess           *process = new MyProcess();
    int                 test = 42;
    
    std::cout << test << std::endl;
    process->test();
    std::cout << test << std::endl;
    system("pause");
	
    return (false);
}
Exemple #4
0
int System::execAsUser( QStringList & SL, bool Synchronous ) {
      MyProcess * P = new MyProcess();
      CurrentQPEUser CU = NSResources->currentUser();
      char * usr = getenv("USER");

      if( usr == 0 ||
          strcmp( usr, "root" ) == 0 ) {
        // find user running qpe
        if( CU.UserName.isEmpty() ) {
          // if we come here, the exec was not successfull
          Log(("User not known \n" ));
          return 0;
        }
      }

      // now we are ready to exec the requested command
      setuid( CU.Uid );
      setgid( CU.Gid );

      for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
        QString X;
        QStringList SL;
        X = CU.EnvList[i];
        SL = QStringList::split( "=", X );
        P->process().setEnvironment( SL[0], SL[1] );
      }

      P->process() << SL;

      emit processEvent( tr("Command : ") + SL.join( " " ) );

      Log(("Executing as user %s : %s\n",
            CU.UserName.latin1(),
            SL.join( " " ).latin1() ));

      P->setEchoMode( Synchronous );

      bool rv = P->process().start(
            (Synchronous) ? OProcess::Block :
                            OProcess::DontCare,
            (Synchronous) ? OProcess::AllOutput :
                            OProcess::NoCommunication );
      delete P;

      if( ! rv ) {
        // if we come here, the exec was not successfull
        Log(("Could not exec : %d\n", errno ));
      }

      return rv;
}
	  void insert(MyProcess p){
			int blockReq ;
			blockReq = p.getSize()/partSize;
	  	   
			 if(p.getSize()%partSize)
			 	blockReq++;
			 
	  	   int pos;
			pos = findSpace(blockReq);
			
		   for(int i=0; i< blockReq; ++i){
				parts[pos+i] = true;
				procs[pos+i] = p.getPid();
		   }
   	  }
Exemple #6
0
int main()
{
   WordVector  v;
   for (size_t j=0; j<10; j++) {
      v.push_back(Word(j*10));
   }
   WordVectorPtr  p = boost::make_shared<const std::vector<Word> >(v);

   MyProcess   m;
   m.test(p);
   
   
   std::cout << "--- test\n";
   Word  x(100);
   std::cout << "x = " << x << std::endl;
   
   
   return 0;
}
void ExecButton::startProcess()
{
  QString at = evalAssociatedText().stripWhiteSpace();
  bool enabledStatus = isEnabled();
  if (m_blockGUI != None)
    setEnabled(false);
  if (m_blockGUI == GUI)
    KApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  MyProcess* process = new MyProcess(this);
  process->setBlocking(m_blockGUI == GUI);
  connect(process, SIGNAL(processExited(MyProcess*)), SLOT(processExited(MyProcess*)));
  m_output = process->run(at);
  if (m_blockGUI == GUI)
  {
    KApplication::restoreOverrideCursor();
    if (writeStdout())
      cout << m_output << flush;
  }
  setEnabled(enabledStatus);
}
void ANROptimize::getCompareResult() {
	//create process
	MyProcess* process = new MyProcess();
	process->Create(IDD_PROCESS,NULL);
	process->MyProcessInfo="请稍后,正在生成邻区优化前后对比结果...";
	process->UpdateData(FALSE);
	process->ShowWindow(SW_SHOW);
	process->RedrawWindow();

	/*
	vector<double> percentVector;
	vector<double> cntVector;
	string tableName = "AOldNRT";
	double percentAnr = getSwitchPercent(tableName);
	double cntAnr = getCnt(tableName);
	percentVector.push_back(1.0*percentAnr*100);
	cntVector.push_back(cntAnr);

	tableName = "ANRT";
	percentAnr = getSwitchPercent(tableName);
	cntAnr = getCnt(tableName);
	percentVector.push_back(1.0*percentAnr*100);
	cntVector.push_back(cntAnr);
	*/
	//画图  运算得到的数据
	
	double percentArray[2] = {0.971*100,0.942*100};  
	vector<double> percentVector(percentArray,percentArray+2);
	double cntArray[2] = {5.5,4};  
	vector<double> cntVector(cntArray,cntArray+2);
	

	//close process
	process->DestroyWindow();
	delete process;
	process = NULL;

	DrawAnrPic::drawPic(percentVector,cntVector);
}