Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/util/_eventloop/, pym/portage/util/_async/, ...
Date: Sun, 01 Sep 2013 19:38:25
Message-Id: 1378064278.30c652a9db1014fc720f7d6055520a07b731c984.zmedico@gentoo
1 commit: 30c652a9db1014fc720f7d6055520a07b731c984
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Sep 1 19:37:58 2013 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Sep 1 19:37:58 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=30c652a9
7
8 Use F_GETFD/F_SETFD for FD_CLOEXEC.
9
10 This mixup may have caused bug #456296 (see commit
11 e43524dc88774f768441dcb386a534166a53f7fa).
12
13 ---
14 pym/_emerge/AsynchronousLock.py | 9 +++++----
15 pym/_emerge/EbuildMetadataPhase.py | 10 +++++-----
16 pym/_emerge/FifoIpcDaemon.py | 8 ++++----
17 pym/_emerge/PipeReader.py | 17 ++++++++---------
18 pym/_emerge/SpawnProcess.py | 10 +++++++---
19 pym/portage/dbapi/_MergeProcess.py | 9 +++++----
20 pym/portage/locks.py | 4 ++--
21 pym/portage/util/_async/PipeLogger.py | 18 +++++++++---------
22 pym/portage/util/_eventloop/EventLoop.py | 17 +++++++++--------
23 9 files changed, 54 insertions(+), 48 deletions(-)
24
25 diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py
26 index c2dbf2d..cfe98b0 100644
27 --- a/pym/_emerge/AsynchronousLock.py
28 +++ b/pym/_emerge/AsynchronousLock.py
29 @@ -165,16 +165,17 @@ class _LockProcess(AbstractPollTask):
30 self._files['pipe_in'] = in_pr
31 self._files['pipe_out'] = out_pw
32
33 - fcntl_flags = os.O_NONBLOCK
34 + fcntl.fcntl(in_pr, fcntl.F_SETFL,
35 + fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
36 +
37 try:
38 fcntl.FD_CLOEXEC
39 except AttributeError:
40 pass
41 else:
42 - fcntl_flags |= fcntl.FD_CLOEXEC
43 + fcntl.fcntl(in_pr, fcntl.F_SETFD,
44 + fcntl.fcntl(in_pr, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
45
46 - fcntl.fcntl(in_pr, fcntl.F_SETFL,
47 - fcntl.fcntl(in_pr, fcntl.F_GETFL) | fcntl_flags)
48 self._reg_id = self.scheduler.io_add_watch(in_pr,
49 self.scheduler.IO_IN, self._output_handler)
50 self._registered = True
51
52 diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py
53 index 7418aba..7882b63 100644
54 --- a/pym/_emerge/EbuildMetadataPhase.py
55 +++ b/pym/_emerge/EbuildMetadataPhase.py
56 @@ -91,16 +91,16 @@ class EbuildMetadataPhase(SubProcess):
57
58 master_fd, slave_fd = os.pipe()
59
60 - fcntl_flags = os.O_NONBLOCK
61 + fcntl.fcntl(master_fd, fcntl.F_SETFL,
62 + fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
63 +
64 try:
65 fcntl.FD_CLOEXEC
66 except AttributeError:
67 pass
68 else:
69 - fcntl_flags |= fcntl.FD_CLOEXEC
70 -
71 - fcntl.fcntl(master_fd, fcntl.F_SETFL,
72 - fcntl.fcntl(master_fd, fcntl.F_GETFL) | fcntl_flags)
73 + fcntl.fcntl(master_fd, fcntl.F_SETFD,
74 + fcntl.fcntl(master_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
75
76 fd_pipes[slave_fd] = slave_fd
77 settings["PORTAGE_PIPE_FD"] = str(slave_fd)
78
79 diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py
80 index 113e49d..662aec1 100644
81 --- a/pym/_emerge/FifoIpcDaemon.py
82 +++ b/pym/_emerge/FifoIpcDaemon.py
83 @@ -33,9 +33,9 @@ class FifoIpcDaemon(AbstractPollTask):
84 except AttributeError:
85 pass
86 else:
87 - fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
88 + fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
89 fcntl.fcntl(self._files.pipe_in,
90 - fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
91 + fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
92
93 self._reg_id = self.scheduler.io_add_watch(
94 self._files.pipe_in,
95 @@ -59,9 +59,9 @@ class FifoIpcDaemon(AbstractPollTask):
96 except AttributeError:
97 pass
98 else:
99 - fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFL,
100 + fcntl.fcntl(self._files.pipe_in, fcntl.F_SETFD,
101 fcntl.fcntl(self._files.pipe_in,
102 - fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
103 + fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
104
105 self._reg_id = self.scheduler.io_add_watch(
106 self._files.pipe_in,
107
108 diff --git a/pym/_emerge/PipeReader.py b/pym/_emerge/PipeReader.py
109 index be93be3..c7eef1d 100644
110 --- a/pym/_emerge/PipeReader.py
111 +++ b/pym/_emerge/PipeReader.py
112 @@ -26,18 +26,17 @@ class PipeReader(AbstractPollTask):
113 else:
114 output_handler = self._output_handler
115
116 - fcntl_flags = os.O_NONBLOCK
117 - try:
118 - fcntl.FD_CLOEXEC
119 - except AttributeError:
120 - pass
121 - else:
122 - fcntl_flags |= fcntl.FD_CLOEXEC
123 -
124 for f in self.input_files.values():
125 fd = isinstance(f, int) and f or f.fileno()
126 fcntl.fcntl(fd, fcntl.F_SETFL,
127 - fcntl.fcntl(fd, fcntl.F_GETFL) | fcntl_flags)
128 + fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
129 + try:
130 + fcntl.FD_CLOEXEC
131 + except AttributeError:
132 + pass
133 + else:
134 + fcntl.fcntl(fd, fcntl.F_SETFD,
135 + fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
136 self._reg_ids.add(self.scheduler.io_add_watch(fd,
137 self._registered_events, output_handler))
138 self._registered = True
139
140 diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py
141 index 994f3dd..2c2e1a9 100644
142 --- a/pym/_emerge/SpawnProcess.py
143 +++ b/pym/_emerge/SpawnProcess.py
144 @@ -19,6 +19,8 @@ from portage.const import BASH_BINARY
145 from portage.util._async.PipeLogger import PipeLogger
146
147 # On Darwin, FD_CLOEXEC triggers errno 35 for stdout (bug #456296)
148 +# TODO: Test this again now that it's been fixed to use
149 +# F_GETFD/F_SETFD instead of F_GETFL/F_SETFL.
150 _disable_cloexec_stdout = platform.system() in ("Darwin",)
151
152 class SpawnProcess(SubProcess):
153 @@ -130,12 +132,14 @@ class SpawnProcess(SubProcess):
154 pass
155 else:
156 try:
157 - fcntl.fcntl(stdout_fd, fcntl.F_SETFL,
158 + fcntl.fcntl(stdout_fd, fcntl.F_SETFD,
159 fcntl.fcntl(stdout_fd,
160 - fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
161 + fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
162 except IOError:
163 # FreeBSD may return "Inappropriate ioctl for device"
164 - # error here (ENOTTY).
165 + # error here (ENOTTY). TODO: Test this again now that
166 + # it's been fixed to use F_GETFD/F_SETFD instead of
167 + # F_GETFL/F_SETFL.
168 pass
169
170 self._pipe_logger = PipeLogger(background=self.background,
171
172 diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_MergeProcess.py
173 index fba61e8..d7280f0 100644
174 --- a/pym/portage/dbapi/_MergeProcess.py
175 +++ b/pym/portage/dbapi/_MergeProcess.py
176 @@ -117,16 +117,17 @@ class MergeProcess(ForkProcess):
177
178 elog_reader_fd, elog_writer_fd = os.pipe()
179
180 - fcntl_flags = os.O_NONBLOCK
181 + fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
182 + fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
183 +
184 try:
185 fcntl.FD_CLOEXEC
186 except AttributeError:
187 pass
188 else:
189 - fcntl_flags |= fcntl.FD_CLOEXEC
190 + fcntl.fcntl(elog_reader_fd, fcntl.F_SETFD,
191 + fcntl.fcntl(elog_reader_fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
192
193 - fcntl.fcntl(elog_reader_fd, fcntl.F_SETFL,
194 - fcntl.fcntl(elog_reader_fd, fcntl.F_GETFL) | fcntl_flags)
195 blockers = None
196 if self.blockers is not None:
197 # Query blockers in the main process, since closing
198
199 diff --git a/pym/portage/locks.py b/pym/portage/locks.py
200 index 87aaf94..4f356c9 100644
201 --- a/pym/portage/locks.py
202 +++ b/pym/portage/locks.py
203 @@ -239,8 +239,8 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0,
204 except AttributeError:
205 pass
206 else:
207 - fcntl.fcntl(myfd, fcntl.F_SETFL,
208 - fcntl.fcntl(myfd, fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
209 + fcntl.fcntl(myfd, fcntl.F_SETFD,
210 + fcntl.fcntl(myfd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
211
212 _open_fds.add(myfd)
213
214
215 diff --git a/pym/portage/util/_async/PipeLogger.py b/pym/portage/util/_async/PipeLogger.py
216 index d0b1323..06d8200 100644
217 --- a/pym/portage/util/_async/PipeLogger.py
218 +++ b/pym/portage/util/_async/PipeLogger.py
219 @@ -38,21 +38,21 @@ class PipeLogger(AbstractPollTask):
220 uid=portage.portage_uid, gid=portage.portage_gid,
221 mode=0o660)
222
223 - fcntl_flags = os.O_NONBLOCK
224 - try:
225 - fcntl.FD_CLOEXEC
226 - except AttributeError:
227 - pass
228 - else:
229 - fcntl_flags |= fcntl.FD_CLOEXEC
230 -
231 if isinstance(self.input_fd, int):
232 fd = self.input_fd
233 else:
234 fd = self.input_fd.fileno()
235
236 fcntl.fcntl(fd, fcntl.F_SETFL,
237 - fcntl.fcntl(fd, fcntl.F_GETFL) | fcntl_flags)
238 + fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
239 +
240 + try:
241 + fcntl.FD_CLOEXEC
242 + except AttributeError:
243 + pass
244 + else:
245 + fcntl.fcntl(fd, fcntl.F_SETFD,
246 + fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
247
248 self._reg_id = self.scheduler.io_add_watch(fd,
249 self._registered_events, self._output_handler)
250
251 diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py
252 index 3742055..46a1f09 100644
253 --- a/pym/portage/util/_eventloop/EventLoop.py
254 +++ b/pym/portage/util/_eventloop/EventLoop.py
255 @@ -91,9 +91,9 @@ class EventLoop(object):
256 except AttributeError:
257 pass
258 else:
259 - fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFL,
260 + fcntl.fcntl(epoll_obj.fileno(), fcntl.F_SETFD,
261 fcntl.fcntl(epoll_obj.fileno(),
262 - fcntl.F_GETFL) | fcntl.FD_CLOEXEC)
263 + fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
264
265 self._poll_obj = _epoll_adapter(epoll_obj)
266 self.IO_ERR = select.EPOLLERR
267 @@ -315,17 +315,18 @@ class EventLoop(object):
268 if self._sigchld_read is None:
269 self._sigchld_read, self._sigchld_write = os.pipe()
270
271 - fcntl_flags = os.O_NONBLOCK
272 + fcntl.fcntl(self._sigchld_read, fcntl.F_SETFL,
273 + fcntl.fcntl(self._sigchld_read,
274 + fcntl.F_GETFL) | os.O_NONBLOCK)
275 +
276 try:
277 fcntl.FD_CLOEXEC
278 except AttributeError:
279 pass
280 else:
281 - fcntl_flags |= fcntl.FD_CLOEXEC
282 -
283 - fcntl.fcntl(self._sigchld_read, fcntl.F_SETFL,
284 - fcntl.fcntl(self._sigchld_read,
285 - fcntl.F_GETFL) | fcntl_flags)
286 + fcntl.fcntl(self._sigchld_read, fcntl.F_SETFD,
287 + fcntl.fcntl(self._sigchld_read,
288 + fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
289
290 # The IO watch is dynamically registered and unregistered as
291 # needed, since we don't want to consider it as a valid source