1 This patch implements a new --remote-option (-M) option that allows the
2 user to override certain settings on the remote system. For instance, it
3 is now easier to pass -M--fake-super or "-M --log-file=/tmp/foo" instead of
4 kluging up an --rsync-path setting. This also solves the case where we
5 want local --one-file-system (-x) but not remote ("-x -M--no-x"), or visa
8 To use this patch, run these commands for a successful build:
10 patch -p1 <patches/remote-option.diff
11 ./configure (optional if already run)
14 based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
15 diff --git a/options.c b/options.c
18 @@ -172,6 +172,10 @@ int link_dest = 0;
19 int basis_dir_cnt = 0;
20 char *dest_option = NULL;
22 +static int remote_option_alloc = 0;
23 +int remote_option_cnt = 0;
24 +const char **remote_options = NULL;
29 @@ -386,6 +390,7 @@ void usage(enum logcode F)
30 rprintf(F," --timeout=SECONDS set I/O timeout in seconds\n");
31 rprintf(F," --contimeout=SECONDS set daemon connection timeout in seconds\n");
32 rprintf(F," -I, --ignore-times don't skip files that match in size and mod-time\n");
33 + rprintf(F," -M, --remote-option=OPTION send OPTION to the remote side only\n");
34 rprintf(F," --size-only skip files that match in size\n");
35 rprintf(F," --modify-window=NUM compare mod-times with reduced accuracy\n");
36 rprintf(F," -T, --temp-dir=DIR create temporary files in directory DIR\n");
37 @@ -644,6 +649,7 @@ static struct poptOption long_options[] = {
38 {"password-file", 0, POPT_ARG_STRING, &password_file, 0, 0, 0 },
39 {"blocking-io", 0, POPT_ARG_VAL, &blocking_io, 1, 0, 0 },
40 {"no-blocking-io", 0, POPT_ARG_VAL, &blocking_io, 0, 0, 0 },
41 + {"remote-option", 'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
42 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
43 {"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
44 {"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
45 @@ -1139,6 +1145,26 @@ int parse_arguments(int *argc_p, const char ***argv_p)
50 + arg = poptGetOptArg(pc);
52 + snprintf(err_buf, sizeof err_buf,
53 + "Remote option must start with a dash: %s\n", arg);
56 + if (remote_option_cnt+2 >= remote_option_alloc) {
57 + remote_option_alloc += 16;
58 + remote_options = realloc_array(remote_options,
59 + const char *, remote_option_alloc);
60 + if (!remote_options)
61 + out_of_memory("parse_arguments");
62 + if (!remote_option_cnt)
63 + remote_options[0] = "ARG0";
65 + remote_options[++remote_option_cnt] = arg;
66 + remote_options[remote_option_cnt+1] = NULL;
70 /* batch_name is already set */
72 @@ -2074,6 +2100,16 @@ void server_options(char **args, int *argc_p)
73 else if (remove_source_files)
74 args[ac++] = "--remove-sent-files";
76 + if (remote_option_cnt) {
78 + if (ac + remote_option_cnt > MAX_SERVER_ARGS) {
79 + rprintf(FERROR, "too many remote options specified.\n");
80 + exit_cleanup(RERR_SYNTAX);
82 + for (j = 1; j <= remote_option_cnt; j++)
83 + args[ac++] = (char*)remote_options[j];
86 if (ac > MAX_SERVER_ARGS) { /* Not possible... */
87 rprintf(FERROR, "argc overflow in server_options().\n");
88 exit_cleanup(RERR_MALLOC);
89 diff --git a/pipe.c b/pipe.c
92 @@ -28,6 +28,8 @@ extern int blocking_io;
93 extern int filesfrom_fd;
94 extern mode_t orig_umask;
95 extern char *logfile_name;
96 +extern int remote_option_cnt;
97 +extern const char **remote_options;
98 extern struct chmod_mode_struct *chmod_modes;
101 @@ -139,6 +141,15 @@ pid_t local_child(int argc, char **argv, int *f_in, int *f_out,
105 + if (remote_option_cnt) {
106 + int rc = remote_option_cnt + 1;
107 + const char **rv = remote_options;
108 + if (!parse_arguments(&rc, &rv)) {
110 + exit_cleanup(RERR_SYNTAX);
114 if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
115 close(to_child_pipe[1]) < 0 ||
116 close(from_child_pipe[0]) < 0 ||
117 diff --git a/rsync.yo b/rsync.yo
120 @@ -429,6 +429,7 @@ to the detailed description below for a complete description. verb(
121 --progress show progress during transfer
122 -P same as --partial --progress
123 -i, --itemize-changes output a change-summary for all updates
124 + -M, --remote-option=OPTION send OPTION to the remote side only
125 --out-format=FORMAT output updates using the specified FORMAT
126 --log-file=FILE log what we're doing to the specified FILE
127 --log-file-format=FMT log updates using the specified FMT
128 @@ -1103,16 +1104,16 @@ This is a good way to backup data without using a super-user, and to store
129 ACLs from incompatible systems.
131 The bf(--fake-super) option only affects the side where the option is used.
132 -To affect the remote side of a remote-shell connection, specify an rsync
134 +To affect the remote side of a remote-shell connection, use the
135 +bf(--remote-option) (bf(-M)) option:
137 -quote(tt( rsync -av --rsync-path="rsync --fake-super" /src/ host:/dest/))
138 +quote(tt( rsync -av -M--fake-super /src/ host:/dest/))
140 -Since there is only one "side" in a local copy, this option affects both
141 -the sending and receiving of files. You'll need to specify a copy using
142 -"localhost" if you need to avoid this, possibly using the "lsh" shell
143 -script (from the support directory) as a substitute for an actual remote
144 -shell (see bf(--rsh)).
145 +For a local copy, this option affects both the source and the destination.
146 +If you wish a local copy to enable this option just for the destination
147 +files, specify bf(-M--fake-super). If you wish a local copy to enable
148 +this option just for the source files, combine bf(--fake-super) with
151 This option is overridden by both bf(--super) and bf(--no-super).
153 @@ -1384,6 +1385,36 @@ machine for use with the bf(--relative) option. For instance:
155 quote(tt( rsync -avR --rsync-path="cd /a/b && rsync" host:c/d /e/))
157 +dit(bf(-M, --remote-option=OPTION)) This option is used for more advanced
158 +situations where you want certain effects to be limited to one side of the
159 +transfer only. For instance, if you want to pass bf(--log-file=FILE) and
160 +bf(--fake-super) to the remote system, specify it like this:
162 +quote(tt( rsync -av -M --log-file=foo -M--fake-super src/ dest/))
164 +If you want to have an option affect only the local side of a transfer when
165 +it normally affects both sides, send its negation to the remote side. Like
168 +quote(tt( rsync -av -x -M--no-x src/ dest/))
170 +Be cautious using this, as it is possible to toggle an option that will cause
171 +rsync to have a different idea about what data to expect next over the socket,
172 +and that will make it fail in a cryptic fashion.
174 +Note that it is best to use a separate bf(--remote-option) for each option you
175 +want to pass. This makes your useage compatible with the bf(--protect-args)
176 +option. If that option is off, any spaces in your remote options will be split
177 +by the remote shell unless you take steps to protect them.
179 +When performing a local transfer, the "local" side is the sender and the
180 +"remote" side is the receiver.
182 +Note some versions of the popt option-parsing library have a bug in them that
183 +prevents you from using an adjacent arg with an equal in it next to a short
184 +option letter (e.g. tt(-M--log-file=/tmp/foo). If this bug affects your
185 +version of popt, you can use the version of popt that is included with rsync.
187 dit(bf(-C, --cvs-exclude)) This is a useful shorthand for excluding a
188 broad range of files that you often don't want to transfer between
189 systems. It uses a similar algorithm to CVS to determine if
190 @@ -1883,7 +1914,7 @@ option if you wish to override this.
191 Here's a example command that requests the remote side to log what is
194 -verb( rsync -av --rsync-path="rsync --log-file=/tmp/rlog" src/ dest/)
195 +verb( rsync -av --remote-option=--log-file=/tmp/rlog src/ dest/)
197 This is very useful if you need to debug why a connection is closing