That is a bad idea for many reasons.
update: i'm on winblows 9x here, in case you was wonderin';)
Also, exit from a sigint handler is also a bad idea, just as bad as a die, or a warn, or anything, which doesn't actually terminate the program like a kill.
First, that is not the proper way to exit a program after capturing sigint, you gotta kill youself (i found out the hard way), like:
$SIG{INT} = \&zap;
sub zap {
print "You zapped me!\n";
# do some stuff
# you can't die;
# kill 6 which is ABRT doesn't work (crash)
# under strict in indigoperl for some reason
kill 15, $$; # TERM = 15, forgot where you import it from
}
sleep 1 while 1;
Second, because of the funky stuff that happens when you capture signals in perl, you can do a few things before killing yourself, but you can't go back into an infinite loop, cause things get pretty messed up. I was gonna suggest something like (code recycled from my personal tests):
#!/usr/bin/perl -w
use strict;
use sigtrap 'handler' => \&CLEANUP, 'INT';
# $SIG{INT}=\&CLEANUP;
=head1 modulus (%) explained
=pod
Binary ``%'' computes the modulus of two numbers. Given integer opera
+nds
$a and $b: If $b is positive, then $a % $b is $a minus the largest
multiple of $b that is not greater than $a. If $b is negative, then
$a % $b is $a minus the smallest multiple of $b that is not less than
$a (i.e. the result will be less than or equal to zero).
=cut
$|++; # i like a free flow of ideas
&theloopy;
sub theloopy
{
my($a,$b)=(0,0);
while(11)
{
$a = '|' if(($b % 4) == 1); #|
$a = '/' if(($b % 4) == 2); #/
$a = '-' if(($b % 4) == 3); #-
$a = '\\' if(($b % 4) == 0); #\
print "\r $a$a$a infinite loop";
select(undef,undef,undef,0.25); # sleep
$b++;
}
}
sub CLEANUP
{
print "\n caught \$SIG{INT}",@_,"\n";
my $shallwedie = <STDIN>;
print "shall we die (666)\n";
$shallwedie = <STDIN>;
chomp $shallwedie;
# $SIG{'ABRT'} = DEFAULT;
# just make sure
# do your cleanup stuff
# and then kill yourself
#kill 'ABRT', $$; # ABRT = 6
if($shallwedie eq '666')
{
print "the dying\n";
kill 'TERM', $$; # TERM = 15
kill 6, $$;
}
else
{
print "the loopy\n";
&theloopy();
}
#exit;
}
But as you can see if you run it, it does some weird things (or things i just don't understand, which might be the reason my example/strategy failed, in which case explanation is welcome ;)
update: indeed having a label, and using a goto will not work, and it will crash perl.
But what's this you say about about the handler returning someplace?
Ok, it has been my experience that it returns to what your script was doing before, but another sigint will just kill the script, and i that is not desired behaviour.
So there must be some kind of sigint counter?
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;" |