-enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
- OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,OPT_FORCE};
-
-static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
-
-static struct option long_options[] = {
- {"version", 0, 0, OPT_VERSION},
- {"server", 0, 0, OPT_SERVER},
- {"sender", 0, 0, OPT_SENDER},
- {"delete", 0, 0, OPT_DELETE},
- {"force", 0, 0, OPT_FORCE},
- {"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
- {"exclude", 1, 0, OPT_EXCLUDE},
- {"exclude-from",1, 0, OPT_EXCLUDE_FROM},
- {"rsync-path", 1, 0, OPT_RSYNC_PATH},
- {"one-file-system",0, 0, 'x'},
- {"ignore-times",0, 0, 'I'},
- {"help", 0, 0, 'h'},
- {"dry-run", 0, 0, 'n'},
- {"sparse", 0, 0, 'S'},
- {"cvs-exclude", 0, 0, 'C'},
- {"archive", 0, 0, 'a'},
- {"checksum", 0, 0, 'c'},
- {"backup", 0, 0, 'b'},
- {"update", 0, 0, 'u'},
- {"verbose", 0, 0, 'v'},
- {"recursive", 0, 0, 'r'},
- {"relative", 0, 0, 'R'},
- {"devices", 0, 0, 'D'},
- {"perms", 0, 0, 'p'},
- {"links", 0, 0, 'l'},
- {"copy-links", 0, 0, 'L'},
- {"whole-file", 0, 0, 'W'},
- {"hard-links", 0, 0, 'H'},
- {"owner", 0, 0, 'o'},
- {"group", 0, 0, 'g'},
- {"times", 0, 0, 't'},
- {"rsh", 1, 0, 'e'},
- {"suffix", 1, 0, OPT_SUFFIX},
- {"block-size", 1, 0, 'B'},
- {"temp-dir", 1, 0, 'T'},
- {"compress", 0, 0, 'z'},
- {0,0,0,0}};
-
-RETSIGTYPE sigusr1_handler(int val) {
- exit_cleanup(1);
+
+/*
+ * 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)
+ flist = batch_flist;
+
+ set_nonblocking(f_in);
+ set_nonblocking(f_out);
+
+ setup_protocol(f_out,f_in);
+
+ if (protocol_version >= 23)
+ io_start_multiplex_in(f_in);
+
+ if (am_sender) {
+ keep_dirlinks = 0; /* Must be disabled on the sender. */
+ io_start_buffering_out(f_out);
+ 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 (!read_batch) /* don't write to pipe */
+ flist = send_file_list(f_out,argc,argv);
+ 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 = 1;
+
+ if (!read_batch)
+ send_exclude_list(f_out);
+
+ if (filesfrom_fd >= 0) {
+ io_set_filesfrom_fds(filesfrom_fd, f_out);
+ filesfrom_fd = -1;
+ }
+
+ 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);