From 935d79eaaedef532230ab72a8256be713b27de1f Mon Sep 17 00:00:00 2001 From: sebres Date: Sun, 29 Nov 2015 01:04:55 +0100 Subject: [PATCH] 1) prevents a bug by logging stdout/stderr if retcode still None: ``` in executeCmd if retcode < 0: TypeError: unorderable types: NoneType() < int() ``` 2) prevents a rarely test case bug of testExecuteTimeoutWithNastyChildren, because no stdout (Resource temporarily unavailable), possible no flush by IO of the killing process; --- fail2ban/server/utils.py | 4 ++-- fail2ban/tests/actiontestcase.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fail2ban/server/utils.py b/fail2ban/server/utils.py index 262b303d..45d1c09d 100644 --- a/fail2ban/server/utils.py +++ b/fail2ban/server/utils.py @@ -159,7 +159,7 @@ class Utils(): # if was timeouted (killed/terminated) - to prevent waiting, set std handles to non-blocking mode. if popen.stdout: try: - if retcode < 0: + if retcode is None or retcode < 0: Utils.setFBlockMode(popen.stdout, False) stdout = popen.stdout.read() except IOError as e: @@ -169,7 +169,7 @@ class Utils(): popen.stdout.close() if popen.stderr: try: - if retcode < 0: + if retcode is None or retcode < 0: Utils.setFBlockMode(popen.stderr, False) stderr = popen.stderr.read() except IOError as e: diff --git a/fail2ban/tests/actiontestcase.py b/fail2ban/tests/actiontestcase.py index 8c9b5ef1..6d8fcc82 100644 --- a/fail2ban/tests/actiontestcase.py +++ b/fail2ban/tests/actiontestcase.py @@ -247,7 +247,7 @@ class CommandActionTest(LogCaptureTestCase): cpid = getnastypid() # Verify that the process itself got killed self.assertTrue(Utils.wait_for(lambda: not pid_exists(cpid), 3)) # process should have been killed - self.assertLogged('my pid ') + self.assertLogged('my pid ', 'Resource temporarily unavailable') self.assertLogged('timed out') self.assertLogged('killed with SIGTERM', 'killed with SIGKILL') @@ -261,7 +261,7 @@ class CommandActionTest(LogCaptureTestCase): cpid = getnastypid() # Verify that the process itself got killed self.assertTrue(Utils.wait_for(lambda: not pid_exists(cpid), 3)) - self.assertLogged('my pid ') + self.assertLogged('my pid ', 'Resource temporarily unavailable') self.assertLogged('timed out') self.assertLogged('killed with SIGTERM', 'killed with SIGKILL')