]> arthur.barton.de Git - bup.git/commitdiff
Send *all* output before the BUPMUX header to stderr
authorRob Browning <rlb@defaultvalue.org>
Sat, 29 May 2021 20:18:08 +0000 (15:18 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 12 Jun 2021 17:58:59 +0000 (12:58 -0500)
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 <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index aa691eb69ccd198bfc8560f9f0199c7a6621b970..a6bfeebe2304276f381fa7bae44f097ed9c78506 100644 (file)
@@ -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