From 2ab3e48286008694c30aa12fe7a92f22b33326a0 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Fri, 28 Jun 2019 18:57:20 +0200 Subject: [PATCH] Make sure we only pass a single IP to ping For some mysterious reason, I have a duplicate default gateway on my Forma, one with no metrics, and a proper one. This ensures we pick the proper one. I'm fairly sure this is temporary insanity on the part of my device, but, still, it can't hurt. route -n: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 208 0 0 eth0 192.168.0.0 0.0.0.0 255.255.255.0 U 208 0 0 eth0 ip r: default via 192.168.0.1 dev eth0 default via 192.168.0.1 dev eth0 metric 208 192.168.0.0/24 dev eth0 src 192.168.0.49 metric 208 --- frontend/device/generic/device.lua | 4 ++-- frontend/ui/network/manager.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 352d181e9..4915e444c 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -314,9 +314,9 @@ function Device:retrieveNetworkInfo() -- NOTE: No -w flag available in the old busybox build used on Legacy Kindles... local pingok if self:isKindle() and self:hasKeyboard() then - pingok = os.execute("ping -q -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null") + pingok = os.execute("ping -q -c 2 `ip r | grep default | tail -n 1 | cut -d ' ' -f 3` > /dev/null") else - pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | cut -d ' ' -f 3` > /dev/null") + pingok = os.execute("ping -q -w 3 -c 2 `ip r | grep default | tail -n 1 | cut -d ' ' -f 3` > /dev/null") end if pingok == 0 then result = result .. "Gateway ping successful" diff --git a/frontend/ui/network/manager.lua b/frontend/ui/network/manager.lua index 5c3c7301a..9cb91cc25 100644 --- a/frontend/ui/network/manager.lua +++ b/frontend/ui/network/manager.lua @@ -104,9 +104,9 @@ function NetworkMgr:isConnected() -- `-c1` try only once; `-w2` wait 2 seconds -- NOTE: No -w flag available in the old busybox build used on Legacy Kindles... if Device:isKindle() and Device:hasKeyboard() then - return 0 == os.execute([[ping -c1 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]]) + return 0 == os.execute([[ping -c1 $(/sbin/route -n | awk '$4 == "UG" {print $2}' | tail -n 1)]]) else - return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}')]]) + return 0 == os.execute([[ping -c1 -w2 $(/sbin/route -n | awk '$4 == "UG" {print $2}' | tail -n 1)]]) end end end