diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-08-16 23:59:28 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-08-16 23:59:28 +0000 |
commit | 68a29c53b68ed5d3196e36d984ad46cc171fe95a (patch) | |
tree | 626bb44c8720286d96a37992437c5ffc0e6f5fbd | |
parent | d6217f1e0304b5fb226ba520442a930ddceeea43 (diff) | |
download | perl-68a29c53b68ed5d3196e36d984ad46cc171fe95a.tar.gz |
on windows, the return values from wait() and waitpid() don't
match those of pseudo-pids
p4raw-id: //depot/perl@6659
-rw-r--r-- | pp_sys.c | 10 | ||||
-rwxr-xr-x | t/op/fork.t | 24 | ||||
-rw-r--r-- | util.c | 2 | ||||
-rw-r--r-- | win32/win32.c | 4 |
4 files changed, 38 insertions, 2 deletions
@@ -3738,7 +3738,12 @@ PP(pp_wait) int argflags; childpid = wait4pid(-1, &argflags, 0); +# if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) + /* 0 and -1 are both error returns (the former applies to WNOHANG case) */ + STATUS_NATIVE_SET((childpid && childpid != -1) ? argflags : -1); +# else STATUS_NATIVE_SET((childpid > 0) ? argflags : -1); +# endif XPUSHi(childpid); RETURN; #else @@ -3757,7 +3762,12 @@ PP(pp_waitpid) optype = POPi; childpid = TOPi; childpid = wait4pid(childpid, &argflags, optype); +# if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) + /* 0 and -1 are both error returns (the former applies to WNOHANG case) */ + STATUS_NATIVE_SET((childpid && childpid != -1) ? argflags : -1); +# else STATUS_NATIVE_SET((childpid > 0) ? argflags : -1); +# endif SETi(childpid); RETURN; #else diff --git a/t/op/fork.t b/t/op/fork.t index 80c0b723b6..beb64f9624 100755 --- a/t/op/fork.t +++ b/t/op/fork.t @@ -374,3 +374,27 @@ else { EXPECT pipe_from_fork pipe_to_fork +######## +if ($pid = fork()) { + print "forked first kid\n"; + print "waitpid() returned ok\n" if waitpid($pid,0) == $pid; +} +else { + print "first child\n"; + exit(0); +} +if ($pid = fork()) { + print "forked second kid\n"; + print "wait() returned ok\n" if wait() == $pid; +} +else { + print "second child\n"; + exit(0); +} +EXPECT +forked first kid +first child +waitpid() returned ok +forked second kid +second child +wait() returned ok @@ -2676,6 +2676,7 @@ Perl_wait4pid(pTHX_ Pid_t pid, int *statusp, int flags) if (!pid) return -1; +#if !defined(HAS_WAITPID) && !defined(HAS_WAIT4) || defined(HAS_WAITPID_RUNTIME) if (pid > 0) { sprintf(spid, "%"IVdf, (IV)pid); svp = hv_fetch(PL_pidstatus,spid,strlen(spid),FALSE); @@ -2698,6 +2699,7 @@ Perl_wait4pid(pTHX_ Pid_t pid, int *statusp, int flags) return pid; } } +#endif #ifdef HAS_WAITPID # ifdef HAS_WAITPID_RUNTIME if (!HAS_WAITPID_RUNTIME) diff --git a/win32/win32.c b/win32/win32.c index 6856884472..56ebdaf8f4 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1654,7 +1654,7 @@ win32_waitpid(int pid, int *status, int flags) *status = (int)((waitcode & 0xff) << 8); retval = (int)w32_pseudo_child_pids[child]; remove_dead_pseudo_process(child); - return retval; + return -retval; } } else @@ -1720,7 +1720,7 @@ win32_wait(int *status) *status = (int)((exitcode & 0xff) << 8); retval = (int)w32_pseudo_child_pids[i]; remove_dead_pseudo_process(i); - return retval; + return -retval; } } } |