AGI dies on user hangup

I have been unable to capture user hangups with my AGI script. Instead of returning -1 or 0 and ‘hangup’, the script just seems to terminate. I have coded it two ways. In the first way I just made the calls and captured the return value. In the second way I used the Perl Asterisk::AGI module. I get the same behaviour each way. In the code below, it never seems to get to the HandleHangup subrouting. I never see anything come back on STDERR and I don’t get the file created either.

My extensions.conf file is pretty simple with just two real lines. The first calls the agi script using DeadAGI. The second one does a hangup when the script ends.

Here is the script that uses AGI Module.

#!/usr/bin/perl -w
use Asterisk::AGI;
use strict;
$|=1; #This makes the output stream rather than buffer

my %AGIVariables; #the hash I store the AGI default variables in
my $MyAGI = new Asterisk::AGI;

send callback reference

$MyAGI->setcallback(&HandleHangup);

$MyAGI->answer();

%AGIVariables=$MyAGI->ReadParse();

$MyAGI->record_file(’/tmp/CLibTest’,‘wav’,’#’,‘180000’,‘1’,‘10’);
sleep (5);
$MyAGI->stream_file(’/tmp/CLibTest’, ‘""’);

sub HandleHangup{
print STDERR “Got to handlehangup!!!\n”;
my $FlagFile=’/tmp/TestCLibFlagFile’;
my $now = time;
utime $now, $now, $FlagFile;
exit;
}

Any tips, hints, etc. would be greatly appreciated. Thanks.

Here is a snippet from the alternate way I did it (without using the class library).

    print "RECORD FILE $StorageLoc/VF_$RecordFileName wav # 180000 BEEP s=10\n"; 
    $result=<STDIN>;
    print STDERR "MyAGI RECORD FILE Result:   $result\n";
    ($code,$value)=split(/result=/,$result);
    chomp $value;
    @RecordResultDetail=split(/ /,$value);  
    if ($RecordResultDetail[0]=~/^-1/){  
        $IHungUp='true'; #actually they didn't hang up,  write error. 
    }
    if ($RecordResultDetail[0]==0 && $RecordResultDetail[1] eq '(hangup)'){
            print STDERR "caught the hang up by the user\n";
        $IHungUp='true'; #they actually did hang up.
    }

For some reason it just dies if the user hangs up in the middle of the recording. The file gets written, but it never even seems to get to the error handling code after it.

It seems that catching the HUP is the right thing to do.

$SIG{HUP} = “IGNORE”;

I haven’t run through all my test cases, but it looks promising.