Exemplo n.º 1
0
int Booster::run(SocketManager * socketManager)
{
    if (!m_appData->fileName().empty())
    {
        // We can close sockets here because
        // socket FD is passed to daemon already
        if (socketManager)
        {
            socketManager->closeAllSockets();
        }

        // Execute the binary
        Logger::logDebug("Booster: invoking '%s' ", m_appData->fileName().c_str());
        try {
            return launchProcess();
        } catch (const std::runtime_error &e) {
            Logger::logError("Booster: Failed to invoke: %s\n", e.what());
            // Also log to the terminal so the error appears on the terminal too
            fprintf(stderr, "Failed to invoke: %s\n", e.what());
            return EXIT_FAILURE;
        }
    }
    else
    {
        Logger::logError("Booster: nothing to invoke\n");
        return EXIT_FAILURE;
    }
}
Exemplo n.º 2
0
        void ProgramRunner::start() {
            int pipeEnds[ 2 ];
            int status = pipe(pipeEnds);
            if (status != 0) {
                error() << "failed to create pipe: " << errnoWithDescription() << endl;
                fassertFailed(16701);
            }

            fflush( 0 );
            launchProcess(pipeEnds[1]); //sets _pid

            {
                stringstream ss;
                ss << "shell: started program (sh" << _pid << "): ";
                for (unsigned i = 0; i < _argv.size(); i++) {
                    ss << " " << _argv[i];
                }
                log() << ss.str() << endl;
            }

            if ( _port > 0 )
                registry.registerPort( _port, _pid, pipeEnds[ 1 ] );
            else
                registry.registerPid( _pid, pipeEnds[ 1 ] );
            _pipe = pipeEnds[ 0 ];
        }
Exemplo n.º 3
0
void FolderView::navigateToPath(const QString &path)
{
  qDebug() << "FolderView::navigateToPath:" << path;

  QFileInfo info(path);

  if (! info.exists()) {
    qDebug() << "path doesn't exists.";
    return;
  }

  if (info.isDir()) {
    qDebug() << "is a directory";

    setPath(path);
    //scrollTo(fileSystemModel()->index(path));

    //OEG::Qt::TabWidget *tab = qobject_cast<OEG::Qt::TabWidget *>(parent());

    FolderManager *fm = folderManager();
    if (! fm) {
      qDebug() << "No fm";
      return;
    }

    OEG::Qt::TabWidget *tabs = fm->currentTabWidget();
    if (! tabs) {
      qDebug() << "No tabs"; // TODO
      return;
    }
    else {
      int index = tabs->currentIndex();
      if (index >= 0) {
        qDebug() << "New tab title:" << path;
        tabs->setTabText(index, path);
      }
    }

    return;
  }

  if (info.isFile()) {
    qDebug() << "is a file";

    if (info.completeSuffix() == "exe") {
      launchProcess(info.absoluteFilePath());
    }

    return;
  }
}
Exemplo n.º 4
0
/**
  * Appelé à la fin de conversion d'une image
  */
void Converter::convertFinished()
{
    _countFinished++;
    emit imageHasFinished(_countFinished);
    if (_count < _list.size())
    {
        launchProcess(_list[_count],_size);
        _count++;
    }
    if (_countFinished == _list.size())
    {
        emit taskCompleted();
    }
}
Exemplo n.º 5
0
/**
  * Lance la conversion d'images
  */
