X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=pipex_win32.c;h=8924c277e9d94500aef8920a483051593afcbd71;hb=learn;hp=0d6fc7ba61ae6dc82d0fd452c7f06ce8b5446ae4;hpb=60900035e6d0309705f2326ee50edc52386305e9;p=polyglot.git diff --git a/pipex_win32.c b/pipex_win32.c index 0d6fc7b..8924c27 100644 --- a/pipex_win32.c +++ b/pipex_win32.c @@ -193,21 +193,47 @@ void pipex_send_eof(pipex_t *pipex) { // pipex_exit() -void pipex_exit(pipex_t *pipex) { +/* This routine waits for kill_timeout milliseconds for + * the process to exit by itself. If that doesn't + * happen it will kill the process. + */ + +void pipex_exit(pipex_t *pipex, int kill_timeout) { DWORD lpexit; + int elapsed_time; + bool exited; CloseHandle(pipex->hInput); CloseHandle(pipex->hOutput); + // ExitProcess(pipex->hProcess,0); + + my_log("POLYGLOT Waiting for child process to exit.\n"); + elapsed_time=0; + exited=FALSE; + + while(elapsed_timehProcess,&lpexit); + if(lpexit==STILL_ACTIVE){ + my_log("POLYGLOT Child has not exited yet. Sleeping %dms.\n", WAIT_GRANULARITY); + my_sleep(WAIT_GRANULARITY); + elapsed_time+=WAIT_GRANULARITY; + }else{ + exited=TRUE; + break; + } + } + + if(!exited){ + my_log("POLYGLOT Child wouldn't exit by itself. Terminating it.\n"); + TerminateProcess(pipex->hProcess,lpexit); + } + CloseHandle(pipex->hProcess); + if(!pipex->quit_pending){ // suppress further errors pipex->quit_pending=TRUE; my_fatal("pipex_exit(): %s: child exited unexpectedly.\n",pipex->command); } - if(GetExitCodeProcess(pipex->hProcess,&lpexit)){ - if(lpexit==STILL_ACTIVE) - //must be java,hammer it down! - TerminateProcess(pipex->hProcess,lpexit); - } - CloseHandle(pipex->hProcess); + } // pipex_eof_input() @@ -440,7 +466,7 @@ typedef void (WINAPI *SPAM)(HANDLE, int); void pipex_set_affinity(pipex_t *pipex, int value){ SPAM pSPAM; - if(pipex->hProcess) return; + if(!pipex->hProcess) return; if(value==-1) return; pSPAM = (SPAM) GetProcAddress(