open_socket_in was attempting to try all the protocols returned from
[rsync/rsync.git] / options.c
CommitLineData
7a24c346
MP
1/* -*- c-file-style: "linux" -*-
2
2855f61f
MP
3 Copyright (C) 1998-2001 by Andrew Tridgell <tridge@samba.org>
4 Copyright (C) 2000-2001 by Martin Pool <mbp@samba.org>
7a6421fa
AT
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
7a6421fa 21#include "rsync.h"
2855f61f 22#include "popt.h"
7a6421fa
AT
23
24int make_backups = 0;
25int whole_file = 0;
26int copy_links = 0;
27int preserve_links = 0;
28int preserve_hard_links = 0;
29int preserve_perms = 0;
30int preserve_devices = 0;
31int preserve_uid = 0;
32int preserve_gid = 0;
33int preserve_times = 0;
34int update_only = 0;
35int cvs_exclude = 0;
36int dry_run=0;
37int local_server=0;
38int ignore_times=0;
39int delete_mode=0;
b33b791e 40int delete_excluded=0;
7a6421fa
AT
41int one_file_system=0;
42int remote_version=0;
43int sparse_files=0;
44int do_compression=0;
45int am_root=0;
46int orig_umask=0;
47int relative_paths=0;
48int numeric_ids = 0;
49int force_delete = 0;
50int io_timeout = 0;
51int io_error = 0;
52int read_only = 0;
53int module_id = -1;
54int am_server = 0;
30ce7e8a 55int am_sender = 0;
7a6421fa
AT
56int recurse = 0;
57int am_daemon=0;
a800434a 58int do_stats=0;
eb86d661 59int do_progress=0;
c95da96a 60int keep_partial=0;
d853783f 61int safe_symlinks=0;
b5313607 62int copy_unsafe_links=0;
7a6421fa 63int block_size=BLOCK_SIZE;
f83f0548 64int size_only=0;
ef5d23eb 65int bwlimit=0;
57df171b 66int delete_after=0;
1347d512 67int only_existing=0;
0b73ca12 68int max_delete=0;
ef55c686 69int ignore_errors=0;
5b56cc19
AT
70#ifdef _WIN32
71int modify_window=2;
72#else
73int modify_window=0;
74#endif
c80ccabb 75int blocking_io=0;
7a6421fa 76
d5d4b282
MP
77/** Global options set from command line. **/
78struct global_opts global_opts;
06963d0f 79
6902ed17
MP
80int read_batch=0; /* dw */
81int write_batch=0; /* dw */
82
7a6421fa
AT
83char *backup_suffix = BACKUP_SUFFIX;
84char *tmpdir = NULL;
375a4556 85char *compare_dest = NULL;
7a6421fa
AT
86char *config_file = RSYNCD_CONF;
87char *shell_cmd = NULL;
b6062654 88char *log_format = NULL;
65575e96 89char *password_file = NULL;
41bd28fe 90char *rsync_path = RSYNC_PATH;
66203a98 91char *backup_dir = NULL;
7a6421fa
AT
92int rsync_port = RSYNC_PORT;
93
94int verbose = 0;
b86f0cef 95int quiet = 0;
7a6421fa 96int always_checksum = 0;
f7632fc6 97int list_only = 0;
7a6421fa 98
6902ed17
MP
99char *batch_ext = NULL;
100
5b56cc19
AT
101static int modify_window_set;
102
06963d0f
MP
103/** Local address to bind. As a character string because it's
104 * interpreted by the IPv6 layer: should be a numeric IP4 or ip6
105 * address, or a hostname. **/
106char *bind_address;
5c9730a4 107
7a24c346 108
27a12348 109static void print_rsync_version(enum logcode f)
7a24c346 110{
0c80cd8e 111 char const *got_socketpair = "no ";
2855f61f
MP
112 char const *hardlinks = "no ";
113 char const *links = "no ";
a358449a 114 char const *ipv6 = "no ";
0c80cd8e
MP
115
116#ifdef HAVE_SOCKETPAIR
117 got_socketpair = "";
118#endif
2855f61f
MP
119
120#if SUPPORT_HARD_LINKS
121 hardlinks = "";
122#endif
123
124#if SUPPORT_LINKS
125 links = "";
126#endif
127
a358449a
MP
128#if INET6
129 ipv6 = "";
130#endif
131
2855f61f 132 rprintf(f, "%s version %s protocol version %d\n",
a358449a 133 RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
2855f61f 134 rprintf(f,
040f7b65 135 "Copyright (C) 1996-2001 by Andrew Tridgell and others\n");
3b4b1984 136 rprintf(f, "<http://rsync.samba.org/>\n");
2855f61f 137 rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
a358449a 138 "%shard links, %ssymlinks, batchfiles, %sIPv6\n\n",
30ce7e8a 139 (int) (sizeof(OFF_T) * 8),
a358449a 140 got_socketpair, hardlinks, links, ipv6);
2855f61f 141
7a24c346 142#ifdef NO_INT64
4db41492 143 rprintf(f, "WARNING: no 64-bit integers on this platform!\n");
7a24c346
MP
144#endif
145}
146
147
0f3203c3 148void usage(enum logcode F)
7a6421fa 149{
2855f61f 150 print_rsync_version(F);
704f908e
AT
151
152 rprintf(F,"rsync is a file transfer program capable of efficient remote update\nvia a fast differencing algorithm.\n\n");
153
9ef53907 154 rprintf(F,"Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST\n");
704f908e 155 rprintf(F," or rsync [OPTION]... [USER@]HOST:SRC DEST\n");
9ef53907 156 rprintf(F," or rsync [OPTION]... SRC [SRC]... DEST\n");
14d43f1f 157 rprintf(F," or rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
9ef53907 158 rprintf(F," or rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
14d43f1f 159 rprintf(F," or rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
9ef53907
DD
160 rprintf(F,"SRC on single-colon remote HOST will be expanded by remote shell\n");
161 rprintf(F,"SRC on server remote HOST may contain shell wildcards or multiple\n");
162 rprintf(F," sources separated by space as long as they have same top-level\n");
704f908e
AT
163 rprintf(F,"\nOptions\n");
164 rprintf(F," -v, --verbose increase verbosity\n");
b86f0cef 165 rprintf(F," -q, --quiet decrease verbosity\n");
704f908e
AT
166 rprintf(F," -c, --checksum always checksum\n");
167 rprintf(F," -a, --archive archive mode\n");
168 rprintf(F," -r, --recursive recurse into directories\n");
169 rprintf(F," -R, --relative use relative path names\n");
9ef53907 170 rprintf(F," -b, --backup make backups (default %s suffix)\n",BACKUP_SUFFIX);
e20c5e95 171 rprintf(F," --backup-dir make backups into this directory\n");
9ef53907 172 rprintf(F," --suffix=SUFFIX override backup suffix\n");
704f908e
AT
173 rprintf(F," -u, --update update only (don't overwrite newer files)\n");
174 rprintf(F," -l, --links preserve soft links\n");
175 rprintf(F," -L, --copy-links treat soft links like regular files\n");
b5313607 176 rprintf(F," --copy-unsafe-links copy links outside the source tree\n");
d853783f 177 rprintf(F," --safe-links ignore links outside the destination tree\n");
704f908e
AT
178 rprintf(F," -H, --hard-links preserve hard links\n");
179 rprintf(F," -p, --perms preserve permissions\n");
180 rprintf(F," -o, --owner preserve owner (root only)\n");
181 rprintf(F," -g, --group preserve group\n");
182 rprintf(F," -D, --devices preserve devices (root only)\n");
183 rprintf(F," -t, --times preserve times\n");
184 rprintf(F," -S, --sparse handle sparse files efficiently\n");
185 rprintf(F," -n, --dry-run show what would have been transferred\n");
186 rprintf(F," -W, --whole-file copy whole files, no incremental checks\n");
187 rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
9ef53907 188 rprintf(F," -B, --block-size=SIZE checksum blocking size (default %d)\n",BLOCK_SIZE);
704f908e
AT
189 rprintf(F," -e, --rsh=COMMAND specify rsh replacement\n");
190 rprintf(F," --rsync-path=PATH specify path to rsync on the remote machine\n");
191 rprintf(F," -C, --cvs-exclude auto ignore files in the same way CVS does\n");
1347d512 192 rprintf(F," --existing only update files that already exist\n");
704f908e 193 rprintf(F," --delete delete files that don't exist on the sending side\n");
b33b791e 194 rprintf(F," --delete-excluded also delete excluded files on the receiving side\n");
57df171b 195 rprintf(F," --delete-after delete after transferring, not before\n");
ef55c686 196 rprintf(F," --ignore-errors delete even if there are IO errors\n");
0b73ca12 197 rprintf(F," --max-delete=NUM don't delete more than NUM files\n");
c95da96a 198 rprintf(F," --partial keep partially transferred files\n");
704f908e
AT
199 rprintf(F," --force force deletion of directories even if not empty\n");
200 rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
201 rprintf(F," --timeout=TIME set IO timeout in seconds\n");
202 rprintf(F," -I, --ignore-times don't exclude files that match length and time\n");
f83f0548 203 rprintf(F," --size-only only use file size when determining if a file should be transferred\n");
5b56cc19 204 rprintf(F," --modify-window=NUM Timestamp window (seconds) for file match (default=%d)\n",modify_window);
704f908e 205 rprintf(F," -T --temp-dir=DIR create temporary files in directory DIR\n");
375a4556 206 rprintf(F," --compare-dest=DIR also compare destination files relative to DIR\n");
d9fcc198 207 rprintf(F," -P equivalent to --partial --progress\n");
704f908e 208 rprintf(F," -z, --compress compress file data\n");
2acf81eb 209 rprintf(F," --exclude=PATTERN exclude files matching PATTERN\n");
858fb9eb 210 rprintf(F," --exclude-from=FILE exclude patterns listed in FILE\n");
2acf81eb 211 rprintf(F," --include=PATTERN don't exclude files matching PATTERN\n");
858fb9eb 212 rprintf(F," --include-from=FILE don't exclude patterns listed in FILE\n");
704f908e
AT
213 rprintf(F," --version print version number\n");
214 rprintf(F," --daemon run as a rsync daemon\n");
a538066d 215 rprintf(F," --no-detach do not detach from the parent\n");
2a951cd2 216 rprintf(F," --address=ADDRESS bind to the specified address\n");
704f908e
AT
217 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
218 rprintf(F," --port=PORT specify alternate rsyncd port number\n");
c80ccabb 219 rprintf(F," --blocking-io use blocking IO for the remote shell\n");
704f908e 220 rprintf(F," --stats give some file transfer stats\n");
eb86d661 221 rprintf(F," --progress show progress during transfer\n");
b6062654 222 rprintf(F," --log-format=FORMAT log file transfers using specified format\n");
65575e96 223 rprintf(F," --password-file=FILE get password from FILE\n");
ef5d23eb 224 rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
3b4b1984 225 rprintf(F," -f --read-batch=EXT read batch file\n");
6902ed17 226 rprintf(F," -F --write-batch write batch file\n");
704f908e 227 rprintf(F," -h, --help show this help screen\n");
06963d0f
MP
228#ifdef INET6
229 rprintf(F," -4 prefer IPv4\n");
230 rprintf(F," -6 prefer IPv6\n");
231#endif
7a6421fa
AT
232
233 rprintf(F,"\n");
b72f24c7
AT
234
235 rprintf(F,"\nPlease see the rsync(1) and rsyncd.conf(5) man pages for full documentation\n");
2855f61f 236 rprintf(F,"See http://rsync.samba.org/ for updates, bug reports, and answers\n");
7a6421fa
AT
237}
238
2855f61f 239enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
b33b791e
DD
240 OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS,
241 OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT,
d853783f 242 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
b5313607 243 OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
57df171b 244 OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
ef55c686 245 OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR,
5b56cc19
AT
246 OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
247 OPT_MODIFY_WINDOW};
7a6421fa 248
2855f61f
MP
249static struct poptOption long_options[] = {
250 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
251 {"version", 0, POPT_ARG_NONE, 0, OPT_VERSION},
252 {"suffix", 0, POPT_ARG_STRING, &backup_suffix},
253 {"rsync-path", 0, POPT_ARG_STRING, &rsync_path},
254 {"password-file", 0, POPT_ARG_STRING, &password_file},
255 {"ignore-times", 'I', POPT_ARG_NONE, &ignore_times},
256 {"size-only", 0, POPT_ARG_NONE, &size_only},
257 {"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW},
258 {"one-file-system", 'x', POPT_ARG_NONE, &one_file_system},
259 {"delete", 0, POPT_ARG_NONE, &delete_mode},
260 {"existing", 0, POPT_ARG_NONE, &only_existing},
261 {"delete-after", 0, POPT_ARG_NONE, &delete_after},
262 {"delete-excluded", 0, POPT_ARG_NONE, 0, OPT_DELETE_EXCLUDED},
263 {"force", 0, POPT_ARG_NONE, &force_delete},
264 {"numeric-ids", 0, POPT_ARG_NONE, &numeric_ids},
265 {"exclude", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE},
266 {"include", 0, POPT_ARG_STRING, 0, OPT_INCLUDE},
267 {"exclude-from", 0, POPT_ARG_STRING, 0, OPT_EXCLUDE_FROM},
268 {"include-from", 0, POPT_ARG_STRING, 0, OPT_INCLUDE_FROM},
269 {"safe-links", 0, POPT_ARG_NONE, &safe_symlinks},
270 {"help", 'h', POPT_ARG_NONE, 0, 'h'},
271 {"backup", 'b', POPT_ARG_NONE, &make_backups},
272 {"dry-run", 'n', POPT_ARG_NONE, &dry_run},
273 {"sparse", 'S', POPT_ARG_NONE, &sparse_files},
274 {"cvs-exclude", 'C', POPT_ARG_NONE, &cvs_exclude},
275 {"update", 'u', POPT_ARG_NONE, &update_only},
276 {"links", 'l', POPT_ARG_NONE, &preserve_links},
277 {"copy-links", 'L', POPT_ARG_NONE, &copy_links},
278 {"whole", 'W', POPT_ARG_NONE, &whole_file},
279 {"copy-unsafe-links", 0, POPT_ARG_NONE, &copy_unsafe_links},
280 {"perms", 'p', POPT_ARG_NONE, &preserve_perms},
281 {"owner", 'o', POPT_ARG_NONE, &preserve_uid},
282 {"group", 'g', POPT_ARG_NONE, &preserve_gid},
283 {"devices", 'D', POPT_ARG_NONE, &preserve_devices},
284 {"times", 't', POPT_ARG_NONE, &preserve_times},
285 {"checksum", 'c', POPT_ARG_NONE, &always_checksum},
286 {"verbose", 'v', POPT_ARG_NONE, 0, 'v'},
287 {"quiet", 'q', POPT_ARG_NONE, 0, 'q'},
288 {"archive", 'a', POPT_ARG_NONE, 0, 'a'},
289 {"server", 0, POPT_ARG_NONE, &am_server},
290 {"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER},
f6e09367 291 {"recursive", 'r', POPT_ARG_NONE, &recurse},
2855f61f
MP
292 {"relative", 'R', POPT_ARG_NONE, &relative_paths},
293 {"rsh", 'e', POPT_ARG_STRING, &shell_cmd},
294 {"block-size", 'B', POPT_ARG_INT, &block_size},
295 {"max-delete", 0, POPT_ARG_INT, &max_delete},
296 {"timeout", 0, POPT_ARG_INT, &io_timeout},
297 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir},
7c06e407 298 {"compare-dest", 0, POPT_ARG_STRING, &compare_dest},
2855f61f
MP
299 /* TODO: Should this take an optional int giving the compression level? */
300 {"compress", 'z', POPT_ARG_NONE, &do_compression},
301 {"daemon", 0, POPT_ARG_NONE, &am_daemon},
a538066d 302 {"no-detach", 0, POPT_ARG_NONE, &global_opts.no_detach},
2855f61f
MP
303 {"stats", 0, POPT_ARG_NONE, &do_stats},
304 {"progress", 0, POPT_ARG_NONE, &do_progress},
305 {"partial", 0, POPT_ARG_NONE, &keep_partial},
306 {"ignore-errors", 0, POPT_ARG_NONE, &ignore_errors},
307 {"blocking-io", 0, POPT_ARG_NONE, &blocking_io},
308 {0, 'P', POPT_ARG_NONE, 0, 'P'},
309 {"config", 0, POPT_ARG_STRING, &config_file},
310 {"port", 0, POPT_ARG_INT, &rsync_port},
311 {"log-format", 0, POPT_ARG_STRING, &log_format},
312 {"bwlimit", 0, POPT_ARG_INT, &bwlimit},
06963d0f 313 {"address", 0, POPT_ARG_STRING, &bind_address, 0},
2855f61f
MP
314 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir},
315 {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links},
6902ed17
MP
316 {"read-batch", 'f', POPT_ARG_STRING, &batch_ext, 'f'},
317 {"write-batch", 'F', POPT_ARG_NONE, &write_batch, 0},
06963d0f 318#ifdef INET6
9069dfd0
MP
319 {0, '4', POPT_ARG_VAL, &global_opts.af_hint, AF_INET },
320 {0, '6', POPT_ARG_VAL, &global_opts.af_hint, AF_INET6 },
06963d0f 321#endif
2855f61f
MP
322 {0,0,0,0}
323};
7a6421fa 324
06963d0f 325
cd8185f2
AT
326static char err_buf[100];
327
2855f61f 328
add7e8fb
MP
329/* We store the option error message, if any, so that we can log the
330 connection attempt (which requires parsing the options), and then
331 show the error later on. */
cd8185f2
AT
332void option_error(void)
333{
334 if (err_buf[0]) {
2855f61f
MP
335 rprintf(FLOG, "%s", err_buf);
336 rprintf(FERROR, "%s: %s", RSYNC_NAME, err_buf);
cd8185f2 337 } else {
add7e8fb
MP
338 rprintf (FERROR, "Error parsing options: "
339 "option may be supported on client but not on server?\n");
340 rprintf (FERROR, RSYNC_NAME ": Error parsing options: "
341 "option may be supported on client but not on server?\n");
cd8185f2 342 }
cd8185f2
AT
343}
344
345/* check to see if we should refuse this option */
346static int check_refuse_options(char *ref, int opt)
347{
348 int i, len;
349 char *p;
350 const char *name;
351
2855f61f 352 for (i=0; long_options[i].longName; i++) {
cd8185f2
AT
353 if (long_options[i].val == opt) break;
354 }
355
2855f61f 356 if (!long_options[i].longName) return 0;
cd8185f2 357
2855f61f 358 name = long_options[i].longName;
cd8185f2
AT
359 len = strlen(name);
360
361 while ((p = strstr(ref,name))) {
055af776
AT
362 if ((p==ref || p[-1]==' ') &&
363 (p[len] == ' ' || p[len] == 0)) {
8950ac03 364 snprintf(err_buf,sizeof(err_buf),
cd8185f2
AT
365 "The '%s' option is not supported by this server\n", name);
366 return 1;
367 }
368 ref += len;
369 }
370 return 0;
371}
372
373
2855f61f
MP
374static int count_args(char const **argv)
375{
376 int i = 0;
377
378 while (argv[i] != NULL)
379 i++;
380
381 return i;
382}
383
384
385/* Process command line arguments. Called on both local and remote.
386 * Returns if all options are OK, otherwise fills in err_buf and
387 * returns 0. */
388int parse_arguments(int *argc, const char ***argv, int frommain)
7a6421fa 389{
d853783f 390 int opt;
cd8185f2 391 char *ref = lp_refuse_options(module_id);
2855f61f 392 poptContext pc;
d853783f 393
2855f61f 394 /* TODO: Call poptReadDefaultConfig; handle errors. */
cd8185f2 395
2855f61f
MP
396 /* The context leaks in case of an error, but if there's a
397 * problem we always exit anyhow. */
4db41492 398 pc = poptGetContext(RSYNC_NAME, *argc, *argv, long_options, 0);
2855f61f
MP
399
400 while ((opt = poptGetNextOpt(pc)) != -1) {
cd8185f2
AT
401 if (ref) {
402 if (check_refuse_options(ref, opt)) return 0;
403 }
404
2855f61f
MP
405 /* most options are handled automatically by popt;
406 * only special cases are returned and listed here. */
407
d853783f
AT
408 switch (opt) {
409 case OPT_VERSION:
2855f61f 410 print_rsync_version(FINFO);
d853783f
AT
411 exit_cleanup(0);
412
5b56cc19 413 case OPT_MODIFY_WINDOW:
2855f61f
MP
414 /* The value has already been set by popt, but
415 * we need to remember that we're using a
416 * non-default setting. */
5b56cc19
AT
417 modify_window_set = 1;
418 break;
419
b33b791e
DD
420 case OPT_DELETE_EXCLUDED:
421 delete_excluded = 1;
422 delete_mode = 1;
423 break;
424
d853783f 425 case OPT_EXCLUDE:
2855f61f 426 add_exclude(poptGetOptArg(pc), 0);
d853783f
AT
427 break;
428
429 case OPT_INCLUDE:
2855f61f 430 add_exclude(poptGetOptArg(pc), 1);
d853783f
AT
431 break;
432
433 case OPT_EXCLUDE_FROM:
2855f61f 434 add_exclude_file(poptGetOptArg(pc), 1, 0);
d853783f
AT
435 break;
436
437 case OPT_INCLUDE_FROM:
2855f61f 438 add_exclude_file(poptGetOptArg(pc), 1, 1);
d853783f
AT
439 break;
440
441 case 'h':
442 usage(FINFO);
443 exit_cleanup(0);
444
d853783f 445 case 'H':
7a6421fa 446#if SUPPORT_HARD_LINKS
d853783f 447 preserve_hard_links=1;
2855f61f
MP
448#else
449 /* FIXME: Don't say "server" if this is
450 * happening on the client. */
451 /* FIXME: Why do we have the duplicated
452 * rprintf? Everybody who gets this message
453 * ought to send it to the client and also to
454 * the logs. */
8950ac03 455 snprintf(err_buf,sizeof(err_buf),
2855f61f
MP
456 "hard links are not supported on this %s\n",
457 am_server ? "server" : "client");
d853783f 458 rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
b11ed3b1 459 return 0;
2855f61f 460#endif /* SUPPORT_HARD_LINKS */
d853783f 461 break;
7a6421fa 462
d853783f
AT
463 case 'v':
464 verbose++;
465 break;
7a6421fa 466
b86f0cef
DD
467 case 'q':
468 if (frommain) quiet++;
469 break;
470
d853783f
AT
471 case 'a':
472 recurse=1;
7a6421fa 473#if SUPPORT_LINKS
d853783f 474 preserve_links=1;
7a6421fa 475#endif
d853783f
AT
476 preserve_perms=1;
477 preserve_times=1;
478 preserve_gid=1;
e20c5e95
AT
479 preserve_uid=1;
480 preserve_devices=1;
d853783f
AT
481 break;
482
d853783f
AT
483 case OPT_SENDER:
484 if (!am_server) {
485 usage(FERROR);
65417579 486 exit_cleanup(RERR_SYNTAX);
d853783f
AT
487 }
488 am_sender = 1;
489 break;
490
d9fcc198
AT
491 case 'P':
492 do_progress = 1;
493 keep_partial = 1;
494 break;
495
5c9730a4 496
6902ed17
MP
497 case 'f':
498 /* The filename is stored for us by popt */
499 read_batch = 1;
500 break;
501
d853783f 502 default:
2855f61f
MP
503 /* FIXME: If --daemon is specified, then errors for later
504 * parameters seem to disappear. */
8950ac03 505 snprintf(err_buf, sizeof(err_buf),
2855f61f
MP
506 "%s%s: %s\n",
507 am_server ? "on remote machine: " : "",
508 poptBadOption(pc, POPT_BADOPTION_NOALIAS),
509 poptStrerror(opt));
510 return 0;
d853783f 511 }
7a6421fa 512 }
2855f61f
MP
513
514 *argv = poptGetArgs(pc);
515 if (*argv)
516 *argc = count_args(*argv);
517 else
518 *argc = 0;
519
b11ed3b1 520 return 1;
7a6421fa
AT
521}
522
523
2855f61f
MP
524/* Construct a filtered list of options to pass through from the
525 * client to the server */
7a6421fa
AT
526void server_options(char **args,int *argc)
527{
d853783f
AT
528 int ac = *argc;
529 static char argstr[50];
530 static char bsize[30];
531 static char iotime[30];
0b73ca12 532 static char mdelete[30];
5b56cc19 533 static char mwindow[30];
ef5d23eb 534 static char bw[50];
6902ed17 535 static char fext[20]; /* dw */
ef5d23eb 536
d853783f
AT
537 int i, x;
538
539 args[ac++] = "--server";
540
541 if (!am_sender)
542 args[ac++] = "--sender";
543
544 x = 1;
545 argstr[0] = '-';
546 for (i=0;i<verbose;i++)
547 argstr[x++] = 'v';
f0b36a48 548
b86f0cef 549 /* the -q option is intentionally left out */
d853783f
AT
550 if (make_backups)
551 argstr[x++] = 'b';
552 if (update_only)
553 argstr[x++] = 'u';
554 if (dry_run)
555 argstr[x++] = 'n';
556 if (preserve_links)
557 argstr[x++] = 'l';
558 if (copy_links)
559 argstr[x++] = 'L';
560 if (whole_file)
561 argstr[x++] = 'W';
562 if (preserve_hard_links)
563 argstr[x++] = 'H';
564 if (preserve_uid)
565 argstr[x++] = 'o';
566 if (preserve_gid)
567 argstr[x++] = 'g';
568 if (preserve_devices)
569 argstr[x++] = 'D';
570 if (preserve_times)
571 argstr[x++] = 't';
572 if (preserve_perms)
573 argstr[x++] = 'p';
574 if (recurse)
575 argstr[x++] = 'r';
576 if (always_checksum)
577 argstr[x++] = 'c';
578 if (cvs_exclude)
579 argstr[x++] = 'C';
580 if (ignore_times)
581 argstr[x++] = 'I';
582 if (relative_paths)
583 argstr[x++] = 'R';
584 if (one_file_system)
585 argstr[x++] = 'x';
586 if (sparse_files)
587 argstr[x++] = 'S';
588 if (do_compression)
589 argstr[x++] = 'z';
6902ed17
MP
590 if (write_batch)
591 argstr[x++] = 'F'; /* dw */
f0b36a48
AT
592
593 /* this is a complete hack - blame Rusty
594
595 this is a hack to make the list_only (remote file list)
596 more useful */
597 if (list_only && !recurse)
598 argstr[x++] = 'r';
599
d853783f
AT
600 argstr[x] = 0;
601
602 if (x != 1) args[ac++] = argstr;
603
604 if (block_size != BLOCK_SIZE) {
8950ac03 605 snprintf(bsize,sizeof(bsize),"-B%d",block_size);
d853783f
AT
606 args[ac++] = bsize;
607 }
608
0b73ca12 609 if (max_delete && am_sender) {
8950ac03 610 snprintf(mdelete,sizeof(mdelete),"--max-delete=%d",max_delete);
0b73ca12
AT
611 args[ac++] = mdelete;
612 }
6902ed17
MP
613
614 if (batch_ext != NULL) {
615 sprintf(fext,"-f%s",batch_ext);
616 args[ac++] = fext;
617 }
0b73ca12 618
d853783f 619 if (io_timeout) {
8950ac03 620 snprintf(iotime,sizeof(iotime),"--timeout=%d",io_timeout);
d853783f
AT
621 args[ac++] = iotime;
622 }
623
ef5d23eb 624 if (bwlimit) {
8950ac03 625 snprintf(bw,sizeof(bw),"--bwlimit=%d",bwlimit);
ef5d23eb
DD
626 args[ac++] = bw;
627 }
628
d853783f
AT
629 if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
630 args[ac++] = "--suffix";
631 args[ac++] = backup_suffix;
632 }
633
b33b791e 634 if (delete_mode && !delete_excluded)
d853783f
AT
635 args[ac++] = "--delete";
636
b33b791e
DD
637 if (delete_excluded)
638 args[ac++] = "--delete-excluded";
639
f83f0548
AT
640 if (size_only)
641 args[ac++] = "--size-only";
642
5b56cc19 643 if (modify_window_set) {
8950ac03 644 snprintf(mwindow,sizeof(mwindow),"--modify-window=%d",
5b56cc19
AT
645 modify_window);
646 args[ac++] = mwindow;
647 }
648
d853783f
AT
649 if (keep_partial)
650 args[ac++] = "--partial";
651
652 if (force_delete)
653 args[ac++] = "--force";
654
57df171b
AT
655 if (delete_after)
656 args[ac++] = "--delete-after";
657
ef55c686
AT
658 if (ignore_errors)
659 args[ac++] = "--ignore-errors";
660
b5313607
DD
661 if (copy_unsafe_links)
662 args[ac++] = "--copy-unsafe-links";
663
d853783f
AT
664 if (safe_symlinks)
665 args[ac++] = "--safe-links";
666
667 if (numeric_ids)
668 args[ac++] = "--numeric-ids";
669
0b73ca12 670 if (only_existing && am_sender)
1347d512
AT
671 args[ac++] = "--existing";
672
d853783f
AT
673 if (tmpdir) {
674 args[ac++] = "--temp-dir";
675 args[ac++] = tmpdir;
676 }
677
66203a98
AT
678 if (backup_dir && am_sender) {
679 /* only the receiver needs this option, if we are the sender
680 * then we need to send it to the receiver.
681 */
682 args[ac++] = "--backup-dir";
683 args[ac++] = backup_dir;
684 }
685
375a4556
DD
686 if (compare_dest && am_sender) {
687 /* the server only needs this option if it is not the sender,
688 * and it may be an older version that doesn't know this
689 * option, so don't send it if client is the sender.
690 */
691 args[ac++] = "--compare-dest";
692 args[ac++] = compare_dest;
693 }
694
695
d853783f 696 *argc = ac;
7a6421fa
AT
697}
698