]> arthur.barton.de Git - bup.git/blobdiff - cmd/mux-cmd.py
Use absolute_import from the __future__ everywhere
[bup.git] / cmd / mux-cmd.py
index 299dec9da5b854d9b056c817e0bab329daa31042..3b5524415e5f916bfd03b846494cfc8bccc3ed69 100755 (executable)
@@ -1,10 +1,25 @@
-#!/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 [command arguments...]
+bup mux command [arguments...]
 --
 """
 o = options.Options(optspec)
@@ -12,9 +27,7 @@ o = options.Options(optspec)
 if len(extra) < 1:
     o.fatal('command is required')
 
-cmdpath, cmdfn = os.path.split(__file__)
 subcmd = extra
-subcmd[0] = os.path.join(cmdpath, 'bup-' + subcmd[0])
 
 debug2('bup mux: starting %r\n' % (extra,))
 
@@ -23,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,
+                     preexec_fn=close_fds)
 os.close(outw)
 os.close(errw)
 sys.stdout.write('BUPMUX')