diff options
author | Zac Medico <zmedico@gentoo.org> | 2013-01-15 12:09:21 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2013-01-15 12:09:21 -0800 |
commit | dbe26095102cbdc6d5bef3509f05bc7b42c418cc (patch) | |
tree | fbdc5d18ff9fa33dc7b69fdb6c173312cb4507a8 /pym/portage/process.py | |
parent | 7c624515d0bb106c8a468addff5df153cebf31fc (diff) | |
download | portage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.tar.gz portage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.tar.bz2 portage-dbe26095102cbdc6d5bef3509f05bc7b42c418cc.zip |
SpawnProcess: improve dummy pipe allocation logic
By using allocated file descriptors for keys in fd_pipes, we naturally
avoid interference with callers such as FileDigester and MergeProcess.
See the _setup_pipes docstring for more benefits of this allocation
approach.
Diffstat (limited to 'pym/portage/process.py')
-rw-r--r-- | pym/portage/process.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pym/portage/process.py b/pym/portage/process.py index 4cf1cec60..23a909466 100644 --- a/pym/portage/process.py +++ b/pym/portage/process.py @@ -429,6 +429,21 @@ def _setup_pipes(fd_pipes, close_fds=True): and also with CPython under some circumstances (as triggered by xmpppy in bug #374335). In order to close a safe subset of file descriptors, see portage.locks._close_fds(). + + NOTE: When not followed by exec, even when close_fds is False, + it's still possible for dup2() calls to cause interference in a + way that's similar to the way that close_fds interferes (since + dup2() has to close the target fd if it happens to be open). + It's possible to avoid such interference by using allocated + file descriptors as the keys in fd_pipes. For example: + + pr, pw = os.pipe() + fd_pipes[pw] = pw + + By using the allocated pw file descriptor as the key in fd_pipes, + it's not necessary for dup2() to close a file descriptor (it + actually does nothing in this case), which avoids possible + interference. """ my_fds = {} # To protect from cases where direct assignment could |