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