From b7c14d49fd76417ed53f30a92df5448841b6ff94 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 4 Jun 2019 15:10:05 +0200 Subject: [PATCH] threads-shared returns --- pandora_server/lib/PandoraFMS/Core.pm | 48 ++++++++++++++------------ pandora_server/lib/PandoraFMS/Tools.pm | 3 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 0dbc8f963a..548ddafd06 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4859,32 +4859,36 @@ sub pandora_process_policy_queue ($) { logger($pa_config, "Starting policy queue patrol process.", 1); while($THRRUN == 1) { + eval {{ + local $SIG{__DIE__}; - # If we are not the master server sleep and check again. - if (pandora_is_master($pa_config) == 0) { - sleep ($pa_config->{'server_threshold'}); - next; - } + # If we are not the master server sleep and check again. + if (pandora_is_master($pa_config) == 0) { + sleep ($pa_config->{'server_threshold'}); + next; + } + + my $operation = enterprise_hook('get_first_policy_queue', [$dbh]); + next unless (defined ($operation) && $operation ne ''); + + if($operation->{'operation'} eq 'apply' || $operation->{'operation'} eq 'apply_db') { + enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}, $operation->{'operation'}]); + } + elsif($operation->{'operation'} eq 'delete') { + if($operation->{'id_agent'} == 0) { + enterprise_hook('pandora_purge_policy_agents', [$dbh, $pa_config, $operation->{'id_policy'}]); + } + else { + enterprise_hook('pandora_delete_agent_from_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}]); + } + } + + enterprise_hook('pandora_finish_queue_operation', [$dbh, $operation->{'id'}]); + }}; # Check the queue each 5 seconds - sleep (5); + sleep(5); - my $operation = enterprise_hook('get_first_policy_queue', [$dbh]); - next unless (defined ($operation) && $operation ne ''); - - if($operation->{'operation'} eq 'apply' || $operation->{'operation'} eq 'apply_db') { - enterprise_hook('pandora_apply_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}, $operation->{'id'}, $operation->{'operation'}]); - } - elsif($operation->{'operation'} eq 'delete') { - if($operation->{'id_agent'} == 0) { - enterprise_hook('pandora_purge_policy_agents', [$dbh, $pa_config, $operation->{'id_policy'}]); - } - else { - enterprise_hook('pandora_delete_agent_from_policy', [$dbh, $pa_config, $operation->{'id_policy'}, $operation->{'id_agent'}]); - } - } - - enterprise_hook('pandora_finish_queue_operation', [$dbh, $operation->{'id'}]); } db_disconnect($dbh); diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 02bb9f05ea..6271698c03 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -29,6 +29,7 @@ use Sys::Syslog; use Scalar::Util qw(looks_like_number); use LWP::UserAgent; use threads; +use threads::shared; # New in 3.2. Used to sendmail internally, without external scripts # use Module::Loaded; @@ -1864,7 +1865,7 @@ sub stop_server_threads { $THRRUN = 0; foreach my $thr (@ServerThreads) { - $thr->detach(); + $thr->join(); } @ServerThreads = ();