From 5fc152ac4a20a55ff56bf927a04ddbf38031c0a3 Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Mon, 13 Nov 2023 18:50:42 +0100 Subject: [PATCH] fix: Keep compatibility with older platforms when using Parallel::ForkManager Closes #521 --- Changes | 1 + lib/GLPI/Agent/Task/NetDiscovery.pm | 12 ++++++------ lib/GLPI/Agent/Task/NetInventory.pm | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index ef1869683..b6951bf13 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/GLPI/Agent/Task/NetDiscovery.pm b/lib/GLPI/Agent/Task/NetDiscovery.pm index bb52cd3c1..2b374f9bc 100644 --- a/lib/GLPI/Agent/Task/NetDiscovery.pm +++ b/lib/GLPI/Agent/Task/NetDiscovery.pm @@ -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) { @@ -226,8 +226,8 @@ sub run { $self->_sendStopMessage($jobid); $self->_sendStopMessage($jobid); } - return; - }); + $manager->finish(); + } $manager->wait_all_children(); delete $jobs{$jobid}; next; @@ -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; @@ -336,8 +336,8 @@ sub run { # Also send block size to the server $self->_sendBlockMessage($jobid, $size); } - return; - }); + $manager->finish(); + } $manager->wait_all_children(); } diff --git a/lib/GLPI/Agent/Task/NetInventory.pm b/lib/GLPI/Agent/Task/NetInventory.pm index a4fed8210..9abedf355 100644 --- a/lib/GLPI/Agent/Task/NetInventory.pm +++ b/lib/GLPI/Agent/Task/NetInventory.pm @@ -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()