コード例 #1
0
ファイル: Process.cpp プロジェクト: dyreshark/IntroUNIX
    void init()
    {
        execerror = 0;
        pipeClose(errpipes[0]);
        pipeClose(errpipes[1]);

        if (pipe(errpipes) == -1)
        {
            raiseError("Failed to init pipes for sig handler");
        }

        // set the read pipe to nonblocking communications
        if (fcntl(errorReadPipe(), F_SETFL, fcntl(errorReadPipe(), F_GETFL) | O_NONBLOCK) == -1)
        {
            raiseError("Couldn't set pipes to nonblocking");
        }

        struct sigaction sa;

        sa.sa_handler = &sigchldHandler;

        if (sigaction(SIGCHLD, &sa, nullptr) == -1)
        {
            raiseError("Failed to set sig handler");
        }

        if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
        {
            raiseError("Failed to set SIGPIPE");
        }
    }
コード例 #2
0
ファイル: Process.cpp プロジェクト: dyreshark/IntroUNIX
void Process::closeallpipes()
{
    for (int i = 0; i < 2; ++i)
    {
        pipeClose(readpipe[i]);
        pipeClose(writepipe[i]);
    }
}
コード例 #3
0
ファイル: svnmanager.cpp プロジェクト: gogoprog/aqtsvngui
void SVNManager::AnalyzeJob::run()
{
    QString command;
    FILE *fp;
    char buffer[256];

    addLogLine("Analyzing " + path + " ..." );

    command += "svn st";

    fp = pipeOpen(command.toAscii(), "r");

    if (fp == NULL)
        return;

    while (fgets(buffer, 256, fp) != NULL) {
        SVNManager::getInstance().parseLine(buffer);
        addLog(".");
    }

    pipeClose(fp);


    SVNManager::getInstance().currentPath = path;

    QMetaObject::invokeMethod(&MainWindow::getInstance(), "analyzeTerminated", Qt::QueuedConnection, Q_ARG(bool, true));
}
コード例 #4
0
ファイル: svnmanager.cpp プロジェクト: gogoprog/aqtsvngui
void SVNManager::CommitJob::run()
{
    QString command;
    FILE *fp;
    char buffer[256];

    command += "svn ci ";

    foreach(const SVNEntry *entry, SVNManager::getInstance().entryList) {
        if(entry->isSelected()) {
            command += "\"" + entry->getRelativePath() + "\" ";
        }
    }

    command += "-m \"" + message + "\"";

    fp = pipeOpen(command.toAscii(), "r");

    if (fp == NULL)
        return;

    while (fgets(buffer, 256, fp) != NULL) {
        addLog(buffer);
    }

    pipeClose(fp);

    QMetaObject::invokeMethod(&MainWindow::getInstance(), "commitTerminated", Qt::QueuedConnection, Q_ARG(bool, true));
}
コード例 #5
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioShowBuf( USHORT usIndex, PVOID pargs )
{
    PVIOSHOWBUFPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioShowBuf, p->usOfs, p->usLen, p->hvio );

    if( m_LVBPtr )
    {
        USHORT  usStart = p->usOfs & -2;
        USHORT  usEnd = ( p->usOfs + p->usLen + 1 ) & -2;
        USHORT  usLen;

        if( usEnd > m_LVBLen )
            usEnd = m_LVBLen;

        usLen = usEnd - usStart;

        pipeOpen( &hpipe );

        DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, &usStart, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, &usLen, sizeof( USHORT ), &cbActual );
        DosWrite( hpipe, m_LVBPtr + usStart, usLen, &cbActual );

        pipeClose( hpipe );
    }

    return 0;
}
コード例 #6
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioSetCurType( USHORT usIndex, PVOID pargs )
{
    PVIOSETCURTYPEPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioSetCurType, p->pvci, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pvci, sizeof( VIOCURSORINFO ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #7
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioSetCurPos( USHORT usIndex, PVOID pargs )
{
    PVIOSETCURPOSPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioSetCurPos, p->usRow, p->usCol, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #8
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioWrtCellStr( USHORT usIndex, PVOID pargs )
{
    PVIOWRTCELLSTRPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioWrtCellStr, p->pchCellStr, p->usLen, p->usRow, p->usCol, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usLen, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pchCellStr, p->usLen * sizeof( BYTE ) * VIO_CELLSIZE, &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #9
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioWrtNCell( USHORT usIndex, PVOID pargs )
{
    PVIOWRTNCELLPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioWrtNCell, p->pbCell, p->usTimes, p->usRow, p->usCol, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usTimes, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pbCell, sizeof( BYTE ) * VIO_CELLSIZE, &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #10
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioWrtNChar( USHORT usIndex, PVOID pargs )
{
    PVIOWRTNCHARPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioWrtNChar, p->pch, p->usTimes, p->usRow, p->usCol, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usTimes, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pch, sizeof( CHAR ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #11
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioWrtCharStrAtt( USHORT usIndex, PVOID pargs )
{
    PVIOWRTCHARSTRATTPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioWrtCharStrAtt, p->pchCharStr, p->usLen, p->usRow, p->usCol, p->pbAttr, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pbAttr, sizeof( BYTE ), &cbActual );
    DosWrite( hpipe, &p->usCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRow, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usLen, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pchCharStr, p->usLen, &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #12
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioSetMode( USHORT usIndex, PVOID pargs )
{
    PVIOSETMODEPARAM p = pargs;
    VIOMODEINFO      vmi;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioSetMode, p->pvmi, p->hvio );

    vmi.cb = sizeof( VIOMODEINFO );
    CALL_VIO( VioGetMode, &vmi, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &vmi, sizeof( VIOMODEINFO ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #13
0
ファイル: viosub.c プロジェクト: OS2World/UTIL-SHELL-KShell
static ULONG vioScrollRt( USHORT usIndex, PVOID pargs )
{
    PVIOSCROLLRTPARAM p = pargs;

    HPIPE   hpipe;
    ULONG   cbActual;

    CALL_VIO( VioScrollRt, p->usTopRow, p->usLeftCol, p->usBotRow, p->usRightCol, p->usLines, p->pbCell, p->hvio );

    pipeOpen( &hpipe );

    DosWrite( hpipe, &usIndex, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, p->pbCell, sizeof( BYTE ) * VIO_CELLSIZE, &cbActual );
    DosWrite( hpipe, &p->usLines, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usRightCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usBotRow, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usLeftCol, sizeof( USHORT ), &cbActual );
    DosWrite( hpipe, &p->usTopRow, sizeof( USHORT ), &cbActual );

    pipeClose( hpipe );

    return 0;
}
コード例 #14
0
ファイル: Process.cpp プロジェクト: dyreshark/IntroUNIX
void Process::exec()
{
    if (m_args.empty())
    {
        throw std::runtime_error("Need at least one argument for the filename");
    }

    if (!pipecreate())
    {
        raiseError("Failed to create pipes");
    }

    auto forkres = fork();

    switch(forkres)
    {
    case -1:
        closeallpipes();

        raiseError("Forking went poorly");
        // intentional no break -- exception takes care of it
    case 0:
    {
        pipeClose(selectpipe(pipes::READ_PIPE));
        pipeClose(selectpipe(pipes::WRITE_PIPE));
        pipeClose(sighandlers::errorReadPipe());

        assert(selectpipe(pipes::SUB_READ_PIPE) != -1);
        assert(selectpipe(pipes::SUB_WRITE_PIPE) != -1);

        if (dup2(selectpipe(pipes::SUB_READ_PIPE), fileno(stdin)) == -1)
        {
            raiseError("Duplicating read pipe went poorly.");
        }

        if (dup2(selectpipe(pipes::SUB_WRITE_PIPE), fileno(stdout)) == -1)
        {
            raiseError("Duplicating write pipe went poorly");
        }

        const char* filename = m_args[0];

        char** args = const_cast<char**>((m_args.size() > 1) ? &m_args[1] : nullptr);

        char okc = (char)0;

        // tell other program we've started. if that fails then go directly to saying "failed"
        if (::write(fileno(stdout), &okc, sizeof(char)) != -1)
        {
            execvp(filename, args);
        }

        // if exec fails, report error, close file descriptors, and get out.
        if (sighandlers::errorWritePipe() >= 0)
        {
            ::write(sighandlers::errorWritePipe(), &errno, sizeof(decltype(errno)));
        }

        _exit(1);
    }
    default:
    {
        m_pid = forkres;

        pipeClose(selectpipe(pipes::SUB_READ_PIPE));
        pipeClose(selectpipe(pipes::SUB_WRITE_PIPE));

        assert(selectpipe(pipes::READ_PIPE) != -1);
        assert(selectpipe(pipes::WRITE_PIPE) != -1);

        // wait for the program to output (char)0, which means it is running.
        // then wait 50ms for the program to fail/pass exec(). 
        char inbuf = '\0';
        struct timeval maxtime;
        fd_set rdfds;

        FD_ZERO(&rdfds);
        FD_SET(selectpipe(pipes::READ_PIPE), &rdfds);

        maxtime.tv_sec = 1;
        if (select(selectpipe(pipes::READ_PIPE) + 1, &rdfds, nullptr, nullptr, &maxtime) == -1)
        {
            raiseError("Select failed in waiting for new process to spawn");
        }

        // clearing out initial byte
        ::read(selectpipe(pipes::READ_PIPE), &inbuf, sizeof(char));
        
        // wait a max of 50ms for program to report failure
        usleep(50 * 1000);
    }
    }
}
コード例 #15
0
ファイル: Process.cpp プロジェクト: dyreshark/IntroUNIX
 static void destroy()
 {
     pipeClose(errpipes[0]);
     pipeClose(errpipes[1]);
 }