- preserve_perms=1;
- preserve_times=1;
- preserve_gid=1;
- if (getuid() == 0) {
- preserve_devices=1;
- preserve_uid=1;
- }
- break;
-
- case OPT_SERVER:
- am_server = 1;
- break;
-
- case OPT_SENDER:
- if (!am_server) {
- usage(FERROR);
- exit_cleanup(1);
- }
- sender = 1;
- break;
-
- case 'r':
- recurse = 1;
- break;
-
- case 'e':
- shell_cmd = optarg;
- break;
-
- case 'B':
- block_size = atoi(optarg);
- break;
-
- default:
- fprintf(FERROR,"bad option -%c\n",opt);
- exit_cleanup(1);
- }
- }
-
- while (optind--) {
- argc--;
- argv++;
- }
-
- signal(SIGCHLD,SIG_IGN);
- signal(SIGINT,SIGNAL_CAST sig_int);
- signal(SIGPIPE,SIGNAL_CAST sig_int);
- signal(SIGHUP,SIGNAL_CAST sig_int);
-
- if (dry_run)
- verbose = MAX(verbose,1);
-
- if (am_server) {
- remote_version = read_int(STDIN_FILENO);
- if (remote_version < MIN_PROTOCOL_VERSION ||
- remote_version > MAX_PROTOCOL_VERSION) {
- fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
- exit_cleanup(1);
- }
- write_int(STDOUT_FILENO,PROTOCOL_VERSION);
- write_flush(STDOUT_FILENO);
-
- setup_protocol();
-
- 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(FERROR);
- 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(FERROR,"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(FERROR);
- 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(FERROR,"protocol version mismatch - is your shell clean?\n");
- exit_cleanup(1);
- }
- }
-
- setup_protocol();
-
- if (verbose > 3)
- fprintf(FERROR,"parent=%d child=%d sender=%d recurse=%d\n",
- (int)getpid(),pid,sender,recurse);
-
- if (sender) {
- if (cvs_exclude)
- add_cvs_excludes();
- if (delete_mode)
- send_exclude_list(f_out);
- flist = send_file_list(f_out,recurse,argc,argv);
- if (verbose > 3)
- fprintf(FERROR,"file list sent\n");
- send_files(flist,f_out,f_in);
- if (verbose > 3)
- fprintf(FERROR,"waiting on %d\n",pid);
- 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) {
- fprintf(FERROR,"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);
-
- report(f_in);
-
- waitpid(pid, &status, 0);
-
- return status | status2;