summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-09-21 19:30:58 -0700
committerZac Medico <zmedico@gentoo.org>2010-09-21 19:30:58 -0700
commit2be98bc1847c6616fbcc248721c75167fac48651 (patch)
tree0706dbdd0566498c755510c8614be82cb4130290
parent0906fee12ffe0ebd07e8952316f03927962af29b (diff)
downloadportage-2be98bc1847c6616fbcc248721c75167fac48651.tar.gz
portage-2be98bc1847c6616fbcc248721c75167fac48651.tar.bz2
portage-2be98bc1847c6616fbcc248721c75167fac48651.zip
Bug #337465 - Make ebuild-ipc use an array in order to force a
single atomic read of a whole pickle.
-rwxr-xr-xbin/ebuild-ipc.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/bin/ebuild-ipc.py b/bin/ebuild-ipc.py
index 61677c8f1..28352b56d 100755
--- a/bin/ebuild-ipc.py
+++ b/bin/ebuild-ipc.py
@@ -5,6 +5,7 @@
# This is a helper which ebuild processes can use
# to communicate with portage's main python process.
+import array
import logging
import os
import pickle
@@ -36,6 +37,7 @@ 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']
@@ -138,11 +140,22 @@ class EbuildIpc(object):
# File streams are in unbuffered mode since we do atomic
# read and write of whole pickles.
input_file = open(self.ipc_out_fifo, 'rb', 0)
- data = input_file.read()
+
+ # For maximum portability, us an array in order to force
+ # a single atomic read of a whole pickle (bug #337465).
+ buf = array.array('B')
+
+ try:
+ buf.fromfile(input_file, self._BUFSIZE)
+ except (EOFError, IOError) as e:
+ if not buf:
+ portage.util.writemsg_level(
+ "ebuild-ipc: %s\n" % (e,),
+ level=logging.ERROR, noiselevel=-1)
retval = 2
- if not data:
+ if not buf:
portage.util.writemsg_level(
"ebuild-ipc: %s\n" % \
@@ -152,7 +165,7 @@ class EbuildIpc(object):
else:
try:
- reply = pickle.loads(data)
+ reply = pickle.loads(buf.tostring())
except SystemExit:
raise
except Exception as e: