Moved thread setup to read_config to allow setting it via

remote_config.

(cherry picked from commit dc2310362a)
This commit is contained in:
Ramon Novoa 2015-04-22 11:11:49 +02:00
parent 796e7b1f33
commit 50ef10bf72
1 changed files with 26 additions and 24 deletions

50
pandora_agents/unix/pandora_agent Normal file → Executable file
View File

@ -752,8 +752,31 @@ sub read_config (;$) {
$RemoteConfFile = "$AgentMD5.conf"; $RemoteConfFile = "$AgentMD5.conf";
$RemoteMD5File = "$AgentMD5.md5"; $RemoteMD5File = "$AgentMD5.md5";
# Set the maximun number of threads # Load thread support if agent_threads is greater than 1.
$ThreadSem = Thread::Semaphore->new ($Conf{'agent_threads'}) if defined ($Sem); if ($Conf{'agent_threads'} > 1) {
eval {
local $SIG{__DIE__};
require threads;
require threads::shared;
require Thread::Semaphore;
};
if (!$@) {
$Sem = Thread::Semaphore->new;
$ThreadSem = Thread::Semaphore->new ($Conf{'agent_threads'});
threads::shared::share (\$Xml);
threads::shared::share (\$Sem);
log_message ('log', 'Using thread library.');
} else {
log_message ('log', 'Thread library is not available. agent_threads is set to 1 (disabled).');
$Conf{'agent_threads'} = 1;
$Sem = undef;
$ThreadSem = undef;
}
} else {
$Sem = undef;
$ThreadSem = undef;
log_message ('log', 'Thread is disabled.');
}
# Set tentacle client options # Set tentacle client options
if ($Conf{'transfer_mode'} eq 'tentacle') { if ($Conf{'transfer_mode'} eq 'tentacle') {
@ -1200,7 +1223,7 @@ sub guess_os_version ($) {
################################################################################ ################################################################################
sub exec_module ($) { sub exec_module ($) {
my $module = shift; my $module = shift;
print "THREAD " . threads->tid() . " EXECUTING MODULE " . $module->{'name'} . "\n";
# Need something to execute # Need something to execute
if ($module->{'func'} == 0) { if ($module->{'func'} == 0) {
$ThreadSem->up () if (defined ($ThreadSem) && $Conf{'agent_threads'} > 1); $ThreadSem->up () if (defined ($ThreadSem) && $Conf{'agent_threads'} > 1);
@ -2059,27 +2082,6 @@ error ("Temporal directory '" . $Conf{'temporal'} . "' does not exist.") unless
$Conf{'server_path'} = fix_directory ($Conf{'server_path'}); $Conf{'server_path'} = fix_directory ($Conf{'server_path'});
$Conf{'secondary_server_path'} = fix_directory ($Conf{'secondary_server_path'}); $Conf{'secondary_server_path'} = fix_directory ($Conf{'secondary_server_path'});
# Load thread support if agent_threads is greater than 1.
if ($Conf{'agent_threads'} > 1) {
eval {
local $SIG{__DIE__};
require threads;
require threads::shared;
require Thread::Semaphore;
};
if (!$@) {
$Sem = Thread::Semaphore->new;
threads::shared::share (\$Xml);
threads::shared::share (\$Sem);
log_message ('log', 'Using thread library.');
} else {
log_message ('log', 'Thread library is not available. agent_threads is set to 1 (disabled).');
$Conf{'agent_threads'} = 1;
}
} else {
log_message ('log', 'Thread is disabled.');
}
# Startup delay # Startup delay
log_message ('log', 'Sleeping for ' . $Conf{'delayed_startup'} . ' seconds.') if ($Conf{'delayed_startup'} > 0); log_message ('log', 'Sleeping for ' . $Conf{'delayed_startup'} . ' seconds.') if ($Conf{'delayed_startup'} > 0);
sleep ($Conf{'delayed_startup'}); sleep ($Conf{'delayed_startup'});