3 # https://sourceware.org/bugzilla/show_bug.cgi?id=26034
4 export "BUP_ARGV_0"="$0"
7 export "BUP_ARGV_${arg_i}"="$arg"
11 # Here to end of preamble replaced during install
12 bup_python="$(dirname "$0")/../../config/bin/python" || exit $?
13 exec "$bup_python" "$0"
17 from __future__ import absolute_import
18 import os, struct, sys
20 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
22 from bup import compat, options, helpers, path
23 from bup.compat import environ, py_maj
24 from bup.io import byte_stream
29 This command is run automatically by 'bup on'
31 o = options.Options(optspec)
32 opt, flags, extra = o.parse(compat.argv[1:])
34 o.fatal('no arguments expected')
36 # get the subcommand's argv.
37 # Normally we could just pass this on the command line, but since we'll often
38 # be getting called on the other end of an ssh pipe, which tends to mangle
39 # argv (by sending it via the shell), this way is much safer.
41 stdin = byte_stream(sys.stdin)
43 sz = struct.unpack('!I', buf)[0]
47 assert(len(buf) == sz)
48 argv = buf.split(b'\0')
50 argv = [argv[0], b'mux', b'--'] + argv
53 # stdin/stdout are supposedly connected to 'bup server' that the caller
54 # started for us (often on the other end of an ssh tunnel), so we don't want
55 # to misuse them. Move them out of the way, then replace stdout with
56 # a pointer to stderr in case our subcommand wants to do something with it.
58 # It might be nice to do the same with stdin, but my experiments showed that
59 # ssh seems to make its child's stderr a readable-but-never-reads-anything
60 # socket. They really should have used shutdown(SHUT_WR) on the other end
61 # of it, but probably didn't. Anyway, it's too messy, so let's just make sure
62 # anyone reading from stdin is disappointed.
64 # (You can't just leave stdin/stdout "not open" by closing the file
65 # descriptors. Then the next file that opens is automatically assigned 0 or 1,
66 # and people *trying* to read/write stdin/stdout get screwed.)
70 fd = os.open(os.devnull, os.O_RDONLY)
74 environ[b'BUP_SERVER_REVERSE'] = helpers.hostname()
75 os.execvp(argv[0], argv)