From: Dave Rolsky Date: Mon, 27 Apr 2009 21:10:00 +0000 (+0000) Subject: Move killing the child into its own method and add a Win32-specific hack X-Git-Tag: 1.14_01~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02758cf841c5b9bf3afdd75ae9a29d7923b29e3d;p=catagits%2FCatalyst-Devel.git Move killing the child into its own method and add a Win32-specific hack --- diff --git a/lib/Catalyst/Restarter.pm b/lib/Catalyst/Restarter.pm index 7a13897..3a1f6b1 100644 --- a/lib/Catalyst/Restarter.pm +++ b/lib/Catalyst/Restarter.pm @@ -70,10 +70,7 @@ sub _restart_on_changes { print STDERR "\n"; print STDERR "Attempting to restart the server\n\n"; - if ( $self->_child ) { - kill 2, $self->_child - or die "Cannot send INT to child (" . $self->_child . "): $!"; - } + $self->_kill_child; $self->_fork_and_start; @@ -81,14 +78,28 @@ sub _restart_on_changes { } } -sub DEMOLISH { +sub _kill_child { my $self = shift; - if ( $self->_child ) { - kill 2, $self->_child; + return unless $self->_child; + + return unless kill 0, $self->_child; + + local $SIG{CHLD} = 'IGNORE'; + unless ( kill 'INT', $self->_child ) { + # The kill 0 thing does not work on Windows, but the restarter + # seems to work fine on Windows with this hack. + return if $^O eq 'MSWin32'; + die "Cannot send INT signal to ", $self->_child, ": $!"; } } +sub DEMOLISH { + my $self = shift; + + $self->_kill_child; +} + __PACKAGE__->meta->make_immutable; 1;