]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Make -4 & -6 also able to affect an ssh remote shell.
authorWayne Davison <wayne@opencoder.net>
Sun, 14 Jun 2020 01:49:52 +0000 (18:49 -0700)
committerWayne Davison <wayne@opencoder.net>
Sun, 14 Jun 2020 02:15:02 +0000 (19:15 -0700)
NEWS.md
main.c
rsync.1.md

diff --git a/NEWS.md b/NEWS.md
index bfadccde757143cdefe09613491dd6b72178b51f..18a2854594051889e314134f4f60b6de6a42a19f 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -134,6 +134,9 @@ Protocol: 31 (unchanged)
 
  - Made -V the short option for --version.
 
+ - Forward -4 & -6 options to the ssh command, making them easier to type than
+   "--rsh='ssh -4'" (or -6).
+
 ### PACKAGING RELATED:
 
  - Add installed binary: /usr/bin/rsync-sll
diff --git a/main.c b/main.c
index a0b2fbc55edbaf248b656a0b5a649943d4feded0..b41a39435d261424b4c02c16904411f41d5ad864 100644 (file)
--- a/main.c
+++ b/main.c
@@ -81,6 +81,7 @@ extern BOOL want_progress_now;
 extern BOOL shutting_down;
 extern int backup_dir_len;
 extern int basis_dir_cnt;
+extern int default_af_hint;
 extern struct stats stats;
 extern char *stdout_format;
 extern char *logfile_format;
@@ -547,8 +548,13 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
                        *t++ = '\0';
                }
 
-               /* check to see if we've already been given '-l user' in
-                * the remote-shell command */
+               /* NOTE: must preserve t == start of command name until the end of the args handling! */
+               if ((t = strrchr(cmd, '/')) != NULL)
+                       t++;
+               else
+                       t = cmd;
+
+               /* Check to see if we've already been given '-l user' in the remote-shell command. */
                for (i = 0; i < argc-1; i++) {
                        if (!strcmp(args[i], "-l") && args[i+1][0] != '-')
                                dash_l_set = 1;
@@ -566,22 +572,23 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
                        args[argc++] = "-l";
                        args[argc++] = user;
                }
+#ifdef AF_INET
+               if (default_af_hint == AF_INET && strcmp(t, "ssh") == 0)
+                       args[argc++] = "-4"; /* we're using ssh so we can add a -4 option */
+#endif
+#ifdef AF_INET6
+               if (default_af_hint == AF_INET6 && strcmp(t, "ssh") == 0)
+                       args[argc++] = "-6"; /* we're using ssh so we can add a -6 option */
+#endif
                args[argc++] = machine;
 #endif
 
                args[argc++] = rsync_path;
 
-               if (blocking_io < 0) {
-                       char *cp;
-                       if ((cp = strrchr(cmd, '/')) != NULL)
-                               cp++;
-                       else
-                               cp = cmd;
-                       if (strcmp(cp, "rsh") == 0 || strcmp(cp, "remsh") == 0)
-                               blocking_io = 1;
-               }
+               if (blocking_io < 0 && (strcmp(t, "rsh") == 0 || strcmp(t, "remsh") == 0))
+                       blocking_io = 1;
 
-               server_options(args,&argc);
+               server_options(args, &argc);
 
                if (argc >= MAX_ARGS - 2)
                        goto arg_overflow;
index 0af45bdaeb1cf39bdd1308098114816701504eae..f611cd6ccd15a2428c43f88d4527ece0ec63e17b 100644 (file)
@@ -3068,13 +3068,21 @@ your home directory (remove the '=' for that).
 
 0. `--ipv4`, `-4` or `--ipv6`, `-6`
 
-    Tells rsync to prefer IPv4/IPv6 when creating sockets.  This only affects
-    sockets that rsync has direct control over, such as the outgoing socket
-    when directly contacting an rsync daemon.  See also these options in the
-    `--daemon` mode section.
+    Tells rsync to prefer IPv4/IPv6 when creating sockets or running ssh.  This
+    affects sockets that rsync has direct control over, such as the outgoing
+    socket when directly contacting an rsync daemon, as well as the forwaring
+    of the `-4` or `-6` option to ssh when rsync can deduce that ssh is being
+    used as the remote shell.  For other remote shells you'll need to specify
+    the "`--rsh SHELL -4`" option directly (or whatever ipv4/ipv6 hint options
+    it uses).
+
+    These options also exist in the `--daemon` mode section.
 
     If rsync was complied without support for IPv6, the `--ipv6` option will
-    have no effect.  The `--version` output will tell you if this is the case.
+    have no effect.  The `rsync -V` output will contain "no IPv6" if is the
+    case.
+
+    See also these options in the `--daemon` mode section.
 
 0. `--checksum-seed=NUM`
 
@@ -3184,8 +3192,11 @@ The options allowed when starting an rsync daemon are as follows:
     using the port, try specifying `--ipv6` or `--ipv4` when starting the
     daemon).
 
+    These options also exist in the regular rsync options section.
+
     If rsync was complied without support for IPv6, the `--ipv6` option will
-    have no effect.  The `--version` output will tell you if this is the case.
+    have no effect.  The `rsync -V` output will contain "no IPv6" if is the
+    case.
 
 0. `--help`, `-h`