]> arthur.barton.de Git - bup.git/blobdiff - cmd/mux-cmd.py
vint: check for bytes after read
[bup.git] / cmd / mux-cmd.py
index 332d7bdce463a0330549b290bee5b901f3381cac..1a500b658f6bc86c9dc052c4bf50688bcf4f6a97 100755 (executable)
@@ -1,7 +1,22 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+from __future__ import absolute_import
 import os, sys, subprocess, struct
+
 from bup import options
-from bup.helpers import *
+from bup.helpers import debug1, debug2, mux
+
+
+# Give the subcommand exclusive access to stdin.
+orig_stdin = os.dup(0)
+devnull = os.open('/dev/null', os.O_RDONLY)
+os.dup2(devnull, 0)
+os.close(devnull)
 
 optspec = """
 bup mux command [arguments...]
@@ -21,7 +36,9 @@ errr, errw = os.pipe()
 def close_fds():
     os.close(outr)
     os.close(errr)
-p = subprocess.Popen(subcmd, stdout=outw, stderr=errw, preexec_fn=close_fds)
+
+p = subprocess.Popen(subcmd, stdin=orig_stdin, stdout=outw, stderr=errw,
+                     close_fds=False, preexec_fn=close_fds)
 os.close(outw)
 os.close(errw)
 sys.stdout.write('BUPMUX')