$SIG{TERM}=$SIG{INT}=$SIG{PIPE}=$SIG{CHLD} = sub { my $sig=shift; if (defined $sth) { $sth->finish; } if (defined $stDst) { $stDst->finish; } if (defined $dbh ) { $dbh->disconnect; } if (defined $socket) { $socket->shutdown(2); } sleep(5); do { $pid = waitpid(-1,&WNOHANG); } until $pid == -1; log_notice ("Client : Caught signal SIG$sig\n"); if($sig eq 'PIPE') { log_notice ("Connection Ended\n"); } if($sig eq 'TERM' || $sig eq 'HUP' || $sig eq 'INT') { log_notice ("User Cancelling?\n"); exit 1; #User cancelling job ? } if ($connected) { $timestamp=time; if($timestamp < $midnight) { log_notice ("Client : Restarting $0\n"); log_error("End Processing $src_cdr_file\n"); exec '/home/user/$0' || log_warn ("Client : Could not exec $0\n"); exit 6; # Something is wrong if this exit is taken } # End if $timestamp log_notice ("Client : Normal Termination\n"); log_error("End Processing $src_cdr_file\n\n"); exec '/usr/bin/perl', '/home/user/$0' || log_warn ("Client : Could not exec $0\n"); exit 7; # Something is wrong if this exit is taken } # End if $connected }; # End anonymous sub