Skip to content

Commit 926bc91

Browse files
authored
Merge pull request #2229 from IrimieBogdan/maint-mac-check
(maint) Catch exceptions when resolving mac, this can happen on Jruby
2 parents 8dffc51 + be370fa commit 926bc91

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/facter/resolvers/networking_linux_resolver.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ def retrieve_interface_info(mtu_and_indexes)
8383

8484
def extract_mac_address(interface)
8585
mac = get_bonded_interface_mac(interface.name)
86-
if mac.nil?
87-
if Socket.const_defined? :PF_LINK
88-
mac = interface.addr&.getnameinfo&.first #sometimes it returns localhost, ip but mac also
89-
elsif Socket.const_defined? :PF_PACKET
90-
return if interface.addr.nil? || interface.addr.inspect_sockaddr.nil?
91-
92-
mac = interface.addr&.inspect_sockaddr[/hwaddr=([\h:]+)/, 1]
86+
begin
87+
if mac.nil?
88+
if Socket.const_defined? :PF_LINK
89+
mac = interface.addr&.getnameinfo&.first #sometimes it returns localhost, ip but mac also
90+
elsif Socket.const_defined? :PF_PACKET
91+
return if interface.addr.nil? || interface.addr.inspect_sockaddr.nil?
92+
93+
mac = interface.addr&.inspect_sockaddr[/hwaddr=([\h:]+)/, 1]
94+
end
9395
end
96+
rescue StandardError => e
97+
log.debug("Could not read mac, got #{e}")
9498
end
9599
mac if !mac.nil? && mac != '00:00:00:00:00:00' && mac =~ /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/
96100
end

0 commit comments

Comments
 (0)