Esempio n. 1
0
unsigned BatchSpawn( char *cmd )
{
    buff[0] = LNK_RUN;
    strcpy( &buff[1], cmd );
    BatservWrite( buff, strlen( buff ) );
    return( 0 );
}
Esempio n. 2
0
unsigned BatchAbort()
{
    char        cmd;

    cmd = LNK_ABORT;
    BatservWrite( &cmd, sizeof( cmd ) );
    return( 0 );
}
Esempio n. 3
0
unsigned BatchCancel()
{
    char        cmd;

    cmd = LNK_CANCEL;
    BatservWrite( &cmd, sizeof( cmd ) );
    return( 0 );
}
Esempio n. 4
0
unsigned BatchChdir( char *new_dir )
{

    buff[0] = LNK_CWD;
    strcpy( &buff[1], new_dir );
    BatservWrite( buff, strlen( buff ) + 1 );
    BatservRead( buff, sizeof( buff ) );
    return( *(unsigned long *)&buff[1] );
}
Esempio n. 5
0
static void SendStatus( unsigned long status )
{
    struct {
        unsigned char   cmd;
        unsigned long   stat;
    } buff;

    buff.cmd = LNK_STATUS;
    buff.stat = status;
    BatservWrite( &buff, sizeof( buff ) );
}
Esempio n. 6
0
void BatchUnlink( int shutdown )
{
    char        done;

    done = shutdown ? LNK_SHUTDOWN : LNK_DONE;
    BatservWrite( &done, sizeof( done ) );
    CloseHandle( SemReadUp );
    CloseHandle( SemReadDone );
    CloseHandle( SemWritten );
    CloseHandle( MemHdl );
    UnmapViewOfFile( SharedMem );
    SharedMem = NULL;
}
Esempio n. 7
0
unsigned BatchCollect( void *ptr, unsigned max, unsigned long *status )
{
    int         len;
    char        *buff = ptr;

    buff[0] = LNK_QUERY;
    *(unsigned long *)&buff[1] = max;
    BatservWrite( buff, 5 );
    len = BatservRead( buff, max ) - 1;
    if( len <= 0 ) return( 0 );
    if( *buff == LNK_STATUS ) {
        *status = *(unsigned long *)&buff[1];
        return( -1 );
    }
    memmove( buff, &buff[1], len );
    return( len );
}
Esempio n. 8
0
static void ProcessConnection( void )
{
    char                buff[MAX_TRANS];
    DWORD               bytes_read;
    char                *dir;
    DWORD               rc;
    DWORD               status;
    unsigned            max;

    for( ;; ) {
        bytes_read = BatservRead( buff, sizeof( buff ) );
        if( bytes_read == 0 ) break;
        buff[bytes_read] = '\0';
        switch( buff[0] ) {
        case LNK_CWD:
            rc = 0;
            dir = &buff[1];
            if( !SetCurrentDirectory( dir ) ) {
                rc = GetLastError();
            }
            SendStatus( rc );
            break;
        case LNK_RUN:
            RunCmd( &buff[1] );
            break;
        case LNK_QUERY:
            max = *(unsigned long *)&buff[1];
            if( max > sizeof( buff ) ) max = sizeof( buff );
            --max;
            if( PeekNamedPipe( RedirRead, buff, 0, NULL, &bytes_read,
                        NULL ) && bytes_read != 0 ) {
                if( bytes_read < max ) max = bytes_read;
                ReadFile( RedirRead, &buff[1], max, &bytes_read, NULL );
                buff[0] = LNK_OUTPUT;
                BatservWrite( buff, bytes_read + 1 );
            } else {
                if( WaitForSingleObject( ProcHdl, 0 ) == WAIT_TIMEOUT ) {
                    /* let someone else run */
                    Sleep( 1 );
                    buff[0] = LNK_NOP;
                    BatservWrite( buff, 1 );
                } else {
                    GetExitCodeProcess( ProcHdl, &status );
                    CloseHandle( RedirRead );
                    SendStatus( status );
                    ProcId = 0;
                    CloseHandle( ProcHdl );
                }
            }
            break;
        case LNK_CANCEL:
//            GenerateConsoleCtrlEvent( CTRL_BREAK_EVENT, ProcId );
            GenerateConsoleCtrlEvent( CTRL_BREAK_EVENT, 0 );
            break;
        case LNK_ABORT:
            TerminateProcess( ProcHdl, 0 );
            break;
        case LNK_DONE:
            Say(( "LNK_DONE\n" ));
            return;
        case LNK_SHUTDOWN:
            Say(( "LNK_SHUTDOWN\n" ));
            CloseHandle( SemReadUp );
            CloseHandle( SemReadDone );
            CloseHandle( SemWritten );
            CloseHandle( MemHdl );
            UnmapViewOfFile( SharedMem );
            exit( 0 );
            break;
        }
    }
}