SubProcess: make returncode like Popen
authorZac Medico <zmedico@gentoo.org>
Thu, 9 Jun 2011 16:07:54 +0000 (09:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 9 Jun 2011 16:07:54 +0000 (09:07 -0700)
pym/_emerge/SubProcess.py

index 115af803d186661fa2af23ff354434450c6194e1..da2b301db10f3a525097e33ba99363bec7141733 100644 (file)
@@ -124,14 +124,18 @@ class SubProcess(AbstractPollTask):
                        self._files = None
 
        def _set_returncode(self, wait_retval):
+               """
+               Set the returncode in a manner compatible with
+               subprocess.Popen.returncode: A negative value -N indicates
+               that the child was terminated by signal N (Unix only).
+               """
 
-               retval = wait_retval[1]
+               pid, status = wait_retval
 
-               if retval != os.EX_OK:
-                       if retval & 0xff:
-                               retval = (retval & 0xff) << 8
-                       else:
-                               retval = retval >> 8
+               if os.WIFSIGNALED(status):
+                       retval = - os.WTERMSIG(status)
+               else:
+                       retval = os.WEXITSTATUS(status)
 
                self.returncode = retval