From db3313c76d8942a7b9feaab5a1262e1b5c0b7fb6 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 25 Mar 2020 15:42:55 +0100 Subject: [PATCH] added exception handler --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index f26cb4c3d9..5a5a741525 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -28,6 +28,8 @@ use Time::Local; use Time::HiRes qw(usleep); use XML::Simple; +use Scalar::Util qw(looks_like_number); + # Default lib dir for RPM and DEB packages use lib '/usr/lib/perl5'; @@ -540,10 +542,17 @@ sub reset_if_truncated($$) { ############################################################################### sub DESTROY { my $self = shift; - + if ($self->{'snmp_trapd'} ne 'manual') { - system ("kill -9 `cat /var/run/pandora_snmptrapd.pid 2>$DEVNULL`"); - unlink ('/var/run/pandora_snmptrapd.pid'); + my $pid_file = '/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); + } } }