Handling of SIGINT

Alex Vandiver alexmv at MIT.EDU
Thu Feb 19 17:16:57 GMT 2009


Heya,
  Test::HTTP::Server::Simple sets up a $SIG{INT} handler to try to tear
down the HTTP server it starts, which works fine if you hand the test
script directly to perl.  But if you run it with prove, prove gets hit
by the SIGINT, dies, and summarily kills off the test script with no
warning, which leaves the HTTP server hanging around, and generally
makes a mess of things.  What would people think of the following patch?
It has the side-effect of having prove print out a summary after the ^C,
which doesn't seem too wrong to me offhand.
 - Alex

Index: lib/TAP/Parser/Iterator/Process.pm
===================================================================
--- lib/TAP/Parser/Iterator/Process.pm	(revision 1269)
+++ lib/TAP/Parser/Iterator/Process.pm	(working copy)
@@ -123,6 +123,11 @@
     my $merge = delete $args->{merge};
     my ( $pid, $err, $sel );
 
+    # Pass along any interrupts to the child
+    $SIG{INT} = sub {
+        kill INT => $self->{pid};
+    };
+
     if ( my $setup = delete $args->{setup} ) {
         $setup->(@command);
     }

-- 
Networking -- only one letter away from not working



More information about the tapx-dev mailing list