1 |
commit: 22be2988af6d8425d5c4cf66d92b8b8657bdbc5a |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Dec 22 21:34:17 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Dec 22 21:34:17 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=22be2988 |
7 |
|
8 |
_pty.py: remove _test_pty_eof() |
9 |
|
10 |
If array.fromfile() is not used, then _test_pty_eof() is useless. |
11 |
This function was for runtime detection of python issue 5380: |
12 |
|
13 |
http://bugs.python.org/issue5380 |
14 |
|
15 |
However, array.fromfile() use has since been abandoned due to |
16 |
bugs that exist in all known versions of Python (including Python |
17 |
2.7 and Python 3.2). See PipeReaderArrayTestCase, for example. |
18 |
|
19 |
--- |
20 |
pym/portage/tests/ebuild/test_pty_eof.py | 26 ----- |
21 |
pym/portage/util/_pty.py | 157 ++---------------------------- |
22 |
2 files changed, 8 insertions(+), 175 deletions(-) |
23 |
|
24 |
diff --git a/pym/portage/tests/ebuild/test_pty_eof.py b/pym/portage/tests/ebuild/test_pty_eof.py |
25 |
deleted file mode 100644 |
26 |
index fe218b6..0000000 |
27 |
--- a/pym/portage/tests/ebuild/test_pty_eof.py |
28 |
+++ /dev/null |
29 |
@@ -1,26 +0,0 @@ |
30 |
-# Copyright 2009-2011 Gentoo Foundation |
31 |
-# Distributed under the terms of the GNU General Public License v2 |
32 |
- |
33 |
-from portage.tests import TestCase |
34 |
-from portage.util._pty import _can_test_pty_eof, _test_pty_eof |
35 |
- |
36 |
-class PtyEofTestCase(TestCase): |
37 |
- |
38 |
- def testPtyEof(self): |
39 |
- |
40 |
- if not _can_test_pty_eof(): |
41 |
- skip_reason = "unsupported on this platform" |
42 |
- self.portage_skip = skip_reason |
43 |
- self.fail(skip_reason) |
44 |
- return |
45 |
- |
46 |
- # This tests if the following python issue is fixed yet: |
47 |
- # http://bugs.python.org/issue5380 |
48 |
- # Since it might not be fixed, mark as todo. |
49 |
- self.todo = True |
50 |
- # The result is only valid if openpty does not raise EnvironmentError. |
51 |
- if _can_test_pty_eof(): |
52 |
- try: |
53 |
- self.assertEqual(_test_pty_eof(), True) |
54 |
- except EnvironmentError: |
55 |
- pass |
56 |
|
57 |
diff --git a/pym/portage/util/_pty.py b/pym/portage/util/_pty.py |
58 |
index 97a38c0..efabb0a 100644 |
59 |
--- a/pym/portage/util/_pty.py |
60 |
+++ b/pym/portage/util/_pty.py |
61 |
@@ -1,154 +1,23 @@ |
62 |
# Copyright 2010-2011 Gentoo Foundation |
63 |
# Distributed under the terms of the GNU General Public License v2 |
64 |
|
65 |
-import errno |
66 |
-import fcntl |
67 |
import platform |
68 |
import pty |
69 |
-import select |
70 |
-import sys |
71 |
import termios |
72 |
|
73 |
-from portage import os, _unicode_decode, _unicode_encode |
74 |
+from portage import os |
75 |
from portage.output import get_term_size, set_term_size |
76 |
-from portage.process import spawn_bash |
77 |
from portage.util import writemsg |
78 |
|
79 |
-def _can_test_pty_eof(): |
80 |
- """ |
81 |
- The _test_pty_eof() function seems to hang on most |
82 |
- kernels other than Linux. |
83 |
- This was reported for the following kernels which used to work fine |
84 |
- without this EOF test: Darwin, AIX, FreeBSD. They seem to hang on |
85 |
- the slave_file.close() call. Note that Python's implementation of |
86 |
- openpty on Solaris already caused random hangs without this EOF test |
87 |
- and hence is globally disabled. |
88 |
- @rtype: bool |
89 |
- @returns: True if _test_pty_eof() won't hang, False otherwise. |
90 |
- """ |
91 |
- return platform.system() in ("Linux",) |
92 |
- |
93 |
-def _test_pty_eof(): |
94 |
- """ |
95 |
- Returns True if EOF appears to be handled correctly with pty |
96 |
- devices. Raises an EnvironmentError from openpty() if it fails. |
97 |
- |
98 |
- This used to be used to detect if the following issue was fixed |
99 |
- in the currently running version of python: |
100 |
- |
101 |
- http://bugs.python.org/issue5380 |
102 |
- |
103 |
- However, array.fromfile() use has since been abandoned due to |
104 |
- bugs that exist in all known versions of Python (including Python |
105 |
- 2.7 and Python 3.2). See PipeReaderArrayTestCase, for example. |
106 |
- This is somewhat unfortunate, since the combination of |
107 |
- array.fromfile() and array.tofile() is approximately 10% faster |
108 |
- than the combination of os.read() and os.write(). |
109 |
- """ |
110 |
- |
111 |
- use_fork = False |
112 |
- |
113 |
- test_string = 2 * "blah blah blah\n" |
114 |
- test_string = _unicode_decode(test_string, |
115 |
- encoding='utf_8', errors='strict') |
116 |
- |
117 |
- # may raise EnvironmentError |
118 |
- master_fd, slave_fd = pty.openpty() |
119 |
- |
120 |
- # Non-blocking mode is required for Darwin kernel. |
121 |
- fcntl.fcntl(master_fd, fcntl.F_SETFL, |
122 |
- fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK) |
123 |
- |
124 |
- # Disable post-processing of output since otherwise weird |
125 |
- # things like \n -> \r\n transformations may occur. |
126 |
- mode = termios.tcgetattr(slave_fd) |
127 |
- mode[1] &= ~termios.OPOST |
128 |
- termios.tcsetattr(slave_fd, termios.TCSANOW, mode) |
129 |
- |
130 |
- # Simulate a subprocess writing some data to the |
131 |
- # slave end of the pipe, and then exiting. |
132 |
- pid = None |
133 |
- if use_fork: |
134 |
- pids = spawn_bash(_unicode_encode("echo -n '%s'" % test_string, |
135 |
- encoding='utf_8', errors='strict'), env=os.environ, |
136 |
- fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, |
137 |
- returnpid=True) |
138 |
- if isinstance(pids, int): |
139 |
- os.close(master_fd) |
140 |
- os.close(slave_fd) |
141 |
- raise EnvironmentError('spawn failed') |
142 |
- pid = pids[0] |
143 |
- else: |
144 |
- os.write(slave_fd, _unicode_encode(test_string, |
145 |
- encoding='utf_8', errors='strict')) |
146 |
- os.close(slave_fd) |
147 |
- |
148 |
- # If using a fork, we must wait for the child here, |
149 |
- # in order to avoid a race condition that would |
150 |
- # lead to inconsistent results. |
151 |
- if pid is not None: |
152 |
- os.waitpid(pid, 0) |
153 |
+# Disable the use of openpty on Solaris as it seems Python's openpty |
154 |
+# implementation doesn't play nice on Solaris with Portage's |
155 |
+# behaviour causing hangs/deadlocks. |
156 |
+# Additional note for the future: on Interix, pipes do NOT work, so |
157 |
+# _disable_openpty on Interix must *never* be True |
158 |
+_disable_openpty = platform.system() in ("SunOS",) |
159 |
|
160 |
- data = [] |
161 |
- iwtd = [master_fd] |
162 |
- owtd = [] |
163 |
- ewtd = [] |
164 |
- |
165 |
- while True: |
166 |
- |
167 |
- events = select.select(iwtd, owtd, ewtd) |
168 |
- if not events[0]: |
169 |
- # EOF |
170 |
- break |
171 |
- |
172 |
- buf = None |
173 |
- try: |
174 |
- buf = os.read(master_fd, 1024) |
175 |
- except OSError as e: |
176 |
- # EIO happens with pty on Linux after the |
177 |
- # slave end of the pty has been closed. |
178 |
- if e.errno == errno.EIO: |
179 |
- # EOF: return empty string of bytes |
180 |
- buf = b'' |
181 |
- elif e.errno == errno.EAGAIN: |
182 |
- # EAGAIN: return None |
183 |
- buf = None |
184 |
- else: |
185 |
- raise |
186 |
- |
187 |
- if buf is None: |
188 |
- pass |
189 |
- elif not buf: |
190 |
- # EOF |
191 |
- break |
192 |
- else: |
193 |
- data.append(buf) |
194 |
- |
195 |
- os.close(master_fd) |
196 |
- |
197 |
- return test_string == _unicode_decode(b''.join(data), encoding='utf_8', errors='strict') |
198 |
- |
199 |
-# If _test_pty_eof() can't be used for runtime detection of |
200 |
-# http://bugs.python.org/issue5380, openpty can't safely be used |
201 |
-# unless we can guarantee that the current version of python has |
202 |
-# been fixed (affects all current versions of python3). When |
203 |
-# this issue is fixed in python3, we can add another sys.hexversion |
204 |
-# conditional to enable openpty support in the fixed versions. |
205 |
-if sys.hexversion >= 0x3000000 and not _can_test_pty_eof(): |
206 |
- _disable_openpty = True |
207 |
-else: |
208 |
- # Disable the use of openpty on Solaris as it seems Python's openpty |
209 |
- # implementation doesn't play nice on Solaris with Portage's |
210 |
- # behaviour causing hangs/deadlocks. |
211 |
- # Additional note for the future: on Interix, pipes do NOT work, so |
212 |
- # _disable_openpty on Interix must *never* be True |
213 |
- _disable_openpty = platform.system() in ("SunOS",) |
214 |
_tested_pty = False |
215 |
|
216 |
-if not _can_test_pty_eof(): |
217 |
- # Skip _test_pty_eof() on systems where it hangs. |
218 |
- _tested_pty = True |
219 |
- |
220 |
_fbsd_test_pty = platform.system() == 'FreeBSD' |
221 |
|
222 |
def _create_pty_or_pipe(copy_term_size=None): |
223 |
@@ -167,17 +36,7 @@ def _create_pty_or_pipe(copy_term_size=None): |
224 |
|
225 |
got_pty = False |
226 |
|
227 |
- global _disable_openpty, _fbsd_test_pty, _tested_pty |
228 |
- if not (_tested_pty or _disable_openpty): |
229 |
- try: |
230 |
- if not _test_pty_eof(): |
231 |
- _disable_openpty = True |
232 |
- except EnvironmentError as e: |
233 |
- _disable_openpty = True |
234 |
- writemsg("openpty failed: '%s'\n" % str(e), |
235 |
- noiselevel=-1) |
236 |
- del e |
237 |
- _tested_pty = True |
238 |
+ global _disable_openpty, _fbsd_test_pty |
239 |
|
240 |
if _fbsd_test_pty and not _disable_openpty: |
241 |
# Test for python openpty breakage after freebsd7 to freebsd8 |