From f01556b0e7b35bfc0caa01b6eeab42cb1313dd64 Mon Sep 17 00:00:00 2001 From: dvs1 Date: Sun, 20 Oct 2024 10:48:23 +1000 Subject: Tweak APT.exe status return code to be more reliable. --- aataaj.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/aataaj.lua b/aataaj.lua index d5b081e..b139faa 100755 --- a/aataaj.lua +++ b/aataaj.lua @@ -94,12 +94,13 @@ APT.readCmd = function(cmd) table.insert(result, l) end end + -- While this does return the same things as os.execute(), it's just as useless. + output:close() return result end - APT.exe = function(c) - local exe = {status = 0, result = '', lines = {}, log = true, cmd = c .. ' ', command = c} + local exe = {status = 0, lines = {}, log = true, cmd = c .. ' ', command = c} function exe:log() self.log = true @@ -159,15 +160,14 @@ 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 = APT.readCmd(self.cmd .. '; echo "$?"', 'r') + self.lines = APT.readCmd(self.cmd .. '; echo "$?"', 'r') -- The last line will be the command's returned status, collect everything else in result. - self.status = tonumber(f[#f]) - f[#f] = nil - self.result = '\n' - self.lines = f - for i,l in ipairs(f) do - self.result = self.result .. l .. "\n" - end + self.status = tonumber(self.lines[#self.lines]) + self.lines[#self.lines] = nil +-- self.result = '\n' +-- for i,l in ipairs(self.lines) do +-- self.result = self.result .. l .. "\n" +-- end if (137 == self.status) or (124 == self.status) then print("timeout killed " .. self.status .. ' ' .. self.command) print('ERROR ' .. "timeout killed " .. self.status .. ' ' .. self.command) @@ -196,7 +196,7 @@ end APT.killEmAll = function(all) for i,l in ipairs(all) do local c = 0 - while 0 ~= tonumber(APT.exe("pgrep -u $USER -xc " .. l):Do().result) do + while 0 ~= tonumber(APT.exe("pgrep -u $USER -xc " .. l):Do().lines[1]) do local s = 'TERM' if c > 0 then s = 'KILL'; APT.exe("sleep " .. c):Do() end print( "pkill -" .. s .. " -u $USER -x " .. l) -- cgit v1.1