- fprintf(f,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
- VERSION);
- fprintf(f,"Usage:\t%s [options] src user@host:dest\nOR",RSYNC_NAME);
- fprintf(f,"\t%s [options] user@host:src dest\n\n",RSYNC_NAME);
- fprintf(f,"Options:\n");
- fprintf(f,"-v, --verbose increase verbosity\n");
- fprintf(f,"-c, --checksum always checksum\n");
- fprintf(f,"-a, --archive archive mode (same as -rlptDog)\n");
- fprintf(f,"-r, --recursive recurse into directories\n");
- fprintf(f,"-R, --relative use relative path names\n");
- fprintf(f,"-b, --backup make backups (default ~ extension)\n");
- fprintf(f,"-u, --update update only (don't overwrite newer files)\n");
- fprintf(f,"-l, --links preserve soft links\n");
- fprintf(f,"-L, --copy-links treat soft links like regular files\n");
- fprintf(f,"-H, --hard-links preserve hard links\n");
- fprintf(f,"-p, --perms preserve permissions\n");
- fprintf(f,"-o, --owner preserve owner (root only)\n");
- fprintf(f,"-g, --group preserve group\n");
- fprintf(f,"-D, --devices preserve devices (root only)\n");
- fprintf(f,"-t, --times preserve times\n");
- fprintf(f,"-S, --sparse handle sparse files efficiently\n");
- fprintf(f,"-n, --dry-run show what would have been transferred\n");
- fprintf(f,"-W, --whole-file copy whole files, no incremental checks\n");
- fprintf(f,"-x, --one-file-system don't cross filesystem boundaries\n");
- fprintf(f,"-B, --block-size SIZE checksum blocking size\n");
- fprintf(f,"-e, --rsh COMMAND specify rsh replacement\n");
- fprintf(f," --rsync-path PATH specify path to rsync on the remote machine\n");
- fprintf(f,"-C, --cvs-exclude auto ignore files in the same way CVS does\n");
- fprintf(f," --delete delete files that don't exist on the sending side\n");
- fprintf(f," --numeric-ids don't map uid/gid values by user/group name\n");
- fprintf(f,"-I, --ignore-times don't exclude files that match length and time\n");
- fprintf(f,"-T --temp-dir DIR create temporary files in directory DIR\n");
- fprintf(f,"-z, --compress compress file data\n");
- fprintf(f," --exclude FILE exclude file FILE\n");
- fprintf(f," --exclude-from FILE exclude files listed in FILE\n");
- fprintf(f," --suffix SUFFIX override backup suffix\n");
- fprintf(f," --version print version number\n");
-
- fprintf(f,"\n");
- fprintf(f,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
- fprintf(f,"the block size defaults to %d\n",BLOCK_SIZE);
+ set_nonblocking(f_in);
+ set_nonblocking(f_out);
+
+ io_set_sock_fds(f_in, f_out);
+ setup_protocol(f_out, f_in);
+
+ if (protocol_version >= 23)
+ io_start_multiplex_out();
+
+ if (am_sender) {
+ keep_dirlinks = 0; /* Must be disabled on the sender. */
+
+ recv_exclude_list(f_in);
+ if (cvs_exclude)
+ add_cvs_excludes();
+ do_server_sender(f_in, f_out, argc, argv);
+ } else {
+ do_server_recv(f_in, f_out, argc, argv);
+ }
+ exit_cleanup(0);
+}
+
+
+/*
+ * This is called once the connection has been negotiated. It is used
+ * for rsyncd, remote-shell, and local connections.
+ */
+int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
+{
+ struct file_list *flist = NULL;
+ int status = 0, status2 = 0;
+ char *local_name = NULL;
+
+ cleanup_child_pid = pid;
+ if (!read_batch) {
+ set_nonblocking(f_in);
+ set_nonblocking(f_out);
+ }
+
+ io_set_sock_fds(f_in, f_out);
+ setup_protocol(f_out,f_in);
+
+ if (protocol_version >= 23 && !read_batch)
+ io_start_multiplex_in();
+
+ /* We set our stderr file handle to blocking because ssh might have
+ * set it to non-blocking. This can be particularly troublesome if
+ * stderr is a clone of stdout, because ssh would have set our stdout
+ * to non-blocking at the same time (which can easily cause us to lose
+ * output from our print statements). This kluge shouldn't cause ssh
+ * any problems for how we use it. Note also that we delayed setting
+ * this until after the above protocol setup so that we know for sure
+ * that ssh is done twiddling its file descriptors. */
+ set_blocking(STDERR_FILENO);
+
+ if (am_sender) {
+ keep_dirlinks = 0; /* Must be disabled on the sender. */
+ io_start_buffering_out();
+ if (!remote_filesfrom_file)
+ set_msg_fd_in(f_in);
+ if (cvs_exclude)
+ add_cvs_excludes();
+ if (delete_mode && !delete_excluded)
+ send_exclude_list(f_out);
+ if (remote_filesfrom_file)
+ filesfrom_fd = f_in;
+
+ if (write_batch)
+ start_write_batch(f_out);
+ if (!read_batch) /* don't write to pipe */
+ flist = send_file_list(f_out,argc,argv);
+ set_msg_fd_in(-1);
+ if (verbose > 3)
+ rprintf(FINFO,"file list sent\n");
+
+ io_flush(NORMAL_FLUSH);
+ send_files(flist,f_out,f_in);
+ io_flush(FULL_FLUSH);
+ if (protocol_version >= 24) {
+ /* final goodbye message */
+ read_int(f_in);
+ }
+ if (pid != -1) {
+ if (verbose > 3)
+ rprintf(FINFO,"client_run waiting on %d\n", (int) pid);
+ io_flush(FULL_FLUSH);
+ wait_process(pid, &status);
+ }
+ report(-1);
+ io_flush(FULL_FLUSH);
+ exit_cleanup(status);
+ }
+
+ if (argc == 0 && !list_only)
+ list_only = 1;
+
+ if (!read_batch)
+ send_exclude_list(f_out);
+
+ if (filesfrom_fd >= 0) {
+ io_set_filesfrom_fds(filesfrom_fd, f_out);
+ filesfrom_fd = -1;
+ }
+
+ if (write_batch)
+ start_write_batch(f_in);
+ flist = recv_file_list(f_in);
+ if (!flist || flist->count == 0) {
+ rprintf(FINFO, "client: nothing to do: "
+ "perhaps you need to specify some filenames or "
+ "the --recursive option?\n");
+ exit_cleanup(0);
+ }
+
+ local_name = get_local_name(flist,argv[0]);
+
+ status2 = do_recv(f_in,f_out,flist,local_name);
+
+ if (pid != -1) {
+ if (verbose > 3)
+ rprintf(FINFO,"client_run2 waiting on %d\n", (int) pid);
+ io_flush(FULL_FLUSH);
+ wait_process(pid, &status);
+ }
+
+ return MAX(status, status2);