// DoBuild //------------------------------------------------------------------------------ /*virtual*/ Node::BuildResult ExecNode::DoBuild( Job * job ) { // If the workingDir is empty, use the current dir for the process const char * workingDir = m_WorkingDir.IsEmpty() ? nullptr : m_WorkingDir.Get(); AStackString<> fullArgs( m_Arguments ); fullArgs.Replace( "%1", m_SourceFile->GetName().Get() ); fullArgs.Replace( "%2", GetName().Get() ); EmitCompilationMessage( fullArgs ); // spawn the process Process p; bool spawnOK = p.Spawn( m_Executable->GetName().Get(), fullArgs.Get(), workingDir, FBuild::Get().GetEnvironmentString() ); if ( !spawnOK ) { FLOG_ERROR( "Failed to spawn process for '%s'", GetName().Get() ); return NODE_RESULT_FAILED; } // capture all of the stdout and stderr AutoPtr< char > memOut; AutoPtr< char > memErr; uint32_t memOutSize = 0; uint32_t memErrSize = 0; p.ReadAllData( memOut, &memOutSize, memErr, &memErrSize ); ASSERT( !p.IsRunning() ); // Get result int result = p.WaitForExit(); // did the executable fail? if ( result != m_ExpectedReturnCode ) { // something went wrong, print details Node::DumpOutput( job, memOut.Get(), memOutSize ); Node::DumpOutput( job, memErr.Get(), memErrSize ); FLOG_ERROR( "Execution failed (error %i) '%s'", result, GetName().Get() ); return NODE_RESULT_FAILED; } // update the file's "last modified" time m_Stamp = FileIO::GetFileLastWriteTime( m_Name ); return NODE_RESULT_OK; }
pid_t sysexec::doExec(const QString & execPath, int gid, int uid, const QValueList<QCString> & args, const QValueList<QCString> & env ) { //zEnter(); pid_t pid; pid = ::vfork(); if ( 0 == pid ) { int nv = getpriority( PRIO_PROCESS, 0 ); nice( -nv ); for ( int fd = 3; fd < 100; fd++ ) { ::close( fd ); } setSameGidUid(gid, uid); //set enviroments setEnv(env); //generate arguement QValueList<QCString> fullArgs(args); fullArgs.prepend(QFile::encodeName( execPath )); char ** argList = stringListToStr(fullArgs); if ( ::execv( QFile::encodeName( execPath ) ,argList) < 0 ) { perror( "::execl error:" ); } ::_exit( -1 ); } //zLeave(); return pid; }
bool SSHConnectionCLI::executeSCPFrom(const QString& source, const QString& dest, const QStringList& args, QString* stdout_str, QString* stderr_str, int* ec) { QProcess proc; // Start with input args QStringList fullArgs(args); // Add port number fullArgs << "-P" << QString::number(m_port); // Add source fullArgs << QString("%1%2%3:%4") .arg(m_user) .arg(m_user.isEmpty() ? "" : "@") .arg(m_host) .arg(source); // Add destination fullArgs << dest; proc.start("scp", fullArgs); int timeout_ms = 60000; // one minute if (!proc.waitForStarted(timeout_ms)) { qWarning() << QString("Failed to start scp command with args \"%1\" " "after %2 seconds.") .arg(fullArgs.join(",")) .arg(timeout_ms / 1000); return false; } proc.closeWriteChannel(); if (!proc.waitForFinished(timeout_ms)) { qWarning() << QString("scp command with args \"%1\" failed to finish " "within %2 seconds.") .arg(fullArgs.join(",")) .arg(timeout_ms / 1000); return false; } if (proc.exitCode() != 0) { qWarning() << QString("scp command with args \"%1\" failed with an exit " "code of %2.") .arg(fullArgs.join(",")) .arg(proc.exitCode()) << "\nstdout:\n" << QString(proc.readAllStandardOutput()) << "\nstderr:\n" << QString(proc.readAllStandardError()); return false; } if (stdout_str != nullptr) *stdout_str = QString(proc.readAllStandardOutput()); if (stderr_str != nullptr) *stderr_str = QString(proc.readAllStandardError()); if (ec != nullptr) *ec = proc.exitCode(); proc.close(); return true; }