summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xt/io/pipe.t20
-rw-r--r--util.c4
2 files changed, 23 insertions, 1 deletions
diff --git a/t/io/pipe.t b/t/io/pipe.t
index 95cdd5587e..24c5d76cc6 100755
--- a/t/io/pipe.t
+++ b/t/io/pipe.t
@@ -11,7 +11,7 @@ BEGIN {
}
$| = 1;
-print "1..15\n";
+print "1..16\n";
# External program 'tr' assumed.
open(PIPE, "|-") || (exec 'tr', 'YX', 'ko');
@@ -185,3 +185,21 @@ if ($? != 42) {
}
print "ok 15\n";
$? = 0;
+
+# check that child is reaped if the piped program can't be executed
+{
+ local $SIG{CHLD} = 'DEFAULT';
+ open NIL, '/no_such_process |';
+ close NIL;
+
+ my $child = 0;
+ eval {
+ local $SIG{ALRM} = sub { die; };
+ alarm 2;
+ $child = wait;
+ alarm 0;
+ };
+
+ print "not " if $child != -1;
+ print "ok 16\n";
+}
diff --git a/util.c b/util.c
index 60e82e3550..1261b98331 100644
--- a/util.c
+++ b/util.c
@@ -2455,8 +2455,12 @@ Perl_my_popen(pTHX_ char *cmd, char *mode)
PerlLIO_close(pp[0]);
did_pipes = 0;
if (n) { /* Error */
+ int pid2, status;
if (n != sizeof(int))
Perl_croak(aTHX_ "panic: kid popen errno read");
+ do {
+ pid2 = wait4pid(pid, &status, 0);
+ } while (pid2 == -1 && errno == EINTR);
errno = errkid; /* Propagate errno from kid */
return Nullfp;
}