Changeset 4664


Ignore:
Timestamp:
10/05/10 02:16:54 (3 years ago)
Author:
sam
Message:

Inherit stdin/stdout/stderr in the child process under Win32.

Location:
zzuf/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/libzzuf/lib-win32.c

    r4663 r4664  
    6565           HANDLE hTemplateFile) 
    6666{ 
    67     fprintf(stderr, "CreateFileA(%s)\n", lpFileName); 
    68     return ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode, 
    69                              lpSecurityAttributes, dwCreationDisposition, 
    70                              dwFlagsAndAttributes, hTemplateFile); 
     67    HANDLE ret; 
     68    ret = ORIG(CreateFileA)(lpFileName, dwDesiredAccess, dwShareMode, 
     69                            lpSecurityAttributes, dwCreationDisposition, 
     70                            dwFlagsAndAttributes, hTemplateFile); 
     71    debug("%s(\"%s\", %x, %x, ..., %x, %x, ...) = [%i]", 
     72          __func__, lpFileName, dwDesiredAccess, dwShareMode, 
     73          dwCreationDisposition, dwFlagsAndAttributes, (int)ret); \ 
     74    return ret; 
    7175} 
    7276#endif 
  • zzuf/trunk/src/myfork.c

    r4650 r4664  
    3434#   include <tlhelp32.h> 
    3535#endif 
     36#if defined HAVE_IO_H 
     37#   include <io.h> 
     38#endif 
    3639#include <string.h> 
    3740#include <fcntl.h> /* for O_BINARY */ 
     
    7376 
    7477#if defined HAVE_WINDOWS_H 
     78#   define PARENT_FD(x) ((x) ? 0 : 1) 
     79#   define CHILD_FD(x) ((x) ? 1 : 0) 
     80#else 
     81#   define PARENT_FD(x) 0 
     82#   define CHILD_FD(x) 1 
     83#endif 
     84 
     85#if defined HAVE_WINDOWS_H 
    7586static void rep32(uint8_t *buf, void *addr); 
    7687static int dll_inject(PROCESS_INFORMATION *, char const *); 
     
    91102        ret = pipe(pipes[i]); 
    92103#elif defined HAVE__PIPE 
     104        int tmp; 
     105        /* The pipe is created with NOINHERIT otherwise both parts are 
     106         * inherited. We then duplicate the part we want. */ 
    93107        ret = _pipe(pipes[i], 512, _O_BINARY | O_NOINHERIT); 
     108        tmp = _dup(pipes[i][CHILD_FD(i)]); 
     109        close(pipes[i][CHILD_FD(i)]); 
     110        pipes[i][CHILD_FD(i)] = tmp; 
    94111#endif 
    95112        if(ret < 0) 
     
    111128    for(i = 0; i < 3; i++) 
    112129    { 
    113         close(pipes[i][1]); 
    114         child->fd[i] = pipes[i][0]; 
     130        close(pipes[i][CHILD_FD(i)]); 
     131        child->fd[i] = pipes[i][PARENT_FD(i)]; 
    115132    } 
    116133 
     
    259276    memset(&sinfo, 0, sizeof(sinfo)); 
    260277    sinfo.cb = sizeof(sinfo); 
    261 #if 0 
    262     DuplicateHandle(pid, (HANDLE)_get_osfhandle(pipes[0][1]), pid, 
    263         /* FIXME */ &sinfo.hStdInput, 0, TRUE, DUPLICATE_SAME_ACCESS); 
    264     DuplicateHandle(pid, (HANDLE)_get_osfhandle(pipes[1][1]), pid, 
    265                     &sinfo.hStdError, 0, TRUE, DUPLICATE_SAME_ACCESS); 
    266     DuplicateHandle(pid, (HANDLE)_get_osfhandle(pipes[2][1]), pid, 
    267                     &sinfo.hStdOutput, 0, TRUE, DUPLICATE_SAME_ACCESS); 
     278 
     279    sinfo.hStdInput = (HANDLE)_get_osfhandle(pipes[0][CHILD_FD(0)]); 
     280    sinfo.hStdOutput = (HANDLE)_get_osfhandle(pipes[1][CHILD_FD(1)]); 
     281    sinfo.hStdError = (HANDLE)_get_osfhandle(pipes[2][CHILD_FD(2)]); 
    268282    sinfo.dwFlags = STARTF_USESTDHANDLES; 
    269 #endif 
    270     ret = CreateProcess(NULL, child->newargv[0], NULL, NULL, FALSE, 
     283    ret = CreateProcess(NULL, child->newargv[0], NULL, NULL, TRUE, 
    271284                        CREATE_SUSPENDED, NULL, NULL, &sinfo, &pinfo); 
    272285    if(!ret) 
  • zzuf/trunk/src/zzuf.c

    r4646 r4664  
    939939            continue; 
    940940 
    941         for(j = 0; j < 3; j++) 
     941        for(j = 1; j < 3; j++) 
    942942            ZZUF_FD_SET(opts->child[i].fd[j], &fdset, maxfd); 
    943943    } 
     
    945945    tv.tv_usec = 1000; 
    946946 
     947#if _WIN32 
     948    for(i = 0; i < opts->maxchild; i++) 
     949        for (j = 1; j < 3; j++) 
     950        { 
     951            char tmpbuf[1025]; 
     952            int tmp = _read(opts->child[i].fd[j], tmpbuf, 1024); 
     953            if (tmp > 0) 
     954            { 
     955                tmpbuf[tmp] = 0; 
     956                fprintf(stderr, "read %i bytes on fd %i: \"%s\"\n", tmp, j, tmpbuf); 
     957            } 
     958        } 
     959#endif 
     960 
     961    errno = 0; 
    947962    ret = select(maxfd + 1, &fdset, NULL, NULL, &tv); 
    948963    if(ret < 0 && errno) 
Note: See TracChangeset for help on using the changeset viewer.