1 |
commit: 850b1c33a04b734d143df3474568cf07e77b4411 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Sep 1 20:23:50 2013 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Sep 1 20:54:43 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=850b1c33 |
7 |
|
8 |
_setup_pipes: os.set_inheritable() for Python 3.4 |
9 |
|
10 |
--- |
11 |
pym/portage/process.py | 17 +++++++++++++++-- |
12 |
1 file changed, 15 insertions(+), 2 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/process.py b/pym/portage/process.py |
15 |
index 20ef97d..3ec6d70 100644 |
16 |
--- a/pym/portage/process.py |
17 |
+++ b/pym/portage/process.py |
18 |
@@ -437,7 +437,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, |
19 |
# the parent process (see bug #289486). |
20 |
signal.signal(signal.SIGQUIT, signal.SIG_DFL) |
21 |
|
22 |
- _setup_pipes(fd_pipes, close_fds=close_fds) |
23 |
+ _setup_pipes(fd_pipes, close_fds=close_fds, inheritable=True) |
24 |
|
25 |
# Add to cgroup |
26 |
# it's better to do it from the child since we can guarantee |
27 |
@@ -502,7 +502,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, |
28 |
# And switch to the new process. |
29 |
os.execve(binary, myargs, env) |
30 |
|
31 |
-def _setup_pipes(fd_pipes, close_fds=True): |
32 |
+def _setup_pipes(fd_pipes, close_fds=True, inheritable=None): |
33 |
"""Setup pipes for a forked process. |
34 |
|
35 |
Even when close_fds is False, file descriptors referenced as |
36 |
@@ -538,6 +538,13 @@ def _setup_pipes(fd_pipes, close_fds=True): |
37 |
actually does nothing in this case), which avoids possible |
38 |
interference. |
39 |
""" |
40 |
+ |
41 |
+ # Support PEP 446 for Python >=3.4 |
42 |
+ try: |
43 |
+ set_inheritable = _os.set_inheritable |
44 |
+ except AttributeError: |
45 |
+ set_inheritable = None |
46 |
+ |
47 |
reverse_map = {} |
48 |
# To protect from cases where direct assignment could |
49 |
# clobber needed fds ({1:2, 2:1}) we create a reverse map |
50 |
@@ -570,6 +577,12 @@ def _setup_pipes(fd_pipes, close_fds=True): |
51 |
if oldfd != newfd: |
52 |
os.dup2(oldfd, newfd) |
53 |
|
54 |
+ if set_inheritable is not None: |
55 |
+ if inheritable is not None: |
56 |
+ set_inheritable(newfd, inheritable) |
57 |
+ elif newfd in (0, 1, 2): |
58 |
+ set_inheritable(newfd, True) |
59 |
+ |
60 |
if oldfd not in fd_pipes: |
61 |
# If oldfd is not a key in fd_pipes, then it's safe |
62 |
# to close now, since we've already made all of the |