Skip to content

Commit

Permalink
fix: Keep compatibility with older platforms when using Parallel::For…
Browse files Browse the repository at this point in the history
…kManager

Closes #521
  • Loading branch information
g-bougard committed Nov 13, 2023
1 parent 13f17fc commit 5fc152a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ netdiscovery/netinventory:
* Add ESX & RemoteInventory scanning support to netdiscovery
* fix #327: Make task expiration a function of backend-collect-timeout configuration
Add backend-collect-timeout support to glpi-netdiscovery & glpi-netinventory scripts
* fix #521: Keep compatibility with older platforms when using Parallel::ForkManager

esx:
* Refactoring to share more code between task & glpi-esx script and to support netscan
Expand Down
12 changes: 6 additions & 6 deletions lib/GLPI/Agent/Task/NetDiscovery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ sub run {
unless ($size) {
$self->{logger}->debug("no valid block found for job $jobid");
# Always send control messages from a worker to avoid issue on win32
$manager->start_child( 0, sub {
unless ($manager->start(0)) {
# Support glpi-netdiscovery --control option & local task from ToolBox
$self->{_control} = $job->control;
unless ($job->localtask) {
Expand All @@ -226,8 +226,8 @@ sub run {
$self->_sendStopMessage($jobid);
$self->_sendStopMessage($jobid);
}
return;
});
$manager->finish();
}
$manager->wait_all_children();
delete $jobs{$jobid};
next;
Expand Down Expand Up @@ -327,7 +327,7 @@ sub run {
my $max = $job->max_threads;
$self->{logger}->debug("starting job $jobid with $size ip".($size > 1 ? "s" : "")." to scan using $max worker".($max > 1 ? "s" : ""));
# Always send control messages from a worker to avoid issue on win32
$manager->start_child( 0, sub {
unless ($manager->start(0)) {
# Support glpi-netdiscovery --control option & local task from ToolBox
$self->{_control} = $job->control;

Expand All @@ -336,8 +336,8 @@ sub run {
# Also send block size to the server
$self->_sendBlockMessage($jobid, $size);
}
return;
});
$manager->finish();
}
$manager->wait_all_children();
}

Expand Down
6 changes: 4 additions & 2 deletions lib/GLPI/Agent/Task/NetInventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ sub run {
my $pid = $job->pid() || $pid_index++;

# send initial message to server in a worker unless it supports newer protocol
$manager->start_child(0, sub { $self->_sendStartMessage($pid) })
unless $skip_start_stop;
unless ($skip_start_stop || $manager->start(0)) {
$self->_sendStartMessage($pid);
$manager->finish();
}

# Only keep job if it has devices to scan
my @devices = $job->devices()
Expand Down

0 comments on commit 5fc152a

Please sign in to comment.