]> arthur.barton.de Git - bup.git/blobdiff - cmd/mux-cmd.py
helpers: add close_fds to exo
[bup.git] / cmd / mux-cmd.py
index 3b5524415e5f916bfd03b846494cfc8bccc3ed69..f7be4c2f96da49f5b4accf636a84809cd94b67de 100755 (executable)
@@ -10,11 +10,11 @@ import os, sys, subprocess, struct
 
 from bup import options
 from bup.helpers import debug1, debug2, mux
-
+from bup.io import byte_stream
 
 # Give the subcommand exclusive access to stdin.
 orig_stdin = os.dup(0)
-devnull = os.open('/dev/null', os.O_RDONLY)
+devnull = os.open(os.devnull, os.O_RDONLY)
 os.dup2(devnull, 0)
 os.close(devnull)
 
@@ -38,12 +38,14 @@ def close_fds():
     os.close(errr)
 
 p = subprocess.Popen(subcmd, stdin=orig_stdin, stdout=outw, stderr=errw,
-                     preexec_fn=close_fds)
+                     close_fds=False, preexec_fn=close_fds)
 os.close(outw)
 os.close(errw)
-sys.stdout.write('BUPMUX')
 sys.stdout.flush()
-mux(p, sys.stdout.fileno(), outr, errr)
+out = byte_stream(sys.stdout)
+out.write(b'BUPMUX')
+out.flush()
+mux(p, out.fileno(), outr, errr)
 os.close(outr)
 os.close(errr)
 prv = p.wait()