diff options
| author | onefang | 2023-02-23 02:26:36 +1000 |
|---|---|---|
| committer | onefang | 2023-02-23 02:26:36 +1000 |
| commit | fab1f109d0564b44c950055d3233d6e7a1f3be81 (patch) | |
| tree | a002b3509041e8d5c140bc208b6496bc5fa4e7f4 /apt-panopticommon.lua | |
| parent | Update base files reference package. (diff) | |
| download | apt-panopticon-fab1f109d0564b44c950055d3233d6e7a1f3be81.zip apt-panopticon-fab1f109d0564b44c950055d3233d6e7a1f3be81.tar.gz apt-panopticon-fab1f109d0564b44c950055d3233d6e7a1f3be81.tar.bz2 apt-panopticon-fab1f109d0564b44c950055d3233d6e7a1f3be81.tar.xz | |
Add yet another timeout watchdog.
Diffstat (limited to 'apt-panopticommon.lua')
| -rw-r--r-- | apt-panopticommon.lua | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua index da1fc3d..a2def5a 100644 --- a/apt-panopticommon.lua +++ b/apt-panopticommon.lua | |||
| @@ -134,7 +134,7 @@ APT.parseArgs = function(args) | |||
| 134 | local arg = {} | 134 | local arg = {} |
| 135 | local sendArgs = "" | 135 | local sendArgs = "" |
| 136 | -- A special test to disable IPv6 tests if IPv6 isn't available. | 136 | -- A special test to disable IPv6 tests if IPv6 isn't available. |
| 137 | if 1 == APT.exe('ip -6 addr | grep inet6 | grep " global"'):Do().status then | 137 | if 1 == APT.exe('ip -6 addr | grep inet6 | grep " global"'):timeout():Do().status then |
| 138 | table.insert(args, '--tests=-IPv6') | 138 | table.insert(args, '--tests=-IPv6') |
| 139 | end | 139 | end |
| 140 | if 0 ~= #(args) then | 140 | if 0 ~= #(args) then |
| @@ -529,7 +529,7 @@ APT.tested = function(prot, test, host) | |||
| 529 | end | 529 | end |
| 530 | 530 | ||
| 531 | APT.exe = function(c) | 531 | APT.exe = function(c) |
| 532 | local exe = {status = 0, result = '', log = true, cmd = c .. ' '} | 532 | local exe = {status = 0, result = '', log = true, cmd = c .. ' ', command = c} |
| 533 | 533 | ||
| 534 | function exe:log() | 534 | function exe:log() |
| 535 | self.log = true | 535 | self.log = true |
| @@ -543,6 +543,16 @@ APT.exe = function(c) | |||
| 543 | end | 543 | end |
| 544 | return self | 544 | return self |
| 545 | end | 545 | end |
| 546 | function exe:timeout(c) | ||
| 547 | -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well. | ||
| 548 | -- --kill-after means "send KILL after TERM fails. | ||
| 549 | if nil == c then | ||
| 550 | self.cmd = 'timeout --kill-after=10.0 --foreground -v 42.0s ' .. self.cmd | ||
| 551 | else | ||
| 552 | self.cmd = 'timeout --kill-after=10.0 --foreground -v ' .. c .. ' ' .. self.cmd | ||
| 553 | end | ||
| 554 | return self | ||
| 555 | end | ||
| 546 | function exe:also(c) | 556 | function exe:also(c) |
| 547 | if nil == c then c = '' else c = ' ' .. c end | 557 | if nil == c then c = '' else c = ' ' .. c end |
| 548 | self.cmd = self.cmd .. ';' .. c .. ' ' | 558 | self.cmd = self.cmd .. ';' .. c .. ' ' |
| @@ -579,17 +589,28 @@ APT.exe = function(c) | |||
| 579 | I'm getting 7168 or 0. No idea what the fuck that is. | 589 | I'm getting 7168 or 0. No idea what the fuck that is. |
| 580 | local ok, rslt, status = os.execute(s) | 590 | local ok, rslt, status = os.execute(s) |
| 581 | ]] | 591 | ]] |
| 582 | local f = APT.readCmd(self.cmd .. ' ; echo "$?"', 'r') | 592 | local f = APT.readCmd(self.cmd, 'r') |
| 583 | -- The last line will be the command's returned status, collect everything else in result. | 593 | -- The last line will be the command's returned status, collect everything else in result. |
| 584 | self.status = '' -- Otherwise the result starts with 0. | 594 | self.status = '' -- Otherwise the result starts with 0. |
| 595 | self.result = '\n' | ||
| 596 | for i,l in ipairs(f) do | ||
| 597 | self.result = self.result .. l .. "\n" | ||
| 598 | end | ||
| 599 | f = APT.readCmd('echo "$?"', 'r') | ||
| 585 | for i,l in ipairs(f) do | 600 | for i,l in ipairs(f) do |
| 586 | self.result = self.result .. self.status .. "\n" | 601 | self.status = tonumber(l) |
| 587 | self.status = l | 602 | if (137 == self.status) or (124 == self.status) then |
| 603 | print("timeout killed " .. self.status .. ' ' .. self.command) | ||
| 604 | E("timeout killed " .. self.status .. ' ' .. self.command) | ||
| 605 | elseif (0 ~= self.status) then | ||
| 606 | print("status |" .. self.status .. '| ' .. self.command) | ||
| 607 | E("status |" .. self.status .. '| ' .. self.command) | ||
| 608 | end | ||
| 588 | end | 609 | end |
| 589 | self.status = tonumber(self.status) | ||
| 590 | return self | 610 | return self |
| 591 | end | 611 | end |
| 592 | function exe:fork() | 612 | function exe:fork(host) |
| 613 | if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end | ||
| 593 | self.cmd = '{ ' .. self.cmd .. '; } &' | 614 | self.cmd = '{ ' .. self.cmd .. '; } &' |
| 594 | if true == self.log then D(" forking - <code>" .. self.cmd .. "</code>") end | 615 | if true == self.log then D(" forking - <code>" .. self.cmd .. "</code>") end |
| 595 | os.execute(self.cmd) | 616 | os.execute(self.cmd) |
