Changeset 4828
- Timestamp:
- 07/11/12 17:31:23 (11 months ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/myfork.c
r4827 r4828 354 354 free(cmdline); 355 355 356 child->process_handle = pinfo.hProcess; 357 child->pid = pinfo.dwProcessId; 358 356 359 if (!ret) 357 360 { -
zzuf/trunk/src/opts.h
r4393 r4828 14 14 * opts.h: configuration handling 15 15 */ 16 17 #ifdef _WIN32 18 # include <Windows.h> 19 #endif 16 20 17 21 struct opts … … 55 59 56 60 pid_t pid; 61 #ifdef _WIN32 62 HANDLE process_handle; 63 #endif 57 64 int fd[3]; /* 0 is debug, 1 is stderr, 2 is stdout */ 58 65 int bytes, seed; -
zzuf/trunk/src/zzuf.c
r4827 r4828 115 115 #if defined _WIN32 116 116 # include <Windows.h> 117 # include <fcntl.h> /* _O_RDWR */ 118 # include <io.h> /* _open */ 117 119 static CRITICAL_SECTION _zz_pipe_cs; 118 120 #endif … … 714 716 continue; 715 717 718 #ifdef _WIN32 719 # 720 sprintf(tmpname, "%s/zzuf.$i.XXXXXX", tmpdir, GetCurrentProcessId()); 721 fdout = _open(mktemp(tmpname), _O_RDWR, 0600); 722 #else 716 723 sprintf(tmpname, "%s/zzuf.%i.XXXXXX", tmpdir, (int)getpid()); 717 #ifdef _WIN32718 fdout = mktemp(tmpname);719 #else720 724 fdout = mkstemp(tmpname); 721 725 #endif … … 890 894 fprintf(stderr, "exit %i\n", WEXITSTATUS(status)); 891 895 } 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 } 892 919 #else 893 920 /* waitpid() is not available. Don't kill the process. */ … … 986 1013 { 987 1014 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--; 991 1022 continue; 1023 } 992 1024 993 1025 co = malloc(sizeof(*co)); … … 998 1030 co->opts = opts; 999 1031 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 } 1004 1043 cur_child_handle++; 1005 1044 } 1006 1045 1046 if (fd_number == 0) return; 1047 1007 1048 /* FIXME: handle error */ 1008 WaitForMultipleObjectsEx(fd_number, children_handle, FALSE, INFINITE, TRUE);1049 WaitForMultipleObjectsEx(fd_number, children_handle, FALSE, 1000, TRUE); 1009 1050 } 1010 1051
Note: See TracChangeset
for help on using the changeset viewer.
