From: Jonathan Rockway Date: Tue, 12 May 2009 01:00:12 +0000 (-0500) Subject: exit parent if child dies unexpectedly (instead of fork-bombing) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7bd2975e68a94679faf0c68af07203206a5c006b;p=gitmo%2FMooseX-Runnable.git exit parent if child dies unexpectedly (instead of fork-bombing) --- diff --git a/lib/MooseX/Runnable/Invocation/Plugin/Restart/Base.pm b/lib/MooseX/Runnable/Invocation/Plugin/Restart/Base.pm index 9d516db..1802a0c 100644 --- a/lib/MooseX/Runnable/Invocation/Plugin/Restart/Base.pm +++ b/lib/MooseX/Runnable/Invocation/Plugin/Restart/Base.pm @@ -44,6 +44,14 @@ around 'run' => sub { # handle the case where the child dies unexpectedly waitpid $self->child_pid, 0; $self->clear_child_pid; + my ($code, $sig) = ($? >> 8, $? & 127); + eval { $self->_debug_message( + "Exiting early, child died with status $code (signal $sig).", + )}; + + # relay the error up, so the shell (etc.) can see it + kill $sig, $$ if $sig; # no-op? + exit $code; }; # parent @@ -71,12 +79,20 @@ around 'run' => sub { kill 'KILL', $pid2; }; waitpid $pid2, 0; - $child_body->(); + my $code = $? >> 8; + if($code == 0){ + goto $child_body; + } + else { + eval { $self->_debug_message( + "Child exited with non-zero status; aborting.", + )}; + exit $code; + } } else { # child? actually do the work exit $self->$next(@args); - } } };