1 |
commit: 7becb0d1e85d9154f8d18ac85e9ee5dd3f99a4e9 |
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:23:50 2013 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7becb0d1 |
7 |
|
8 |
_setup_pipes: os.set_inheritable() for Python 3.4 |
9 |
|
10 |
--- |
11 |
pym/portage/dbapi/_MergeProcess.py | 3 ++- |
12 |
pym/portage/process.py | 12 +++++++++++- |
13 |
pym/portage/util/_async/ForkProcess.py | 3 ++- |
14 |
3 files changed, 15 insertions(+), 3 deletions(-) |
15 |
|
16 |
diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py |
17 |
index d7280f0..4fec0a9 100644 |
18 |
--- a/pym/portage/dbapi/_MergeProcess.py |
19 |
+++ b/pym/portage/dbapi/_MergeProcess.py |
20 |
@@ -189,7 +189,8 @@ class MergeProcess(ForkProcess): |
21 |
portage.locks._close_fds() |
22 |
# We don't exec, so use close_fds=False |
23 |
# (see _setup_pipes docstring). |
24 |
- portage.process._setup_pipes(fd_pipes, close_fds=False) |
25 |
+ portage.process._setup_pipes(fd_pipes, close_fds=False, |
26 |
+ inheritable=False) |
27 |
|
28 |
portage.output.havecolor = self.settings.get('NOCOLOR') \ |
29 |
not in ('yes', 'true') |
30 |
|
31 |
diff --git a/pym/portage/process.py b/pym/portage/process.py |
32 |
index 20ef97d..869f2ce 100644 |
33 |
--- a/pym/portage/process.py |
34 |
+++ b/pym/portage/process.py |
35 |
@@ -502,7 +502,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, |
36 |
# And switch to the new process. |
37 |
os.execve(binary, myargs, env) |
38 |
|
39 |
-def _setup_pipes(fd_pipes, close_fds=True): |
40 |
+def _setup_pipes(fd_pipes, close_fds=True, inheritable=True): |
41 |
"""Setup pipes for a forked process. |
42 |
|
43 |
Even when close_fds is False, file descriptors referenced as |
44 |
@@ -538,6 +538,13 @@ def _setup_pipes(fd_pipes, close_fds=True): |
45 |
actually does nothing in this case), which avoids possible |
46 |
interference. |
47 |
""" |
48 |
+ |
49 |
+ # Support PEP 446 for Python >=3.4 |
50 |
+ try: |
51 |
+ set_inheritable = _os.set_inheritable |
52 |
+ except AttributeError: |
53 |
+ set_inheritable = None |
54 |
+ |
55 |
reverse_map = {} |
56 |
# To protect from cases where direct assignment could |
57 |
# clobber needed fds ({1:2, 2:1}) we create a reverse map |
58 |
@@ -570,6 +577,9 @@ def _setup_pipes(fd_pipes, close_fds=True): |
59 |
if oldfd != newfd: |
60 |
os.dup2(oldfd, newfd) |
61 |
|
62 |
+ if set_inheritable is not None: |
63 |
+ set_inheritable(newfd, inheritable) |
64 |
+ |
65 |
if oldfd not in fd_pipes: |
66 |
# If oldfd is not a key in fd_pipes, then it's safe |
67 |
# to close now, since we've already made all of the |
68 |
|
69 |
diff --git a/pym/portage/util/_async/ForkProcess.py b/pym/portage/util/_async/ForkProcess.py |
70 |
index 25f72d3..292df78 100644 |
71 |
--- a/pym/portage/util/_async/ForkProcess.py |
72 |
+++ b/pym/portage/util/_async/ForkProcess.py |
73 |
@@ -40,7 +40,8 @@ class ForkProcess(SpawnProcess): |
74 |
portage.locks._close_fds() |
75 |
# We don't exec, so use close_fds=False |
76 |
# (see _setup_pipes docstring). |
77 |
- portage.process._setup_pipes(fd_pipes, close_fds=False) |
78 |
+ portage.process._setup_pipes(fd_pipes, close_fds=False, |
79 |
+ inheritable=False) |
80 |
|
81 |
rval = self._run() |
82 |
except SystemExit: |