alfred: bat-hosts.lua: 'alfred -r' can fail with no output, so retry 3 times
Signed-off-by: Gui Iribarren <gui@altermundi.net>
This commit is contained in:
parent
e912da6625
commit
7b851e5f19
|
@ -12,7 +12,7 @@ include $(TOPDIR)/rules.mk
|
||||||
#
|
#
|
||||||
PKG_NAME:=alfred
|
PKG_NAME:=alfred
|
||||||
PKG_VERSION:=2017.0
|
PKG_VERSION:=2017.0
|
||||||
PKG_RELEASE:=0
|
PKG_RELEASE:=1
|
||||||
PKG_MD5SUM:=2e9ae897b1d477f14d06389eb7c1f97b
|
PKG_MD5SUM:=2e9ae897b1d477f14d06389eb7c1f97b
|
||||||
PKG_HASH:=f8d6d83d2ce30b2238354ce12073285387c0f4ca1a28060390ff50b411b50fa8
|
PKG_HASH:=f8d6d83d2ce30b2238354ce12073285387c0f4ca1a28060390ff50b411b50fa8
|
||||||
|
|
||||||
|
|
|
@ -87,19 +87,24 @@ end
|
||||||
|
|
||||||
local function receive_bat_hosts()
|
local function receive_bat_hosts()
|
||||||
-- read raw chunks from alfred, convert them to a nested table and call write_bat_hosts
|
-- read raw chunks from alfred, convert them to a nested table and call write_bat_hosts
|
||||||
local fd = io.popen("alfred -r " .. type_id)
|
-- "alfred -r" can fail in slave nodes (returns empty stdout), so:
|
||||||
--[[ this command returns something like
|
-- check output is not null before writing /tmp/bat-hosts, and retry 3 times before giving up.
|
||||||
{ "54:e6:fc:b9:cb:37", "00:11:22:33:44:55 ham_wlan0\x0a00:22:33:22:33:22 ham_eth0\x0a" },
|
for n = 1, 3 do
|
||||||
{ "90:f6:52:bb:ec:57", "00:22:33:22:33:23 spam\x0a" },
|
local fd = io.popen("alfred -r " .. type_id)
|
||||||
]]--
|
--[[ this command returns something like
|
||||||
|
{ "54:e6:fc:b9:cb:37", "00:11:22:33:44:55 ham_wlan0\x0a00:22:33:22:33:22 ham_eth0\x0a" },
|
||||||
|
{ "90:f6:52:bb:ec:57", "00:22:33:22:33:23 spam\x0a" },
|
||||||
|
]]--
|
||||||
|
|
||||||
if fd then
|
if fd then
|
||||||
local output = fd:read("*a")
|
local output = fd:read("*a")
|
||||||
if output then
|
fd:close()
|
||||||
assert(loadstring("rows = {" .. output .. "}"))()
|
if output and output ~= "" then
|
||||||
write_bat_hosts(rows)
|
assert(loadstring("rows = {" .. output .. "}"))()
|
||||||
|
write_bat_hosts(rows)
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
fd:close()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue