78f1eb
From fb5e77103dd443cc2112ba14dc665aa5ec072ce6 Mon Sep 17 00:00:00 2001
78f1eb
From: Tony Cook <tony@develop-help.com>
78f1eb
Date: Wed, 30 May 2018 14:03:04 +1000
78f1eb
Subject: [PATCH] (perl #122112) test for signal handler death in pclose
78f1eb
MIME-Version: 1.0
78f1eb
Content-Type: text/plain; charset=UTF-8
78f1eb
Content-Transfer-Encoding: 8bit
78f1eb
78f1eb
Signed-off-by: Petr Písař <ppisar@redhat.com>
78f1eb
---
78f1eb
 t/io/pipe.t | 23 ++++++++++++++++++++++-
78f1eb
 1 file changed, 22 insertions(+), 1 deletion(-)
78f1eb
78f1eb
diff --git a/t/io/pipe.t b/t/io/pipe.t
78f1eb
index f9ee65afe8..1d01db6af6 100644
78f1eb
--- a/t/io/pipe.t
78f1eb
+++ b/t/io/pipe.t
78f1eb
@@ -10,7 +10,7 @@ if (!$Config{'d_fork'}) {
78f1eb
     skip_all("fork required to pipe");
78f1eb
 }
78f1eb
 else {
78f1eb
-    plan(tests => 25);
78f1eb
+    plan(tests => 27);
78f1eb
 }
78f1eb
 
78f1eb
 my $Perl = which_perl();
78f1eb
@@ -241,3 +241,24 @@ SKIP: {
78f1eb
 
78f1eb
   is($child, -1, 'child reaped if piped program cannot be executed');
78f1eb
 }
78f1eb
+
78f1eb
+{
78f1eb
+    # [perl #122112] refcnt: fd -1 < 0 when a signal handler dies
78f1eb
+    # while a pipe close is waiting on a child process
78f1eb
+    my $prog = <
78f1eb
+\$SIG{ALRM}=sub{die};
78f1eb
+alarm 1;
78f1eb
+\$Perl = "$Perl";
78f1eb
+my \$cmd = qq(\$Perl -e "sleep 3");
78f1eb
+my \$pid = open my \$fh, "|\$cmd" or die "\$!\n";
78f1eb
+close \$fh;
78f1eb
+PROG
78f1eb
+    print $prog;
78f1eb
+    my $out = fresh_perl($prog, {});
78f1eb
+    $::TODO = "not fixed yet";
78f1eb
+    cmp_ok($out, '!~', qr/refcnt/, "no exception from PerlIO");
78f1eb
+    undef $::TODO;
78f1eb
+    # checks that that program did something rather than failing to
78f1eb
+    # compile
78f1eb
+    cmp_ok($out, '=~', qr/Died at/, "but we did get the exception from die");
78f1eb
+}
78f1eb
-- 
78f1eb
2.20.1
78f1eb