void task_2() { while(1) { currentPro = getCMD(); if(currentPro != 0) exec(currentPro); OS_DelayTimes(10); } }
int main(int argc, char **argv){ //Run all the actual code in a separate function to have as little memory usage // as possible aside from the main application when running //Make sure the XDG environment variables exist first LXDG::setEnvironmentVars(); //now get the command QString cmd, args, path; getCMD(argc, argv, cmd, args, path); //qDebug() << "Run CMD:" << cmd << args; //Now run the command (move to execvp() later?) if(!args.isEmpty()){ cmd.append(" \""+args+"\""); } int retcode = system( cmd.toUtf8() ); /* QProcess *p = new QProcess(); p->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); if(!path.isEmpty() && QFile::exists(path)){ p->setWorkingDirectory(path); } p->start(cmd+" \""+args+"\""); //Check the startup procedure while(!p->waitForStarted(5000)){ if(p->state() == QProcess::NotRunning){ //bad/invalid start qDebug() << "[lumina-open] Application did not startup properly:"<<cmd+" "+args; return p->exitCode(); }else if(p->state() == QProcess::Running){ //This just missed the "started" signal - continue break; } } //Now check up on it once every minute until it is finished while(!p->waitForFinished(60000)){ if(p->state() != QProcess::Running){ break; } //somehow missed the finished signal } int retcode = p->exitCode();*/ if(retcode!=0){ qDebug() << "[lumina-open] Application Error:" << retcode; } return retcode; }
int main(int argc, char **argv){ //Run all the actual code in a separate function to have as little memory usage // as possible aside from the main application when running //Make sure the XDG environment variables exist first LXDG::setEnvironmentVars(); //now get the command QString cmd, args, path; bool watch = true; //enable the crash handler by default (only disabled for some *.desktop inputs) getCMD(argc, argv, cmd, args, path, watch); //qDebug() << "Run CMD:" << cmd << args; //Now run the command (move to execvp() later?) if(cmd.isEmpty()){ return 0; } //no command to run (handled internally) qDebug() << "[lumina-open] Running Cmd:" << cmd; int retcode = 0; if(!watch && path.isEmpty()){ //Nothing special about this one - just start it detached (less overhead) QProcess::startDetached(cmd); }else{ //Keep an eye on this process for errors and notify the user if it crashes QString log; if(cmd.contains("\\\\")){ //Special case (generally for Wine applications) cmd = cmd.replace("\\\\","\\"); retcode = system(cmd.toLocal8Bit()); //need to run it through the "system" instead of QProcess }else{ QProcess *p = new QProcess(); p->setProcessEnvironment(QProcessEnvironment::systemEnvironment()); if(!path.isEmpty() && QFile::exists(path)){ //qDebug() << " - Setting working path:" << path; p->setWorkingDirectory(path); } p->start(cmd); //Now check up on it once every minute until it is finished while(!p->waitForFinished(60000)){ //qDebug() << "[lumina-open] process check:" << p->state(); if(p->state() != QProcess::Running){ break; } //somehow missed the finished signal } retcode = p->exitCode(); if( (p->exitStatus()==QProcess::CrashExit) && retcode ==0){ retcode=1; } //so we catch it later log = QString(p->readAllStandardError()); if(log.isEmpty()){ log = QString(p->readAllStandardOutput()); } } //qDebug() << "[lumina-open] Finished Cmd:" << cmd << retcode << p->exitStatus(); if( QFile::exists("/tmp/.luminastopping") ){ watch = false; } //closing down session - ignore "crashes" (app could have been killed during cleanup) if( (retcode > 0) && watch && !(retcode==1 && cmd.startsWith("pc-su ")) ){ //pc-su returns 1 if the user cancelles the operation qDebug() << "[lumina-open] Application Error:" << retcode; //Setup the application QApplication App(argc, argv); LuminaThemeEngine theme(&App); LUtils::LoadTranslation(&App,"lumina-open"); QMessageBox dlg(QMessageBox::Critical, QObject::tr("Application Error"), QObject::tr("The following application experienced an error and needed to close:")+"\n\n"+cmd ); if(!log.isEmpty()){ dlg.setDetailedText(log); } dlg.exec(); } } return retcode; }