From cb40673c41cdb56ad0d4b5626e0cd4c031f173a7 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 29 May 2021 15:18:08 -0500 Subject: [PATCH] Send *all* output before the BUPMUX header to stderr This is just an incremental fix. We may need to follow up with additional improvements. Thanks to Johannes Berg for diagnosing the problem. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/helpers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index aa691eb..a6bfeeb 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -12,7 +12,7 @@ import hashlib, heapq, math, operator, time, grp, tempfile from bup import _helpers from bup import compat -from bup.compat import argv_bytes, byte_int +from bup.compat import argv_bytes, byte_int, pending_raise from bup.io import byte_stream, path_msg # This function should really be in helpers, not in bup.options. But we # want options.py to be standalone so people can include it in other projects. @@ -561,13 +561,19 @@ class DemuxConn(BaseConn): # Anything that comes through before the sync string was not # multiplexed and can be assumed to be debug/log before mux init. tail = b'' + stderr = byte_stream(sys.stderr) while tail != b'BUPMUX': + # Make sure to write all pre-BUPMUX output to stderr b = os.read(infd, (len(tail) < 6) and (6-len(tail)) or 1) if not b: - raise IOError('demux: unexpected EOF during initialization') + ex = IOError('demux: unexpected EOF during initialization') + with pending_raise(ex): + stderr.write(tail) + stderr.flush() tail += b - byte_stream(sys.stderr).write(tail[:-6]) # pre-mux log messages + stderr.write(tail[:-6]) tail = tail[-6:] + stderr.flush() self.infd = infd self.reader = None self.buf = None -- 2.39.2