Пример #1
0
/*
 * Try to populate a req struct with
 * all the various arguments and
 * parameters.
 */
int initReq(struct extRequest *req) {

  req->url = NULL;
  req->args = NULL;
  req->numargs = 0;

  if(!parseURL(req)) {
    exitStatus(400, "Error parsing URL.\n");
    return 0;
  } 

  if(!parseArguments(req)) {
    exitStatus(400, "Error parsing passed arguments or values.\n");
    return 0;
  }

  /*
   * The callback function is not required,
   * because some JSON-producing webservices
   * provide their own parameter for this.
   */
  parseCallback(req);

  return 1;

}
Пример #2
0
void KompareProcess::slotProcessExited( KProcess* /* proc */ )
{
	// exit status of 0: no differences
	//                1: some differences
	//                2: error but there may be differences !
	kdDebug(8101) << "Exited with exit status : " << exitStatus() << endl;
	emit diffHasFinished( normalExit() && exitStatus() != 0 );
}
Пример #3
0
bool Process::failed()
// ----------------------------------------------------------------------------
//   Return true if the process crashed or returned a non-zero value
// ----------------------------------------------------------------------------
{
  return (exitStatus() != QProcess::NormalExit) || exitCode();
}
Пример #4
0
keyFileTask::~keyFileTask()
{
	close( m_qfread ) ;
	close( m_qfwrite ) ;
	if( m_status != keyFileTask::cancelled ){
		QFile::setPermissions( m_path,QFile::ReadOwner|QFile::WriteOwner ) ;
	}
	emit exitStatus( m_status ) ;
}
Пример #5
0
void KJavaProcess::slotExited()
{
    int status = -1;
    if ( exitStatus() == NormalExit ) {
     status = exitCode();
    }
    kDebug(6100) << "jvm exited with status " << status; 
    emit exited(status);
}
Пример #6
0
int KProcess::execute(int msecs)
{
    start();
    if (!waitForFinished(msecs)) {
        kill();
        waitForFinished(-1);
        return -2;
    }
    return (exitStatus() == QProcess::NormalExit) ? exitCode() : -1;
}
Пример #7
0
void ScProcess::postQuitNotification()
{
    QString message;
    switch (exitStatus()) {
    case QProcess::CrashExit:
        message = tr("Interpreter has crashed or stopped forcefully. [Exit code: %1]\n").arg(exitCode());
        break;
    default:
        message = tr("Interpreter has quit. [Exit code: %1]\n").arg(exitCode());
    }
    emit scPost(message);
}
Пример #8
0
std::string ProcessReturnCode::str() const {
  switch (state()) {
  case NOT_STARTED:
    return "not started";
  case RUNNING:
    return "running";
  case EXITED:
    return to<std::string>("exited with status ", exitStatus());
  case KILLED:
    return to<std::string>("killed by signal ", killSignal(),
                           (coreDumped() ? " (core dumped)" : ""));
  }
  CHECK(false);  // unreached
}
Пример #9
0
void TEPty::donePty()
{
    emit done(exitStatus());
}
Пример #10
0
void Task::openMountPointTask()
{
	auto r       = utility::Task( QString( "%1 \"%2\"" ).arg( m_folderOpener ).arg( m_mpoint ) ) ;
	m_exitCode   = r.exitCode() ;
	m_exitStatus = r.exitStatus() ;
}
/** Runs the command.
	@param timeout timeout to use for waiting when starting and when waiting for the process to finish
	@return true on success
*/
bool ExternalCommand::run(int timeout)
{
	return start(timeout) && waitFor(timeout) && exitStatus() == 0;
}
Пример #12
0
bool ExportSpreadsheet::exportSpreadsheet(const analysisdriver::SimpleProject& project)
{
    //Make sure a QApplication exists
    openstudio::Application::instance().application();

    //get the project's directory
    openstudio::path projectPath = project.projectDir();

    LOG_FREE(Debug, "ExportSpreadsheet", "Starting export of projectPath:" << toString(projectPath));

    openstudio::path rubyPath;
#if defined(Q_OS_WIN)
    rubyPath = getOpenStudioEmbeddedRubyPath() / toPath("bin/ruby.exe");
#else
    rubyPath = "ruby";
#endif

    openstudio::path rubyIncludePath = getOpenStudioRubyIncludePath();
    if (!boost::filesystem::exists(rubyIncludePath)) {
        LOG_FREE(Error, "ExportSpreadsheet", "Ruby include path '" << rubyIncludePath << "' cannot be found.");
        return false;
    }

    openstudio::path scriptPath = getOpenStudioRubyScriptsPath() / openstudio::toPath("openstudio/analysisdriver/ExportToSpreadsheet.rb");
    if (!boost::filesystem::exists(scriptPath)) {
        LOG_FREE(Error, "ExportSpreadsheet", "ExportToSpreadsheet script '" << scriptPath << "' cannot be found.");
        return false;
    }

    QStringList args;
    args << "-I";
    args << openstudio::toQString(rubyIncludePath);
    args << openstudio::toQString(scriptPath);
    args << openstudio::toQString(projectPath);

    auto p = new QProcess();
    p->start(toQString(rubyPath), args);

    if (!p->waitForStarted(30000)) {
        p->terminate();
        p->deleteLater();
        LOG_FREE(Error, "ExportSpreadsheet", "Process failed to start");
        return false;
    }

    if (!p->waitForFinished(300000)) {
        p->terminate();
        p->deleteLater();
        LOG_FREE(Error, "ExportSpreadsheet", "Process failed to complete");
        return false;
    }

    QByteArray error = p->readAllStandardError();
    std::string errorString = toString(QString(error));
    LOG_FREE(Debug, "ExportSpreadsheet", "StandardError:" << std::endl << errorString);
    QByteArray output = p->readAllStandardOutput();
    std::string outputString = toString(QString(output));
    LOG_FREE(Debug, "ExportSpreadsheet", "StandardOutput:" << std::endl << outputString);

    // remove previous export
    openstudio::path exportPath = projectPath / toPath("analysis_spreadsheet_export");
    openstudio::path modelMeasuresCSV = exportPath / toPath("spreadsheet_model_measures_export.csv");
    openstudio::path energyplusMeasuresCSV = exportPath / toPath("spreadsheet_energyplus_measures_export.csv");
    openstudio::path reportingMeasuresCSV = exportPath / toPath("spreadsheet_reporting_measures_export.csv");
    openstudio::path outputsCSV = exportPath / toPath("spreadsheet_outputs_export.csv");

    bool result = ((p->exitStatus() == QProcess::NormalExit) &&
                   boost::filesystem::exists(modelMeasuresCSV) &&
                   boost::filesystem::exists(energyplusMeasuresCSV) &&
                   boost::filesystem::exists(reportingMeasuresCSV) &&
                   boost::filesystem::exists(outputsCSV));

    p->deleteLater();
    return result;
}
Пример #13
0
int Process::start()
{
  logTrace("Process::start");

  int childIn[2]  = { -1, -1 };
  int childOut[2] = { -1, -1 };
  int childErr[2] = { -1, -1 };

  //
  // We either have 2 parameters and this process
  // will exec() a new command, or we have one or
  // none and this process will yield control to
  // a function.
  //

  if (function_ == NULL && (parameters_[0] == NULL ||
          parameters_[1] == NULL))
  {
    logTest("Process::start", "Can't start the process "
                "without a command or function");

    logError("Process::start", ESET(EPERM));

    return -1;
  }

  #ifdef TEST

  if (function_ == NULL)
  {
    logTest("Process::start", "Executing command '%s'",
                parameters_[0]);

    for (int i = 1; i < parametersLimit_ &&
             parameters_[i] != NULL; i++)
    {
      logTest("Process::start", "Parameter [%d] is '%s'",
                  i, parameters_[i]);
    }
  }
  else
  {
    logTest("Process::start", "Executing function at %p",
                function_);

    logTest("Process::start", "Passing data as %p",
                parameters_[0]);
  }

  for (int i = 0; i < environmentLimit_ &&
           environment_[i] != NULL; i++)
  {
    logTest("Process::start", "Environment [%d] is '%s'",
                i, environment_[i]);
  }

  #endif

  //
  // Create the pipes that will be used to replace
  // the standard descriptors.
  //

  if ((in_ == -1 && pipe(childIn) != 0) ||
          (out_ == -1 && pipe(childOut) != 0) ||
              (err_ == -1 && pipe(childErr) != 0))
  {
    logError("Process::start::pipe", EGET());

    return -1;
  }

  //
  // The fork() on Cygwin can show intermittent
  // failures. In this case we try again after
  // some time.
  //

  #ifdef __CYGWIN32__

  switch (pid_ = waitFork())

  #else

  switch (pid_ = fork())

  #endif

  {
    case -1:
    {
      //
      // An error was encountered.
      //

      logError("Process::start::fork", EGET());

      if (in_ == -1)
      {
        close(childIn[0]);
        close(childIn[1]);
      }

      if (out_ == -1)
      {
        close(childOut[0]);
        close(childOut[1]);
      }

      if (err_ == -1)
      {
        close(childErr[0]);
        close(childErr[1]);
      }

      return -1;
    }
    case 0:
    {
      //
      // We are the child process.
      //

      logTest("Process::start", "Child running with pid %d", getpid());

      //
      // Drop the privileges.
      //

      if (privileged_ != 1)
      {
        logTest("Process::start", "Child dropping the permissions");

        setgid(getgid());
        setuid(getuid());
      }

      //
      // Let the input descriptor inherited from the
      // parent replace the standard descriptors. The
      // descriptor can be either the one set by the
      // parent or our end of the pipe we created be-
      // fore forking.
      //
      // Handle the standard input.
      //

      if (in_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for input", childIn[0], childIn[1]);

        if (childIn[0] != 0)
        {
          dup2(childIn[0], 0);

          close(childIn[0]);
        }

        close(childIn[1]);
      }
      else if (in_ != 0)
      {
        logTest("Process::start", "Child replacing input %d", in_);

        dup2(in_, 0);

        if (in_ != out_ && in_ != err_)
        {
          close(in_);
        }
      }
      else
      {
        logTest("Process::start", "Child inherited input");
      }

      in_ = 0;

      //
      // Handle the standard output.
      //

      if (out_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for output", childOut[0], childOut[1]);

        if (childOut[1] != 1)
        {
          dup2(childOut[1], 1);

          close(childOut[1]);
        }

        close(childOut[0]);
      }
      else if (out_ != 1)
      {
        logTest("Process::start", "Child replacing output %d", out_);

        dup2(out_, 1);

        if (out_ != err_)
        {
          close(out_);
        }
      }
      else
      {
        logTest("Process::start", "Child inherited output");
      }

      out_ = 1;

      //
      // Handle the standard error.
      //

      if (err_ == -1)
      {
        logTest("Process::start", "Child replacing pipe "
                    "%d and %d for error", childErr[0], childErr[1]);

        if (childErr[1] != 2)
        {
          dup2(childErr[1], 2);

          close(childErr[1]);
        }

        close(childErr[0]);
      }
      else if (err_ != 2)
      {
        logTest("Process::start", "Child replacing error %d", err_);

        dup2(err_, 2);

        close(err_);
      }
      else
      {
        logTest("Process::start", "Child inherited error");
      }

      err_ = 2;

      //
      // Let the pid be our own pid.
      //

      pid_ = getpid();

      logTest("Process::start", "Child has descriptors "
                  "%d, %d, %d and pid %d", in_, out_, err_, pid_);

      //
      // Set the new environment for the process.
      //

      for (int i = 0; i < environmentLimit_ &&
               environment_[i] != NULL; i++)
      {
        putenv(environment_[i]);
      }

      //
      // Either execute the requested command or
      // yield control to the function.
      //

      if (parameters_[1] != NULL)
      {
        if (execvp(parameters_[0], parameters_ + 1) == -1)
        {
          logTest("Process::start", "Child failed to execute the command");

          logError("Process::start::execvp", EGET());
        }

        exitStatus(-1);
      }
      else
      {
        int result = function_((void *) parameters_[0]);

        exitStatus(result);
      }
    }
    default:
    {
      //
      // We are the parent process.
      //

      logTest("Process::start", "Parent started child with pid %d", pid_);

      if (in_ == -1)
      {
        close(childIn[0]);

        in_ = childIn[1];
      }

      if (out_ == -1)
      {
        close(childOut[1]);

        out_ = childOut[0];
      }

      if (err_ == -1)
      {
        close(childErr[1]);

        err_ = childErr[0];
      }

      logTest("Process::start", "Parent using descriptors %d, %d, %d",
                  in_, out_, err_);

      return 1;
    }
  }
}