X-Git-Url: http://git.indexdata.com/?p=mkws-moved-to-github.git;a=blobdiff_plain;f=test%2Fbin%2Fbomb.pl;h=2dde3d48f37ec1012e98d627f01f2c1db5da628f;hp=a84f40bb82bdc178167e11046f485d5718f137aa;hb=e037fab727a9eb80c33f1693fcd6d0b67b84da32;hpb=bd230d3ba29021292ab66acd507242f66e04c904 diff --git a/test/bin/bomb.pl b/test/bin/bomb.pl index a84f40b..2dde3d4 100755 --- a/test/bin/bomb.pl +++ b/test/bin/bomb.pl @@ -1,10 +1,11 @@ -#!/usr/local/bin/perl -# Copyright (c) 2014 IndexData ApS. http://indexdata.com +#!/usr/bin/perl +# Copyright (c) 2014 Index Data ApS. http://indexdata.com # # bomb.pl - wrapper to stop a process after N seconds # use Getopt::Long; +use POSIX ":sys_wait_h"; use strict; use warnings; @@ -12,39 +13,11 @@ use warnings; my $debug = 0; my $help; my $timeout = 100; +my $pid; binmode \*STDOUT, ":utf8"; binmode \*STDERR, ":utf8"; -# timeout handler -sub set_alarm { - my $time = shift; - my $message = shift || ""; - - $time = 100 if !defined $time; - - $SIG{ALRM} = sub { - - warn "Time out alarm $time\n"; - - # sends a hang-up signal to all processes in the current process group - # and kill running java processes - local $SIG{HUP} = "IGNORE"; - kill 1, -$$; - - local $SIG{TERM} = "IGNORE"; - kill 15, -$$; - kill 15, -$$; - - warn "Send a hang-up to all childs.\n"; - - #exit 1; - }; - - warn "set alarm time to: $time seconds $message\n" if $debug >= 1; - alarm($time); -} - sub usage () { < \$help, "debug=i" => \$debug, - "timeout=i" => \$timeout, + "timeout=f" => \$timeout, ) or die usage; my @system = @ARGV; @@ -65,9 +38,39 @@ my @system = @ARGV; die usage if $help; die usage if !@system; -set_alarm( $timeout, join( " ", @system ) ); +# disabled - we set the CPU limit in the wrapper ./bomb +## set CPU limit, in case the alarm handler will +## be ignored +#eval { +# require BSD::Resource; +# BSD::Resource::setrlimit( "RLIMIT_CPU", $timeout, 2 * $timeout ) +# or die "Cannot set CPU limit: $!\n"; +#}; +#if ($@) { +# warn +# "WARNING: things would go more nicely with the BSD::Resource package\n"; +#} + +# +# configure signal handlers +# +$SIG{ALRM} = sub { + my $pgid = getpgrp(); + + warn "Alarm handler got called after $timeout seconds\n"; + warn "Kill now the process group $pgid\n\n"; + warn "Command: @system\n"; + + # kill process group + kill "INT", -$pgid; +}; + +# don't kill ourself +$SIG{INT} = "IGNORE"; + +alarm($timeout); system(@system) == 0 - or die "system @system failed: $?"; + or die "system('@system') failed: ?='$?', !='$!'\n"; -exit(0); +1;