Popen.returncode does not encode statuses in the same way as os.wait, so using the os.WIF* methods on the returncodes is erroneous. Fix the conditional in execReadlines to look for signals in the encoding used by Popen and correct exec_readlines_test_exits. --- pyanaconda/iutil.py | 2 +- tests/pyanaconda_tests/iutil_test.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py index 621ccff..bf4928d 100644 --- a/pyanaconda/iutil.py +++ b/pyanaconda/iutil.py @@ -366,7 +366,7 @@ def execReadlines(command, argv, stdin=None, root='/', env_prune=None): # Output finished, check for the process dying unexpectedly # and stop the iteration if self._proc.poll() is not None: - if os.WIFSIGNALED(self._proc.returncode): + if self._proc.returncode < 0: raise OSError("process '%s' was killed" % self._argv) raise StopIteration
diff --git a/tests/pyanaconda_tests/iutil_test.py b/tests/pyanaconda_tests/iutil_test.py index a08e167..da33d8e 100644 --- a/tests/pyanaconda_tests/iutil_test.py +++ b/tests/pyanaconda_tests/iutil_test.py @@ -166,7 +166,8 @@ exit 0 def exec_readlines_test_exits(self): """Test execReadlines in different child exit situations."""
- # These tests raise OSError once output has been consumed + # Tests that exit on signal will raise OSError once output + # has been consumed, otherwise the test will exit normally.
# Test a normal, non-0 exit with tempfile.NamedTemporaryFile() as testscript: @@ -183,7 +184,7 @@ exit 1 self.assertEqual(rl_iterator.next(), "one") self.assertEqual(rl_iterator.next(), "two") self.assertEqual(rl_iterator.next(), "three") - self.assertRaises(OSError, rl_iterator.next) + self.assertRaises(StopIteration, rl_iterator.next)
# Test exit on signal with tempfile.NamedTemporaryFile() as testscript: @@ -217,7 +218,7 @@ exit 1 self.assertEqual(rl_iterator.next(), "one") self.assertEqual(rl_iterator.next(), "two") self.assertEqual(rl_iterator.next(), "three") - self.assertRaises(OSError, rl_iterator.next) + self.assertRaises(StopIteration, rl_iterator.next)
with tempfile.NamedTemporaryFile() as testscript: testscript.write("""#!/bin/sh