Moved thread setup to read_config to allow setting it via
remote_config.
(cherry picked from commit dc2310362a
)
This commit is contained in:
parent
796e7b1f33
commit
50ef10bf72
|
@ -752,8 +752,31 @@ sub read_config (;$) {
|
|||
$RemoteConfFile = "$AgentMD5.conf";
|
||||
$RemoteMD5File = "$AgentMD5.md5";
|
||||
|
||||
# Set the maximun number of threads
|
||||
$ThreadSem = Thread::Semaphore->new ($Conf{'agent_threads'}) if defined ($Sem);
|
||||
# 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;
|
||||
$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
|
||||
if ($Conf{'transfer_mode'} eq 'tentacle') {
|
||||
|
@ -1200,7 +1223,7 @@ sub guess_os_version ($) {
|
|||
################################################################################
|
||||
sub exec_module ($) {
|
||||
my $module = shift;
|
||||
|
||||
print "THREAD " . threads->tid() . " EXECUTING MODULE " . $module->{'name'} . "\n";
|
||||
# Need something to execute
|
||||
if ($module->{'func'} == 0) {
|
||||
$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{'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
|
||||
log_message ('log', 'Sleeping for ' . $Conf{'delayed_startup'} . ' seconds.') if ($Conf{'delayed_startup'} > 0);
|
||||
sleep ($Conf{'delayed_startup'});
|
||||
|
|
Loading…
Reference in New Issue