void Converter::start(QStringList list, QSize size, int max, QString dest)
{
    //On inscrit les nouvelles valeurs dans les attributs.
    _size = size;
    _max = max;
    _count = 0;
    _countFinished = 0 ;
    _dest = dest;
    _list = list;
    //On boucle tant que on a pas dépassé le maximum
    for (int i = 0; i < list.size() && _count < _max ; i++)
    {
        launchProcess(_list[i],size);
        _count++;
    }
}
Exemplo n.º 6
0
int Booster::run(SocketManager * socketManager)
{
    if (!m_appData->fileName().empty())
    {
        // We can close sockets here because
        // socket FD is passed to daemon already
        if (socketManager)
        {
            socketManager->closeAllSockets();
        }

        // Execute the binary
        Logger::logDebug("Booster: invoking '%s' ", m_appData->fileName().c_str());
        return launchProcess();
    }
    else
    {
        Logger::logError("Booster: nothing to invoke\n");
        return EXIT_FAILURE;
    }
}
Exemplo n.º 7
0
        void ProgramRunner::start() {
            int pipeEnds[ 2 ];
            verify( pipe( pipeEnds ) != -1 );

            fflush( 0 );
            launchProcess(pipeEnds[1]); //sets _pid

            {
                stringstream ss;
                ss << "shell: started program";
                for (unsigned i=0; i < _argv.size(); i++)
                    ss << " " << _argv[i];
                log() << ss.str() << endl;
            }

            if ( _port > 0 )
                registry.registerPort( _port, _pid, pipeEnds[ 1 ] );
            else
                registry.registerPid( _pid, pipeEnds[ 1 ] );
            _pipe = pipeEnds[ 0 ];
        }
