karma: improve error handling

This commit is contained in:
Matt Simerson 2012-06-22 23:57:43 -04:00
parent 560ce218e3
commit cdfa106b3f
2 changed files with 8 additions and 5 deletions

View File

@ -240,7 +240,7 @@ use Fcntl qw(:DEFAULT :flock LOCK_EX LOCK_NB);
use Net::IP; use Net::IP;
sub register { sub register {
my ($self, $qp ) = shift, shift; my ($self, $qp ) = (shift, shift);
$self->log(LOGERROR, "Bad arguments") if @_ % 2; $self->log(LOGERROR, "Bad arguments") if @_ % 2;
$self->{_args} = { @_ }; $self->{_args} = { @_ };
$self->{_args}{negative} ||= 1; $self->{_args}{negative} ||= 1;
@ -265,7 +265,10 @@ sub connect_handler {
my $db = $self->get_db_location(); my $db = $self->get_db_location();
my $lock = $self->get_db_lock( $db ) or return DECLINED; my $lock = $self->get_db_lock( $db ) or return DECLINED;
my $tied = $self->get_db_tie( $db, $lock ) or return DECLINED; my $tied = $self->get_db_tie( $db, $lock ) or return DECLINED;
my $key = $self->get_db_key(); my $key = $self->get_db_key() or do {
$self->log( LOGINFO, "skip, unable to get DB key" );
return DECLINED;
};
if ( ! $tied->{$key} ) { if ( ! $tied->{$key} ) {
$self->log(LOGINFO, "pass, no record"); $self->log(LOGINFO, "pass, no record");
@ -372,7 +375,7 @@ sub cleanup_and_return {
sub get_db_key { sub get_db_key {
my $self = shift; my $self = shift;
my $nip = Net::IP->new( $self->qp->connection->remote_ip ); my $nip = Net::IP->new( $self->qp->connection->remote_ip ) or return;
return $nip->intip; # convert IP to an int return $nip->intip; # convert IP to an int
}; };

View File

@ -38,7 +38,7 @@ sub usage {
list takes no arguments. list takes no arguments.
search [ naughty nice both ] search [ naughty nice both <ip> ]
and returns a list of matching IPs and returns a list of matching IPs
capture [ IP ] capture [ IP ]
@ -115,7 +115,7 @@ sub main {
elsif ( $search eq 'both' ) { elsif ( $search eq 'both' ) {
next if ! $naughty || ! $nice; next if ! $naughty || ! $nice;
} }
elsif ( is_ip() && $search ne $ip ) { elsif ( is_ip( $ARGV[1] ) && $search ne $ip ) {
next; next;
} }
}; };