X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fbin%2Fbomb.pl;h=b91f0499c68337651af9dce0788fb3598de68916;hb=238734efd7a190c653631ac2db4624c6761df8ec;hp=bff7f687b20ba0f7e682a02da9591dbbd9fe5b8e;hpb=d0c8fb0f03f7bac469fc2543d93b84433256700b;p=mkws-moved-to-github.git diff --git a/test/bin/bomb.pl b/test/bin/bomb.pl index bff7f68..b91f049 100755 --- a/test/bin/bomb.pl +++ b/test/bin/bomb.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright (c) 2014 IndexData ApS. http://indexdata.com +# Copyright (c) 2014 Index Data ApS. http://indexdata.com # # bomb.pl - wrapper to stop a process after N seconds # @@ -41,27 +41,32 @@ die usage if !@system; # set CPU limit, in case the alarm handler will # be ignored eval { - require BSD::Resource2; - setrlimit("RLIMIT_CPU", $timeout, 2*$timeout) or die "Cannot set CPU limit: $!\n"; + require BSD::Resource; + BSD::Resource::setrlimit( "RLIMIT_CPU", $timeout, 2 * $timeout ) + or die "Cannot set CPU limit: $!\n"; }; if ($@) { - warn "Please install the package BSD::Resource!\n\n$@\n"; + warn + "WARNING: things would go more nicely with the BSD::Resource package\n"; } - # -# use fork/exec instead system() +# configure signal handlers # -$pid = fork(); -die "fork() failed: $!" unless defined $pid; +$SIG{ALRM} = sub { + my $pgid = getpgrp(); -# child -if ($pid) { - alarm($timeout); - exec(@system) or die "exec @system: $!\n"; -} + # kill process group + kill "INT", -$pgid; +}; -# parent -else { } +# don't kill ourself +$SIG{INT} = "IGNORE"; + +alarm($timeout); + +system(@system) == 0 + or die "system @system failed: $?"; 1; +