]> arthur.barton.de Git - bup.git/commitdiff
on--server: convert to internal command
authorRob Browning <rlb@defaultvalue.org>
Fri, 12 Feb 2021 20:50:13 +0000 (14:50 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Mar 2021 18:29:39 +0000 (12:29 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/cmd/on__server.py
lib/cmd/bup

index a9d608cfcac2e48c8b35c4d3a3ee7850a6170147..c04b3b0c68207f0ffa16277c2ba2ef33fc73a269 100755 (executable)
@@ -1,28 +1,8 @@
-#!/bin/sh
-"""": # -*-python-*-
-# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
-export "BUP_ARGV_0"="$0"
-arg_i=1
-for arg in "$@"; do
-    export "BUP_ARGV_${arg_i}"="$arg"
-    shift
-    arg_i=$((arg_i + 1))
-done
-# Here to end of preamble replaced during install
-bup_python="$(dirname "$0")/../../../config/bin/python" || exit $?
-exec "$bup_python" "$0"
-"""
-# end of bup preamble
 
 from __future__ import absolute_import
+import os, struct, sys
 
-# Intentionally replace the dirname "$0" that python prepends
-import os, sys
-sys.path[0] = os.path.dirname(os.path.realpath(__file__)) + '/../..'
-
-import struct
-
-from bup import compat, options, helpers, path
+from bup import options, helpers, path
 from bup.compat import environ, py_maj
 from bup.io import byte_stream
 
@@ -31,49 +11,51 @@ bup on--server
 --
     This command is run automatically by 'bup on'
 """
-o = options.Options(optspec)
-opt, flags, extra = o.parse(compat.argv[1:])
-if extra:
-    o.fatal('no arguments expected')
-
-# get the subcommand's argv.
-# Normally we could just pass this on the command line, but since we'll often
-# be getting called on the other end of an ssh pipe, which tends to mangle
-# argv (by sending it via the shell), this way is much safer.
-
-stdin = byte_stream(sys.stdin)
-buf = stdin.read(4)
-sz = struct.unpack('!I', buf)[0]
-assert(sz > 0)
-assert(sz < 1000000)
-buf = stdin.read(sz)
-assert(len(buf) == sz)
-argv = buf.split(b'\0')
-argv[0] = path.exe()
-argv = [argv[0], b'mux', b'--'] + argv
-
-
-# stdin/stdout are supposedly connected to 'bup server' that the caller
-# started for us (often on the other end of an ssh tunnel), so we don't want
-# to misuse them.  Move them out of the way, then replace stdout with
-# a pointer to stderr in case our subcommand wants to do something with it.
-#
-# It might be nice to do the same with stdin, but my experiments showed that
-# ssh seems to make its child's stderr a readable-but-never-reads-anything
-# socket.  They really should have used shutdown(SHUT_WR) on the other end
-# of it, but probably didn't.  Anyway, it's too messy, so let's just make sure
-# anyone reading from stdin is disappointed.
-#
-# (You can't just leave stdin/stdout "not open" by closing the file
-# descriptors.  Then the next file that opens is automatically assigned 0 or 1,
-# and people *trying* to read/write stdin/stdout get screwed.)
-os.dup2(0, 3)
-os.dup2(1, 4)
-os.dup2(2, 1)
-fd = os.open(os.devnull, os.O_RDONLY)
-os.dup2(fd, 0)
-os.close(fd)
 
-environ[b'BUP_SERVER_REVERSE'] = helpers.hostname()
-os.execvp(argv[0], argv)
-sys.exit(99)
+def main(argv):
+    o = options.Options(optspec)
+    opt, flags, extra = o.parse_bytes(argv[1:])
+    if extra:
+        o.fatal('no arguments expected')
+
+    # get the subcommand's argv.
+    # Normally we could just pass this on the command line, but since we'll often
+    # be getting called on the other end of an ssh pipe, which tends to mangle
+    # argv (by sending it via the shell), this way is much safer.
+
+    stdin = byte_stream(sys.stdin)
+    buf = stdin.read(4)
+    sz = struct.unpack('!I', buf)[0]
+    assert(sz > 0)
+    assert(sz < 1000000)
+    buf = stdin.read(sz)
+    assert(len(buf) == sz)
+    argv = buf.split(b'\0')
+    argv[0] = path.exe()
+    argv = [argv[0], b'mux', b'--'] + argv
+
+
+    # stdin/stdout are supposedly connected to 'bup server' that the caller
+    # started for us (often on the other end of an ssh tunnel), so we don't want
+    # to misuse them.  Move them out of the way, then replace stdout with
+    # a pointer to stderr in case our subcommand wants to do something with it.
+    #
+    # It might be nice to do the same with stdin, but my experiments showed that
+    # ssh seems to make its child's stderr a readable-but-never-reads-anything
+    # socket.  They really should have used shutdown(SHUT_WR) on the other end
+    # of it, but probably didn't.  Anyway, it's too messy, so let's just make sure
+    # anyone reading from stdin is disappointed.
+    #
+    # (You can't just leave stdin/stdout "not open" by closing the file
+    # descriptors.  Then the next file that opens is automatically assigned 0 or 1,
+    # and people *trying* to read/write stdin/stdout get screwed.)
+    os.dup2(0, 3)
+    os.dup2(1, 4)
+    os.dup2(2, 1)
+    fd = os.open(os.devnull, os.O_RDONLY)
+    os.dup2(fd, 0)
+    os.close(fd)
+
+    environ[b'BUP_SERVER_REVERSE'] = helpers.hostname()
+    os.execvp(argv[0], argv)
+    sys.exit(99)
index ea021e0a16ecde940e611786dc5911863baac5b9..27b918e94e9178a1d36f6b09b1923157796213c3 100755 (executable)
@@ -206,6 +206,7 @@ try:
                            b'midx',
                            b'mux',
                            b'on',
+                           b'on--server',
                            b'prune-older',
                            b'random',
                            b'rm',