Changeset 4828


Ignore:
Timestamp:
07/11/12 17:31:23 (11 months ago)
Author:
wisk
Message:

fix tmp file creation on win32, start to implement handling of win32 exception with GetExitCodeProcess?

Location:
zzuf/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/myfork.c

    r4827 r4828  
    354354    free(cmdline); 
    355355 
     356    child->process_handle = pinfo.hProcess; 
     357    child->pid            = pinfo.dwProcessId; 
     358 
    356359    if (!ret) 
    357360    { 
  • zzuf/trunk/src/opts.h

    r4393 r4828  
    1414 *  opts.h: configuration handling 
    1515 */ 
     16 
     17#ifdef _WIN32 
     18#   include <Windows.h> 
     19#endif 
    1620 
    1721struct opts 
     
    5559 
    5660        pid_t pid; 
     61#ifdef _WIN32 
     62        HANDLE process_handle; 
     63#endif 
    5764        int fd[3]; /* 0 is debug, 1 is stderr, 2 is stdout */ 
    5865        int bytes, seed; 
  • zzuf/trunk/src/zzuf.c

    r4827 r4828  
    115115#if defined _WIN32 
    116116#   include <Windows.h> 
     117#   include <fcntl.h> /* _O_RDWR */ 
     118#   include <io.h> /* _open */ 
    117119static CRITICAL_SECTION _zz_pipe_cs; 
    118120#endif 
     
    714716                continue; 
    715717 
     718#ifdef _WIN32 
     719# 
     720            sprintf(tmpname, "%s/zzuf.$i.XXXXXX", tmpdir, GetCurrentProcessId()); 
     721            fdout = _open(mktemp(tmpname), _O_RDWR, 0600); 
     722#else 
    716723            sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, (int)getpid()); 
    717 #ifdef _WIN32 
    718             fdout = mktemp(tmpname); 
    719 #else 
    720724            fdout = mkstemp(tmpname); 
    721725#endif 
     
    890894                fprintf(stderr, "exit %i\n", WEXITSTATUS(status)); 
    891895        } 
     896#elif defined _WIN32 
     897        { 
     898            DWORD exit_code; 
     899            if (GetExitCodeProcess(opts->child[i].process_handle, &exit_code)) 
     900            { 
     901                if (exit_code == STILL_ACTIVE) continue; /* The process is still active, we don't do anything */ 
     902 
     903                /*  
     904                 * The main problem with GetExitCodeProcess is it returns either returned parameter value of 
     905                 * ExitProcess/TerminateProcess, or the unhandled exception (which is what we're looking for) 
     906                 */ 
     907                switch (exit_code) 
     908                { 
     909                case EXCEPTION_ACCESS_VIOLATION: fprintf(stderr, "child(%d) unhandled exception: Access Violation", opts->child[i].pid); break; 
     910                default: break; 
     911                } 
     912            } 
     913 
     914            if (opts->child[i].status != STATUS_RUNNING) 
     915            { 
     916                TerminateProcess(opts->child[i].process_handle, 0); 
     917            } 
     918        } 
    892919#else 
    893920        /* waitpid() is not available. Don't kill the process. */ 
     
    9861013    { 
    9871014        struct child_overlapped * co; 
    988         HANDLE h; 
    989  
    990         if(opts->child[i].status != STATUS_RUNNING) 
     1015        HANDLE h = (opts->child[i].fd[j] == -1) ? INVALID_HANDLE_VALUE : (HANDLE)_get_osfhandle(opts->child[i].fd[j]); 
     1016 
     1017        if(opts->child[i].status != STATUS_RUNNING 
     1018        || opts->child[i].fd[j] == -1 
     1019        || h == INVALID_HANDLE_VALUE) 
     1020        { 
     1021            fd_number--; 
    9911022            continue; 
     1023        } 
    9921024 
    9931025        co = malloc(sizeof(*co)); 
     
    9981030        co->opts     = opts; 
    9991031 
    1000         h = (HANDLE)_get_osfhandle(opts->child[i].fd[j]); 
    1001  
    1002         /* FIXME: handle error */ 
    1003         ReadFileEx(h, co->buf, sizeof(co->buf), (LPOVERLAPPED)co, read_child); 
     1032        if(!ReadFileEx(h, co->buf, sizeof(co->buf), (LPOVERLAPPED)co, read_child)) 
     1033        { 
     1034            /* End of file reached */ 
     1035            close(opts->child[i].fd[j]); 
     1036            opts->child[i].fd[j] = -1; 
     1037 
     1038            if(opts->child[i].fd[0] == -1 
     1039                && opts->child[i].fd[1] == -1 
     1040                && opts->child[i].fd[2] == -1) 
     1041                opts->child[i].status = STATUS_EOF; 
     1042        } 
    10041043        cur_child_handle++; 
    10051044    } 
    10061045 
     1046    if (fd_number == 0) return; 
     1047 
    10071048    /* FIXME: handle error */ 
    1008     WaitForMultipleObjectsEx(fd_number, children_handle, FALSE, INFINITE, TRUE); 
     1049    WaitForMultipleObjectsEx(fd_number, children_handle, FALSE, 1000, TRUE); 
    10091050} 
    10101051 
Note: See TracChangeset for help on using the changeset viewer.