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-panopticommon.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'apt-panopticommon.lua') diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index 221c7e3..9de97b4 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua @@ -483,6 +483,17 @@ local E = APT.E local C = APT.C +APT.readCmd = function(cmd) + local result = {} + local output = io.popen(cmd) + if nil ~= output then + for l in output:lines() do + table.insert(result, l) + end + end + return result +end + APT.debians = {} APT.mirrors = {} @@ -559,10 +570,10 @@ APT.exe = function(c) I'm getting 7168 or 0. No idea what the fuck that is. local ok, rslt, status = os.execute(s) ]] - local f = io.popen(self.cmd .. ' ; echo "$?"', 'r') + local f = APT.readCmd(self.cmd .. ' ; echo "$?"', 'r') -- The last line will be the command's returned status, collect everything else in result. self.status = '' -- Otherwise the result starts with 0. - for l in f:lines() do + for i,l in ipairs(f) do self.result = self.result .. self.status .. "\n" self.status = l end @@ -579,7 +590,9 @@ APT.exe = function(c) end APT.checkExes = function (exe) - local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l") + local count = 0 + local ps = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l') + if nil ~= ps then count = ps:read("*l") end D(count .. " " .. exe .. " commands still running.") return tonumber(count) end -- cgit v1.1