OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2010-2011 Gentoo Foundation | 2 # Copyright 2010-2011 Gentoo Foundation |
3 # Distributed under the terms of the GNU General Public License v2 | 3 # Distributed under the terms of the GNU General Public License v2 |
4 # | 4 # |
5 # This is a helper which ebuild processes can use | 5 # This is a helper which ebuild processes can use |
6 # to communicate with portage's main python process. | 6 # to communicate with portage's main python process. |
7 | 7 |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import pickle | 10 import pickle |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 if not os.WIFEXITED(wait_retval[1]): | 127 if not os.WIFEXITED(wait_retval[1]): |
128 portage.util.writemsg_level( | 128 portage.util.writemsg_level( |
129 "ebuild-ipc: %s: %s\n" % (msg, | 129 "ebuild-ipc: %s: %s\n" % (msg, |
130 portage.localization._('subprocess failure: %s')
% \ | 130 portage.localization._('subprocess failure: %s')
% \ |
131 wait_retval[1]), | 131 wait_retval[1]), |
132 level=logging.ERROR, noiselevel=-1) | 132 level=logging.ERROR, noiselevel=-1) |
133 return 2 | 133 return 2 |
134 | 134 |
135 return os.WEXITSTATUS(wait_retval[1]) | 135 return os.WEXITSTATUS(wait_retval[1]) |
136 | 136 |
137 » def _receive_reply(self): | 137 » def _receive_reply(self, input_file): |
138 | |
139 » » # File streams are in unbuffered mode since we do atomic | |
140 » » # read and write of whole pickles. | |
141 » » input_file = open(self.ipc_out_fifo, 'rb', 0) | |
142 | 138 |
143 # For maximum portability, use a single atomic read. | 139 # For maximum portability, use a single atomic read. |
144 buf = None | 140 buf = None |
145 try: | 141 try: |
146 buf = input_file.read(self._BUFSIZE) | 142 buf = input_file.read(self._BUFSIZE) |
147 except IOError as e: | 143 except IOError as e: |
148 if not buf: | 144 if not buf: |
149 portage.util.writemsg_level( | 145 portage.util.writemsg_level( |
150 "ebuild-ipc: %s\n" % (e,), | 146 "ebuild-ipc: %s\n" % (e,), |
151 level=logging.ERROR, noiselevel=-1) | 147 level=logging.ERROR, noiselevel=-1) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 portage.util.writemsg(err, noiselevel=-1
) | 181 portage.util.writemsg(err, noiselevel=-1
) |
186 | 182 |
187 return retval | 183 return retval |
188 | 184 |
189 def _communicate(self, args): | 185 def _communicate(self, args): |
190 | 186 |
191 if not self._daemon_is_alive(): | 187 if not self._daemon_is_alive(): |
192 self._no_daemon_msg() | 188 self._no_daemon_msg() |
193 return 2 | 189 return 2 |
194 | 190 |
| 191 # File streams are in unbuffered mode since we do atomic |
| 192 # read and write of whole pickles. |
| 193 input_file = open(self.ipc_out_fifo, 'rb', 0) |
| 194 |
195 # Use forks so that the child process can handle blocking IO | 195 # Use forks so that the child process can handle blocking IO |
196 # un-interrupted, while the parent handles all timeout | 196 # un-interrupted, while the parent handles all timeout |
197 # considerations. This helps to avoid possible race conditions | 197 # considerations. This helps to avoid possible race conditions |
198 # from interference between timeouts and blocking IO operations. | 198 # from interference between timeouts and blocking IO operations. |
199 pr, pw = os.pipe() | 199 pr, pw = os.pipe() |
200 pid = os.fork() | 200 pid = os.fork() |
201 | 201 |
202 if pid == 0: | 202 if pid == 0: |
203 os.close(pr) | 203 os.close(pr) |
204 | 204 |
(...skipping 19 matching lines...) Expand all Loading... |
224 | 224 |
225 if not self._daemon_is_alive(): | 225 if not self._daemon_is_alive(): |
226 self._no_daemon_msg() | 226 self._no_daemon_msg() |
227 return 2 | 227 return 2 |
228 | 228 |
229 pr, pw = os.pipe() | 229 pr, pw = os.pipe() |
230 pid = os.fork() | 230 pid = os.fork() |
231 | 231 |
232 if pid == 0: | 232 if pid == 0: |
233 os.close(pr) | 233 os.close(pr) |
234 » » » retval = self._receive_reply() | 234 » » » retval = self._receive_reply(input_file) |
235 os._exit(retval) | 235 os._exit(retval) |
236 | 236 |
237 os.close(pw) | 237 os.close(pw) |
238 retval = self._wait(pid, pr, portage.localization._('during read
')) | 238 retval = self._wait(pid, pr, portage.localization._('during read
')) |
239 os.close(pr) | 239 os.close(pr) |
240 return retval | 240 return retval |
241 | 241 |
242 def ebuild_ipc_main(args): | 242 def ebuild_ipc_main(args): |
243 ebuild_ipc = EbuildIpc() | 243 ebuild_ipc = EbuildIpc() |
244 return ebuild_ipc.communicate(args) | 244 return ebuild_ipc.communicate(args) |
245 | 245 |
246 if __name__ == '__main__': | 246 if __name__ == '__main__': |
247 sys.exit(ebuild_ipc_main(sys.argv[1:])) | 247 sys.exit(ebuild_ipc_main(sys.argv[1:])) |
OLD | NEW |