diff --git a/Changes b/Changes index 2753201c90..588d50800f 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ core: 'use parent' and as fields pragma is not used (see 'base' man) * Logger refactoring: no more an Exporter based class to simplify its usage and as Logger object should be commonly shared everywhere it is used. +* Fix command run to also time out while an alarm has been set * Few code refactoring inventory: @@ -22,6 +23,7 @@ inventory: * Fix #349: Include last logged user as usual computer user on win32 platform * Linux distro: Add support for reading os-release file and removing LSB support * Fix Solaris drives df output parsing adding better zfs handling +* Make backend-collect-timeout working even while waiting on command output netdiscovery/netinventory: * Bump NetDiscovery & NetInventory task version to 2.4 diff --git a/lib/FusionInventory/Agent/Tools.pm b/lib/FusionInventory/Agent/Tools.pm index d106fc55e0..56b8844fe3 100644 --- a/lib/FusionInventory/Agent/Tools.pm +++ b/lib/FusionInventory/Agent/Tools.pm @@ -54,8 +54,6 @@ our @EXPORT = qw( slurp ); -my $nowhere = $OSNAME eq 'MSWin32' ? 'nul' : '/dev/null'; - # this trigger some errors under win32: # Anonymous function called in forbidden scalar context if ($OSNAME ne 'MSWin32') { @@ -296,6 +294,7 @@ sub getDirectoryHandle { return $handle; } +my $cmdtemplate = $OSNAME eq 'MSWin32' ? "%s 2>nul" : "exec %s 2>/dev/null"; sub getFileHandle { my (%params) = @_; @@ -320,12 +319,16 @@ sub getFileHandle { local $ENV{LANG} = 'C'; # Ignore 'Broken Pipe' warnings on Solaris local $SIG{PIPE} = 'IGNORE' if $OSNAME eq 'solaris'; - if (!open $handle, '-|', $params{command} . " 2>$nowhere") { + my $command = sprintf($cmdtemplate, $params{command}); + my $cmdpid = open($handle, '-|', $command); + if (!$cmdpid) { $params{logger}->error( "Can't run command $params{command}: $ERRNO" ) if $params{logger}; return; } + # Kill command if a timeout was set + $SIG{ALRM} = sub { kill 'KILL', $cmdpid ; die "alarm\n"; } if $SIG{ALRM}; last SWITCH; } if ($params{string}) {