summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2013-01-03 23:07:00 -0800
committerZac Medico <zmedico@gentoo.org>2013-01-03 23:07:00 -0800
commit06d31ef00da24352a6614f20bccfc892d2120ed9 (patch)
tree9829f5930f4e531104b7bc2524bdfa4bcbad3b63 /bin
parent439151bb5b0bd2ac4c9d2dd218fe377ce0b988e6 (diff)
downloadportage-06d31ef00da24352a6614f20bccfc892d2120ed9.tar.gz
portage-06d31ef00da24352a6614f20bccfc892d2120ed9.tar.bz2
portage-06d31ef00da24352a6614f20bccfc892d2120ed9.zip
ebuild-ipc: use PipeReader in _receive_reply
Diffstat (limited to 'bin')
-rwxr-xr-xbin/ebuild-ipc.py61
1 files changed, 6 insertions, 55 deletions
diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py
index e91c69cd6..ceab4d579 100755
--- a/bin/ebuild-ipc.py
+++ b/bin/ebuild-ipc.py
@@ -5,12 +5,10 @@
# This is a helper which ebuild processes can use
# to communicate with portage's main python process.
-import errno
import logging
import os
import pickle
import platform
-import select
import signal
import sys
import time
@@ -49,7 +47,6 @@ class EbuildIpc(object):
# Timeout for each individual communication attempt (we retry
# as long as the daemon process appears to be alive).
_COMMUNICATE_RETRY_TIMEOUT_SECONDS = 15
- _BUFSIZE = 4096
def __init__(self):
self.fifo_dir = os.environ['PORTAGE_BUILDDIR']
@@ -148,41 +145,13 @@ class EbuildIpc(object):
def _receive_reply(self, input_fd):
- # Timeouts are handled by the parent process, so just
- # block until input is available. For maximum portability,
- # use a single atomic read.
buf = None
- while True:
- try:
- events = select.select([input_fd], [], [])
- except select.error as e:
- portage.util.writemsg_level(
- "ebuild-ipc: %s: %s\n" % \
- (portage.localization._('during select for read'), e),
- level=logging.ERROR, noiselevel=-1)
- continue
- if events[0]:
- # For maximum portability, use os.read() here since
- # array.fromfile() and file.read() are both known to
- # erroneously return an empty string from this
- # non-blocking fifo stream on FreeBSD (bug #337465).
- try:
- buf = os.read(input_fd, self._BUFSIZE)
- except OSError as e:
- if e.errno != errno.EAGAIN:
- portage.util.writemsg_level(
- "ebuild-ipc: %s: %s\n" % \
- (portage.localization._('read error'), e),
- level=logging.ERROR, noiselevel=-1)
- break
- # Assume that another event will be generated
- # if there's any relevant data.
- continue
-
- # Only one (atomic) read should be necessary.
- if buf:
- break
+ pipe_reader = PipeReader(input_files={"input_fd":input_fd},
+ scheduler=global_event_loop())
+ pipe_reader.start()
+ pipe_reader.wait()
+ buf = pipe_reader.getvalue()
retval = 2
@@ -272,25 +241,7 @@ class EbuildIpc(object):
self._no_daemon_msg()
return 2
- pr, pw = os.pipe()
- pid = os.fork()
-
- if pid == 0:
- retval = 2
- try:
- os.close(pr)
- retval = self._receive_reply(input_fd)
- except SystemExit:
- raise
- except:
- traceback.print_exc()
- finally:
- os._exit(retval)
-
- os.close(pw)
- retval = self._wait(pid, pr, portage.localization._('during read'))
- os.close(input_fd)
- return retval
+ return self._receive_reply(input_fd)
def ebuild_ipc_main(args):
ebuild_ipc = EbuildIpc()