From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 48E8D1382AD for ; Fri, 4 Jan 2013 13:23:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 660FEE062B; Fri, 4 Jan 2013 13:23:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D65FFE062B for ; Fri, 4 Jan 2013 13:23:07 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B4FBA33BECC for ; Fri, 4 Jan 2013 13:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 3F798E5439 for ; Fri, 4 Jan 2013 13:23:05 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1357305768.e489dcef3fd91ecf4a0960bdd7ed1de0a992f72b.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/ebuild-ipc.py X-VCS-Directories: bin/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: e489dcef3fd91ecf4a0960bdd7ed1de0a992f72b X-VCS-Branch: master Date: Fri, 4 Jan 2013 13:23:05 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 827634f5-eaa8-407f-a8e8-44049824ea50 X-Archives-Hash: ebbc1dc37ce1d58fa0d98013418c2772 commit: e489dcef3fd91ecf4a0960bdd7ed1de0a992f72b Author: Zac Medico gentoo org> AuthorDate: Fri Jan 4 13:22:48 2013 +0000 Commit: Zac Medico gentoo org> CommitDate: Fri Jan 4 13:22:48 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e489dcef ebuild-ipc: add FifoWriter class --- bin/ebuild-ipc.py | 79 ++++++++++++++--------------------------------------- 1 files changed, 21 insertions(+), 58 deletions(-) diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py index 4046d8d..d351e94 100755 --- a/bin/ebuild-ipc.py +++ b/bin/ebuild-ipc.py @@ -12,7 +12,6 @@ import platform import signal import sys import time -import traceback def debug_signal(signum, frame): import pdb @@ -39,9 +38,20 @@ import portage portage._internal_caller = True portage._disable_legacy_globals() +from portage.util._async.ForkProcess import ForkProcess from portage.util._eventloop.global_event_loop import global_event_loop from _emerge.PipeReader import PipeReader +class FifoWriter(ForkProcess): + + __slots__ = ('buf', 'fifo',) + + def _run(self): + # Atomically write the whole buffer into the fifo. + with open(self.fifo, 'wb', 0) as f: + f.write(self.buf) + return os.EX_OK + class EbuildIpc(object): # Timeout for each individual communication attempt (we retry @@ -90,7 +100,7 @@ class EbuildIpc(object): 'ebuild-ipc: daemon process not detected\n'), level=logging.ERROR, noiselevel=-1) - def _wait(self, pid, pr, msg): + def _run_writer(self, fifo_writer, msg): """ Wait on pid and return an appropriate exit code. This may return unsuccessfully due to timeout if the daemon @@ -99,49 +109,24 @@ class EbuildIpc(object): start_time = time.time() - pipe_reader = PipeReader(input_files={"pipe_read":pr}, - scheduler=global_event_loop()) - pipe_reader.start() - - eof = pipe_reader.poll() is not None + fifo_writer.start() + eof = fifo_writer.poll() is not None while not eof: - pipe_reader._wait_loop(timeout=self._COMMUNICATE_RETRY_TIMEOUT_MS) + fifo_writer._wait_loop(timeout=self._COMMUNICATE_RETRY_TIMEOUT_MS) - eof = pipe_reader.poll() is not None + eof = fifo_writer.poll() is not None if eof: break elif self._daemon_is_alive(): self._timeout_retry_msg(start_time, msg) else: - pipe_reader.cancel() + fifo_writer.cancel() self._no_daemon_msg() - try: - os.kill(pid, signal.SIGKILL) - os.waitpid(pid, 0) - except OSError as e: - portage.util.writemsg_level( - "ebuild-ipc: %s\n" % (e,), - level=logging.ERROR, noiselevel=-1) + fifo_writer.wait() return 2 - try: - wait_retval = os.waitpid(pid, 0) - except OSError as e: - portage.util.writemsg_level( - "ebuild-ipc: %s: %s\n" % (msg, e), - level=logging.ERROR, noiselevel=-1) - return 2 - - if not os.WIFEXITED(wait_retval[1]): - portage.util.writemsg_level( - "ebuild-ipc: %s: %s\n" % (msg, - portage.localization._('subprocess failure: %s') % \ - wait_retval[1]), - level=logging.ERROR, noiselevel=-1) - return 2 - - return os.WEXITSTATUS(wait_retval[1]) + return fifo_writer.wait() def _receive_reply(self, input_fd): @@ -218,31 +203,9 @@ class EbuildIpc(object): # un-interrupted, while the parent handles all timeout # considerations. This helps to avoid possible race conditions # from interference between timeouts and blocking IO operations. - pr, pw = os.pipe() - pid = os.fork() - - if pid == 0: - retval = 2 - try: - os.close(pr) - - # File streams are in unbuffered mode since we do atomic - # read and write of whole pickles. - output_file = open(self.ipc_in_fifo, 'wb', 0) - output_file.write(pickle.dumps(args)) - output_file.close() - retval = os.EX_OK - except SystemExit: - raise - except: - traceback.print_exc() - finally: - os._exit(retval) - - os.close(pw) - msg = portage.localization._('during write') - retval = self._wait(pid, pr, msg) + retval = self._run_writer(FifoWriter(buf=pickle.dumps(args), + fifo=self.ipc_in_fifo, scheduler=global_event_loop()), msg) if retval != os.EX_OK: portage.util.writemsg_level(