From d0b78c01aaecdb8ccf2f5757de49fa3b43b1e537 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 21 Feb 2023 03:12:29 +0100 Subject: [PATCH] Hotfix followup to #10139 (#10151) Don't blow up if we fall back to exec'ing ping Fix https://github.com/koreader/koreader/pull/10139#issuecomment-1437678458 --- frontend/device/generic/device.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 8d938d912..72a129cc2 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -540,9 +540,9 @@ function Device:ping4(ip) if socket == -1 then errno = ffi.errno() if errno == C.EPERM then - logger.dbg("Device:ping4: Opening a RAW ICMP socket requires CAP_NET_RAW capabilities!") + logger.dbg("Device:ping4: opening a RAW ICMP socket requires CAP_NET_RAW capabilities!") else - logger.dbg("Device:ping4: Raw ICMP socket:", ffi.string(C.strerror(errno))) + logger.dbg("Device:ping4: raw ICMP socket:", ffi.string(C.strerror(errno))) end --- Fall-back to the ping CLI tool, in the hope that it's setuid... if self:isKindle() and self:hasDPad() then @@ -841,9 +841,11 @@ function Device:retrieveNetworkInfo() if default_gw then local ok, rtt = self:ping4(default_gw) if ok then - rtt = string.format("%.3f", rtt * 1/1000) -- i.e., time.to_ms w/o flooring table.insert(results, _("Gateway ping successful")) - table.insert(results, T(_("RTT: %1 ms"), rtt)) + if rtt then + rtt = string.format("%.3f", rtt * 1/1000) -- i.e., time.to_ms w/o flooring + table.insert(results, T(_("RTT: %1 ms"), rtt)) + end else table.insert(results, _("Gateway ping FAILED")) if rtt then