Merge branch 'ent-1775-SNMPServer.pm-CDE' into 'develop'

added exception handler

See merge request artica/pandorafms!3119
This commit is contained in:
Alejandro Fraguas 2020-03-26 10:32:08 +01:00
commit 48fc714ba3
1 changed files with 12 additions and 3 deletions

View File

@ -28,6 +28,8 @@ use Time::Local;
use Time::HiRes qw(usleep); use Time::HiRes qw(usleep);
use XML::Simple; use XML::Simple;
use Scalar::Util qw(looks_like_number);
# Default lib dir for RPM and DEB packages # Default lib dir for RPM and DEB packages
use lib '/usr/lib/perl5'; use lib '/usr/lib/perl5';
@ -542,8 +544,15 @@ sub DESTROY {
my $self = shift; my $self = shift;
if ($self->{'snmp_trapd'} ne 'manual') { if ($self->{'snmp_trapd'} ne 'manual') {
system ("kill -9 `cat /var/run/pandora_snmptrapd.pid 2>$DEVNULL`"); my $pid_file = '/var/run/pandora_snmptrapd.pid';
unlink ('/var/run/pandora_snmptrapd.pid'); if (-e $pid_file) {
my $pid = `cat $pid_file 2>$DEVNULL`;
if (defined($pid) && ("$pid" ne "") && looks_like_number($pid)) {
system ("kill -9 $pid");
}
unlink ($pid_file);
}
} }
} }