- if (sender) {
- recv_exclude_list(STDIN_FILENO);
- if (cvs_exclude)
- add_cvs_excludes();
- do_server_sender(argc,argv);
- } else {
- do_server_recv(argc,argv);
- }
- exit_cleanup(0);
- }
-
- if (argc < 2) {
- usage(stderr);
- exit_cleanup(1);
- }
-
- p = strchr(argv[0],':');
-
- if (p) {
- sender = 0;
- *p = 0;
- shell_machine = argv[0];
- shell_path = p+1;
- argc--;
- argv++;
- } else {
- sender = 1;
-
- p = strchr(argv[argc-1],':');
- if (!p) {
- local_server = 1;
- }
-
- if (local_server) {
- shell_machine = NULL;
- shell_path = argv[argc-1];
- } else {
- *p = 0;
- shell_machine = argv[argc-1];
- shell_path = p+1;
- }
- argc--;
- }
-
- if (shell_machine) {
- p = strchr(shell_machine,'@');
- if (p) {
- *p = 0;
- shell_user = shell_machine;
- shell_machine = p+1;
- }
- }
-
- if (verbose > 3) {
- fprintf(stderr,"cmd=%s machine=%s user=%s path=%s\n",
- shell_cmd?shell_cmd:"",
- shell_machine?shell_machine:"",
- shell_user?shell_user:"",
- shell_path?shell_path:"");
- }
-
- if (!sender && argc != 1) {
- usage(stderr);
- exit_cleanup(1);
- }
-
- pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
-
- write_int(f_out,PROTOCOL_VERSION);
- write_flush(f_out);
- {
- remote_version = read_int(f_in);
- if (remote_version < MIN_PROTOCOL_VERSION ||
- remote_version > MAX_PROTOCOL_VERSION) {
- fprintf(stderr,"protocol version mismatch - is your shell clean?\n");
+ if (am_sender) {
+ extern int cvs_exclude;
+ extern int delete_mode;
+ if (cvs_exclude)
+ add_cvs_excludes();
+ if (delete_mode)
+ send_exclude_list(f_out);
+ flist = send_file_list(f_out,argc,argv);
+ if (verbose > 3)
+ rprintf(FINFO,"file list sent\n");
+ send_files(flist,f_out,f_in);
+ if (pid != -1) {
+ if (verbose > 3)
+ rprintf(FINFO,"client_run waiting on %d\n",pid);
+ io_flush();
+ waitpid(pid, &status, 0);
+ }
+ report(-1);
+ exit_cleanup(status);
+ }
+
+ send_exclude_list(f_out);
+
+ flist = recv_file_list(f_in);
+ if (!flist || flist->count == 0) {
+ rprintf(FINFO,"client: nothing to do\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",pid);
+ io_flush();
+ waitpid(pid, &status, 0);
+ }
+
+ return status | status2;
+}
+
+
+int start_client(int argc, char *argv[])
+{
+ char *p;
+ char *shell_machine = NULL;
+ char *shell_path = NULL;
+ char *shell_user = NULL;
+ int pid;
+ int f_in,f_out;
+ extern int local_server;
+ extern int am_sender;
+ extern char *shell_cmd;
+
+ p = strchr(argv[0],':');
+
+ if (p) {
+ if (p[1] == ':') {
+ *p = 0;
+ return start_socket_client(argv[0], p+2, argc-1, argv+1);
+ }
+
+ if (argc < 2) {
+ usage(FERROR);
+ exit_cleanup(1);
+ }
+
+ am_sender = 0;
+ *p = 0;
+ shell_machine = argv[0];
+ shell_path = p+1;
+ argc--;
+ argv++;
+ } else {
+ am_sender = 1;
+
+ p = strchr(argv[argc-1],':');
+ if (!p) {
+ local_server = 1;
+ } else if (p[1] == ':') {
+ *p = 0;
+ return start_socket_client(argv[argc-1], p+2, argc-1, argv);
+ }
+
+ if (argc < 2) {
+ usage(FERROR);
+ exit_cleanup(1);
+ }
+
+ if (local_server) {
+ shell_machine = NULL;
+ shell_path = argv[argc-1];
+ } else {
+ *p = 0;
+ shell_machine = argv[argc-1];
+ shell_path = p+1;
+ }
+ argc--;
+ }
+
+ if (shell_machine) {
+ p = strchr(shell_machine,'@');
+ if (p) {
+ *p = 0;
+ shell_user = shell_machine;
+ shell_machine = p+1;
+ }
+ }
+
+ if (verbose > 3) {
+ rprintf(FINFO,"cmd=%s machine=%s user=%s path=%s\n",
+ shell_cmd?shell_cmd:"",
+ shell_machine?shell_machine:"",
+ shell_user?shell_user:"",
+ shell_path?shell_path:"");
+ }
+
+ if (!am_sender && argc != 1) {
+ usage(FERROR);
+ exit_cleanup(1);
+ }
+
+ pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
+
+#if HAVE_SETLINEBUF
+ setlinebuf(stdout);
+ setlinebuf(stderr);
+#endif
+
+ return client_run(f_in, f_out, pid, argc, argv);
+}
+
+
+RETSIGTYPE sigusr1_handler(int val) {