Comment 6 for bug 1364822

Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

Python's subprocess module converts the exit code to something easier for python programs calling subprocess to interpret: http://hg.python.org/cpython/file/7b0fdc1e917a/Lib/subprocess.py#l1343

We should probably have rootwrap exit with the same value as its child, since we want to treat it as a thin wrapper and transmit as much information as possible to the caller. When called from another python program via subprocess, that exit status will be re-converted to the negative signal value and when called from a shell script, the exit code could be interpreted using normal POSIX conventions of having the "exit code" in the low-order bits and the signal in the high-order bits.

Unfortunately, the actual exit status value is lost in the process because the raw value is never stored anywhere. I see two ways to fix that.

1. We could manually reverse the conversion, as in the proposed patch. I think this is probably safe, but it seems a little clunky.

2. We could subclass Popen() to replace the _handle_exitstatus() method with a version that saves the raw exit code and then calls the parent class implementation. The method is private to Popen, so this implementation is brittle.

I'm leaning toward keeping the implementation in the proposed patch (approach 1).