]> arthur.barton.de Git - bup.git/commitdiff
on--server-cmd: copy to bup.cmd.on__server
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 [new file with mode: 0755]
lib/cmd/on--server-cmd.py [deleted file]

diff --git a/lib/bup/cmd/on__server.py b/lib/bup/cmd/on__server.py
new file mode 100755 (executable)
index 0000000..a9d608c
--- /dev/null
@@ -0,0 +1,79 @@
+#!/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
+
+# 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.compat import environ, py_maj
+from bup.io import byte_stream
+
+optspec = """
+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)
diff --git a/lib/cmd/on--server-cmd.py b/lib/cmd/on--server-cmd.py
deleted file mode 100755 (executable)
index 3940715..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/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
-
-# 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.compat import environ, py_maj
-from bup.io import byte_stream
-
-optspec = """
-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)