Skip to content

Commit

Permalink
fix: avoid failure when daemon is started in environment with missing…
Browse files Browse the repository at this point in the history
… IDS file

Log an error for each not found IDS files
  • Loading branch information
g-bougard committed Jan 26, 2022
1 parent 4ce022a commit ef06ac1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/GLPI/Agent/Daemon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,13 @@ sub ApplyServiceOptimizations {
# Preload all IDS databases to avoid reload them all the time during inventory
my @planned = map { $_->plannedTasks() } $self->getTargets();
if (grep { /^inventory$/i } @planned) {
my %datadir = ( datadir => $self->{datadir} );
getPCIDeviceVendor(%datadir);
getUSBDeviceVendor(%datadir);
getEDIDVendor(%datadir);
my %params = (
logger => $self->{logger},
datadir => $self->{datadir}
);
getPCIDeviceVendor(%params);
getUSBDeviceVendor(%params);
getEDIDVendor(%params);
}
}

Expand Down
14 changes: 11 additions & 3 deletions lib/GLPI/Agent/Tools/Generic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -366,21 +366,28 @@ sub _getIdsFile {
# Sort by creation time
my @sorted_files = sort { $files{$a} <=> $files{$b} } keys(%files);

unless (@sorted_files) {
$params{logger}->error("$params{idsfile} not found") if $params{logger};
return;
}

return pop @sorted_files;
}

sub _loadPCIDatabase {
my (%params) = @_;

my $file = _getIdsFile( %params, idsfile => "pci.ids" );
my $file = _getIdsFile( %params, idsfile => "pci.ids" )
or return;

($PCIVendors, $PCIClasses) = _loadDatabase( file => $file );
}

sub _loadUSBDatabase {
my (%params) = @_;

my $file = _getIdsFile( %params, idsfile => "usb.ids" );
my $file = _getIdsFile( %params, idsfile => "usb.ids" )
or return;

($USBVendors, $USBClasses) = _loadDatabase( file => $file );
}
Expand Down Expand Up @@ -424,7 +431,8 @@ sub _loadDatabase {
sub _loadEDIDDatabase {
my (%params) = @_;

my $file = _getIdsFile( %params, idsfile => "edid.ids" );
my $file = _getIdsFile( %params, idsfile => "edid.ids" )
or return;

my $handle = getFileHandle( file => $file, local => 1 );
return unless $handle;
Expand Down

0 comments on commit ef06ac1

Please sign in to comment.