summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2013-10-17 15:29:58 +1100
committerTony Cook <tony@develop-help.com>2013-10-17 15:43:09 +1100
commite9d373c4fc63458e812eaac6aef324f1b45fd607 (patch)
tree8541974202ab72f8cd6d214ae44e47cc9a1ebe8c /util.c
parentf2a7d0fc9f4d388e4bb0628fba2476c2789721c8 (diff)
downloadperl-e9d373c4fc63458e812eaac6aef324f1b45fd607.tar.gz
[perl #119893] avoid waiting on pid 0
When a filehandle is cloned into a standard handle, do_openn() copies the pid from the original handle in PL_fdpid to the standard handle and zeroes the entry for the original handle, so when the original handle was closed Perl_my_pclose() would call wait4pid() with a pid of 0. With v5.19.3-614-gd4c0274 I modified wait4pid(), perl's waitpid/wait4() wrapper, to allow a pid of zero through to the actual system call when available. These combined so that following v5.19.3-614-gd4c0274 in some circumstances closing the original handle would block by calling waitpid(0, ...) or wait4(0, ...), which waits for any child process in the same process group to terminate. This commit changes Perl_my_pclose() to wait for the child only when the stored pid is positive.
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/util.c b/util.c
index f020b4be14..b62caf8011 100644
--- a/util.c
+++ b/util.c
@@ -2706,19 +2706,21 @@ Perl_my_pclose(pTHX_ PerlIO *ptr)
bool close_failed;
dSAVEDERRNO;
const int fd = PerlIO_fileno(ptr);
+ bool should_wait;
+
+ svp = av_fetch(PL_fdpid,fd,TRUE);
+ pid = (SvTYPE(*svp) == SVt_IV) ? SvIVX(*svp) : -1;
+ SvREFCNT_dec(*svp);
+ *svp = NULL;
#ifdef USE_PERLIO
/* Find out whether the refcount is low enough for us to wait for the
child proc without blocking. */
- const bool should_wait = PerlIOUnix_refcnt(fd) == 1;
+ should_wait = PerlIOUnix_refcnt(fd) == 1 && pid > 0;
#else
- const bool should_wait = 1;
+ should_wait = pid > 0;
#endif
- svp = av_fetch(PL_fdpid,fd,TRUE);
- pid = (SvTYPE(*svp) == SVt_IV) ? SvIVX(*svp) : -1;
- SvREFCNT_dec(*svp);
- *svp = NULL;
#ifdef OS2
if (pid == -1) { /* Opened by popen. */
return my_syspclose(ptr);