From b556f8ae29944962d35f302ec1dd345fe8ec25f1 Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Tue, 19 Dec 2023 18:52:08 +0100 Subject: [PATCH] fix: Fix blocked logger event during netscan on win32 --- Changes | 3 +++ lib/GLPI/Agent/Daemon.pm | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 2213848f3..acfce6f2b 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ core: for trusted clients * Update local target API to support getFullPath() & setFullPath() calls * Handle '.' local target when run as a service to save inventories in vardir +* Reduce internal IPC event supported size +* To optimize IPC support, read all event messages before triggering events inventory: * PR #531: Add SentinelOne Antivirus support on Linux, thanks to @MarcSamD @@ -55,6 +57,7 @@ toolbox: * Fix wrong remote inventory results when using a short timeout for quickier detection * Handle agent folder as vardir folder when agent is running as a service * Fix netscan task fails to submit remote inventories with JSON protocol +* Fix locking on logger IPC events when running netscan for server target on win32 injector: * fix #537: Make -x, --xml-ua & --json-ua options equivalent and update help text diff --git a/lib/GLPI/Agent/Daemon.pm b/lib/GLPI/Agent/Daemon.pm index ddf69a87b..3a40f7df4 100644 --- a/lib/GLPI/Agent/Daemon.pm +++ b/lib/GLPI/Agent/Daemon.pm @@ -453,6 +453,7 @@ sub handleChildren { my $child = $self->{_fork}->{$pid}; # Check if any forked process is communicating + my @messages; delete $child->{in} unless $child->{in} && $child->{in}->opened; while ($child->{in} && $child->{pollin} && $child->{poll} && &{$child->{poll}}($child->{pollin})) { my $msg = " " x 5; @@ -465,7 +466,7 @@ sub handleChildren { if $child->{in}->sysread($len, 2); if ($len) { my $event; - $self->_trigger_event($event) + push @messages, $event if $child->{in}->sysread($event, $len); } } @@ -473,6 +474,9 @@ sub handleChildren { $count++; } + # Trigger events after they have been read + map { $self->_trigger_event($_) } @messages; + # Check if any forked process has been finished waitpid($pid, WNOHANG) or next; @@ -638,7 +642,8 @@ sub forked_process_event { return unless $self->forked() && defined($event); return unless length($event); - if (length($event) > 65535) { + # On MSWin32, syswrite can block if header+size+event is greater than 512 bytes + if (length($event) > 505) { my ($type) = split(",", $event) or return; $type = substr($event, 0, 64) if length($type) > 64;