Exemplo n.º 8
0
void ProgramRunner::start() {
    int pipeEnds[2];

    {
        // NOTE(JCAREY):
        //
        // We take this lock from before our call to pipe until after we close the write side (in
        // the parent) to avoid leaking fds from threads racing around fork().  I.e.
        //
        // Thread A: calls pipe()
        // Thread B: calls fork()
        // A: sets cloexec on read and write sides
        // B: has a forked child with open fds
        // A: spawns a child thread to read it's child process's stdout
        // A: A's child process exits
        // A: wait's on A's reader thread in de-register
        // A: deadlocks forever (because the child reader thread stays in read() because of the open
        //    fd in B)
        //
        // Holding the lock for the duration of those events prevents the leaks and thus the
        // associated deadlocks.
        stdx::lock_guard<stdx::mutex> lk(_createProcessMtx);
        int status = pipe(pipeEnds);
        if (status != 0) {
            const auto ewd = errnoWithDescription();
            error() << "failed to create pipe: " << ewd;
            fassertFailed(16701);
        }
#ifndef _WIN32
        // The calls to fcntl to set CLOEXEC ensure that processes started by the process we are
        // about to fork do *not* inherit the file descriptors for the pipe. If grandchild processes
        // could inherit the FD for the pipe, than the pipe wouldn't close on child process exit. On
        // windows, instead the handle inherit flag is turned off after the call to CreateProcess.
        status = fcntl(pipeEnds[0], F_SETFD, FD_CLOEXEC);
        if (status != 0) {
            const auto ewd = errnoWithDescription();
            error() << "failed to set FD_CLOEXEC on pipe end 0: " << ewd;
            fassertFailed(40308);
        }
        status = fcntl(pipeEnds[1], F_SETFD, FD_CLOEXEC);
        if (status != 0) {
            const auto ewd = errnoWithDescription();
            error() << "failed to set FD_CLOEXEC on pipe end 1: " << ewd;
            fassertFailed(40317);
        }
#endif

        fflush(0);

        launchProcess(pipeEnds[1]);  // sets _pid

        // Close the write end of the pipe.
        safeClose(pipeEnds[1]);
    }

    if (_port >= 0) {
        registry.registerProgram(_pid, _port);
    } else {
        registry.registerProgram(_pid);
    }

    _pipe = pipeEnds[0];

    {
        stringstream ss;
        ss << "shell: started program (sh" << _pid << "): ";
        for (unsigned i = 0; i < _argv.size(); i++) {
            ss << " " << _argv[i];
        }
        log() << ss.str();
    }
}
Exemplo n.º 9
0
void Process::internalExec(const String programName,
                           const List<String>& args,
                           const List<String>& env,
                           bool mergeOutput)
{
    HANDLE hInputRead = INVALID_HANDLE_VALUE;
    HANDLE hInputWrite = INVALID_HANDLE_VALUE;
    HANDLE hOutputRead = INVALID_HANDLE_VALUE;
    HANDLE hOutputWrite = INVALID_HANDLE_VALUE;
    HANDLE hErrorRead = INVALID_HANDLE_VALUE;
    HANDLE hErrorWrite = INVALID_HANDLE_VALUE;
    SECURITY_ATTRIBUTES sa;
    DWORD errorNumber;

    if (m_hasStarted)
    {
        throw SystemException("Failed to create process: Cannot start two "
            "processes with one Process object");
    }

    // Set up the security attributes struct.
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;

    // Create the child input pipe.
    if (!::CreatePipe(&hInputRead, &hInputWrite, &sa, 0))
    {
        throw SystemException(String("Failed to create process. Couldn't create "
            "pipe: ") + WinUtil::getLastErrorMessage());
    }

    // Prevent the stdin write handle from being inherited
    if (!::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0))
    {
        errorNumber = ::GetLastError();
        closePipe(hInputRead, hInputWrite);
        throw SystemException(String("Failed to create process. Couldn't set "
            "handle inheritance: ") + WinUtil::getErrorMessage(errorNumber));
    }

    // Create the child output pipe.
    if (!::CreatePipe(&hOutputRead, &hOutputWrite, &sa, 0))
    {
        errorNumber = GetLastError();
        closePipe(hInputRead, hInputWrite);
        throw SystemException(String("Failed to create process. Couldn't create "
            "pipe: ") + WinUtil::getErrorMessage(errorNumber));
    }

    // Prevent the stdout read handle from being inherited
    if (!::SetHandleInformation(hOutputRead, HANDLE_FLAG_INHERIT, 0))
    {
        errorNumber = ::GetLastError();
        closePipe(hInputRead, hInputWrite);
        closePipe(hOutputRead, hOutputWrite);
        throw SystemException(String("Failed to create process. Couldn't "
            "set handle inheritance: ") + WinUtil::getErrorMessage(errorNumber));
    }

    if (!mergeOutput)
    {
        // Create the child error pipe.
        if (!::CreatePipe(&hErrorRead, &hErrorWrite, &sa, 0))
        {
            errorNumber = ::GetLastError();
            closePipe(hInputRead, hInputWrite);
            closePipe(hOutputRead, hOutputWrite);
            throw SystemException(String("Failed to create process. Couldn't "
                "create pipe: ") + WinUtil::getErrorMessage(errorNumber));
        }

        // Prevent the stderr read handle from being inherited
        if (!::SetHandleInformation(hErrorRead, HANDLE_FLAG_INHERIT, 0))
        {
            errorNumber = ::GetLastError();
            closePipe(hInputRead, hInputWrite);
            closePipe(hOutputRead, hOutputWrite);
            closePipe(hErrorRead, hErrorWrite);
            throw SystemException(String("Failed to create process. Couldn't "
                "set handle inheritance: ") + WinUtil::getErrorMessage(errorNumber));
        }
    }
    else
    {
        // If we are merging the output, just duplicate the stdout write
        // handle and make the child use it as its stderr

        if (!::DuplicateHandle(::GetCurrentProcess(), // Source Process
                               hOutputWrite, // Source HANDLE
                               ::GetCurrentProcess(), // Destination Process
                               &hErrorWrite, // Destination HANDLE address
                               0, // Access rights (ignored due to DUPLICATE_SAME_ACCESS)
                               TRUE, // Make the HANDLE inheritable
                               DUPLICATE_SAME_ACCESS)) // Use same access rights
        {
            closePipe(hInputRead, hInputWrite);
            closePipe(hOutputRead, hOutputWrite);
            throw SystemException(String("Failed to create process. Couldn't "
                "duplicate handle: ") + WinUtil::getLastErrorMessage());
        }
    }

    // Start the process
    m_processHandle = launchProcess(programName, args, env, hInputRead, hOutputWrite, hErrorWrite);

    // Close our copies of the pipe handles that the child process will use.
    ::CloseHandle(hInputRead);
    ::CloseHandle(hOutputWrite);
    ::CloseHandle(hErrorWrite);

    // Make stream objects
    m_stdin = new FileOutputStream(hInputWrite);
    m_stdout = new FileInputStream(hOutputRead);

    if (!mergeOutput)
    {
        m_stderr = new FileInputStream(hErrorRead);
    }

    m_hasStarted = true;
}