From a06e989281515344c562675b8b311ae627b96661 Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 10 Nov 2021 02:33:07 +1000 Subject: io.popen returns nil sometimes, deal with that. --- apt-panopticon.lua | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'apt-panopticon.lua') diff --git a/apt-panopticon.lua b/apt-panopticon.lua index 8543210..482a2ac 100755 --- a/apt-panopticon.lua +++ b/apt-panopticon.lua @@ -175,24 +175,21 @@ gatherIPs = function (host) -- Takes about 30 seconds to look up the lot. -- I tested using dig's -f option, it didn't seem much faster. -- The sort -r assumes that deb.devuan.org is the first alphabetically. - local dig = io.popen('dig +keepopen +noall +nottlid +answer ' .. host .. ' A ' .. host .. ' AAAA ' .. host .. ' CNAME ' .. host .. ' SRV | sort -r | uniq') - repeat - IPs = dig:read("*l") - if nil ~= IPs then - for k, t, v in IPs:gmatch("([%w_%-%.]*)%.%s*IN%s*(%a*)%s*(.*)") do - if "." == v:sub(-1, -1) then v = v:sub(1, -2) end - if nil == IP[k] then IP[k] = {} end - IP[k][v] = t - D(" DNS record " .. host .. " == " .. k .. " type " .. t .. " -> " .. v) - if t == "CNAME" then - gatherIPs(v) - IP[k][v] = IP[v] - elseif v == "SRV" then - print("SVR record found, now what do we do?") - end + local dig = APT.readCmd('dig +keepopen +noall +nottlid +answer ' .. host .. ' A ' .. host .. ' AAAA ' .. host .. ' CNAME ' .. host .. ' SRV | sort -r | uniq') + for i,IPs in ipairs(dig) do + for k, t, v in IPs:gmatch("([%w_%-%.]*)%.%s*IN%s*(%a*)%s*(.*)") do + if "." == v:sub(-1, -1) then v = v:sub(1, -2) end + if nil == IP[k] then IP[k] = {} end + IP[k][v] = t + D(" DNS record " .. host .. " == " .. k .. " type " .. t .. " -> " .. v) + if t == "CNAME" then + gatherIPs(v) + IP[k][v] = IP[v] + elseif v == "SRV" then + print("SVR record found, now what do we do?") end end - until nil == IPs + end end -- If this is the DNS-RR domain name, gather the IPs for the mirrors that mirror_list.txt says should be in it. @@ -1179,8 +1176,8 @@ else local APT_args = APT.args local APT_logFile = APT.logFile local debians = {} - local srvs = io.popen('ls -1 results/*.lua') - for l in srvs:lines() do + local srvs = APT.readCmd('ls -1 results/*.lua') + for ii,l in ipairs(srvs) do local hst = l:sub(9, -5) if nil ~= l:find('_R%.lua') then hst = hst:sub(1, -3) end if (hst:find('_') == nil) and (nil == APT.mirrors[hst]) then @@ -1197,8 +1194,8 @@ else end end end - local files = io.popen('ls -1 results/LOG_' .. hst .. '_*.html') - for ll in files:lines() do + local files = APT.readCmd('ls -1 results/LOG_' .. hst .. '_*.html') + for iii,ll in ipairs(files) do local dn = false for i, a in pairs(ips) do if type(a) == 'table' then -- cgit v1.1