From: Brian Clarke Date: Fri, 28 Jul 2000 15:18:29 +0000 (-0400) Subject: fix and question re: waitpid() under win32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2f67576d8cb103df532c921ad5e6caa4f7927a88;p=p5sagit%2Fp5-mst-13.2.git fix and question re: waitpid() under win32 Message-ID: <3981DC85.290314EB@appliedmeta.com> Slightly reformatted and WNOHANG # define moved to win32.h so that also POSIX.xs sees it, as suggsted by Sarathy. p4raw-id: //depot/perl@6472 --- diff --git a/win32/win32.c b/win32/win32.c index 60777fa..3c3d1e5 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -53,7 +53,6 @@ #else #include #endif - #ifdef __GNUC__ /* Mingw32 defaults to globing command line * So we turn it off like this: @@ -1645,8 +1644,12 @@ win32_waitpid(int pid, int *status, int flags) long child = find_pseudo_pid(-pid); if (child >= 0) { HANDLE hThread = w32_pseudo_child_handles[child]; - DWORD waitcode = WaitForSingleObject(hThread, INFINITE); - if (waitcode != WAIT_FAILED) { + DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE; + DWORD waitcode = WaitForSingleObject(hThread, timeout); + if (waitcode == WAIT_TIMEOUT) { + return 0; + } + else if (waitcode != WAIT_FAILED) { if (GetExitCodeThread(hThread, &waitcode)) { *status = (int)((waitcode & 0xff) << 8); retval = (int)w32_pseudo_child_pids[child]; @@ -1663,15 +1666,20 @@ win32_waitpid(int pid, int *status, int flags) long child = find_pid(pid); if (child >= 0) { HANDLE hProcess = w32_child_handles[child]; - DWORD waitcode = WaitForSingleObject(hProcess, INFINITE); - if (waitcode != WAIT_FAILED) { - if (GetExitCodeProcess(hProcess, &waitcode)) { - *status = (int)((waitcode & 0xff) << 8); - retval = (int)w32_child_pids[child]; - remove_dead_process(child); - return retval; - } - } + DWORD timeout=(flags&WNOHANG)?0:INFINITE; + DWORD waitcode = WaitForSingleObject(hProcess, timeout); + if (waitcode == WAIT_TIMEOUT) { + { + return 0; + } + else if (waitcode != WAIT_FAILED) { + if (GetExitCodeProcess(hProcess, &waitcode)) { + *status = (int)((waitcode & 0xff) << 8); + retval = (int)w32_child_pids[child]; + remove_dead_process(child); + return retval; + } + } else errno = ECHILD; } diff --git a/win32/win32.h b/win32/win32.h index 2e5b074..eb5ecd2 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -492,5 +492,9 @@ struct interp_intern { */ #include "win32iop.h" +#ifndef WNOHANG +# define WNOHANG 1 +#endif + #endif /* _INC_WIN32_PERL5 */