From dbe26095102cbdc6d5bef3509f05bc7b42c418cc Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 15 Jan 2013 12:09:21 -0800 Subject: 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. --- pym/portage/process.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'pym/portage/process.py') 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 -- cgit v1.2.3-1-g7c22