Skip to content

Commit

Permalink
fix: Update error reported when syscall fails to report network inter…
Browse files Browse the repository at this point in the history
…face speed on linux
  • Loading branch information
g-bougard committed Dec 18, 2023
1 parent b7e81f7 commit 3d2b7b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/Task/Inventory/Linux/Networks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ sub _getInterfaces {
} else {
$logger->debug_result(
action => 'retrieving interface speed from syscall',
status => 'syscall failed'
status => $infos && $infos->{ERROR} ? $infos->{ERROR} : 'syscall failed'
);
}
}
Expand Down
9 changes: 6 additions & 3 deletions lib/GLPI/Agent/Tools/Linux.pm
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,13 @@ sub getInterfacesInfosFromIoctl {
return unless $params{interface};

# We don't support this feature on remote inventory
return if $GLPI::Agent::Tools::remote;
return { ERROR => "syscall not remotely supported" }
if $GLPI::Agent::Tools::remote;

my $logger = $params{logger};

socket(my $socket, PF_INET, SOCK_DGRAM, 0)
or return ;
or return { ERROR => "can't open socket" };

# Pack command in ethtool_cmd struct
my $cmd = pack("L3SC6L2SC2L3", ETHTOOL_GSET);
Expand All @@ -621,7 +622,8 @@ sub getInterfacesInfosFromIoctl {
my $request = pack("a16p", $params{interface}, $cmd);

my $retval = ioctl($socket, SIOCETHTOOL, $request) || -1;
return if ($retval < 0);
return { ERROR => "$!" }
if $retval < 0;

# Unpack returned datas
my @datas = unpack("L3SC6L2SC2L3", $cmd);
Expand All @@ -634,6 +636,7 @@ sub getInterfacesInfosFromIoctl {
# Forget speed value if got unknown speed special value
if ($datas->{SPEED} == SPEED_UNKNOWN) {
delete $datas->{SPEED};
$datas->{ERROR} = "unknown speed found";
$logger->debug2("Unknown speed found on $params{interface}")
if $logger;
}
Expand Down

0 comments on commit 3d2b7b3

Please sign in to comment.