home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / UNIX / Utilities / rsync-1.6.3-MIH / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-27  |  16.3 KB  |  765 lines

  1. /* 
  2.    Copyright (C) Andrew Tridgell 1996
  3.    Copyright (C) Paul Mackerras 1996
  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. #include "rsync.h"
  21.  
  22. int verbose = 0;
  23. int always_checksum = 0;
  24. time_t starttime;
  25. off_t total_size = 0;
  26. int block_size=BLOCK_SIZE;
  27.  
  28. char *backup_suffix = BACKUP_SUFFIX;
  29.  
  30. static char *rsync_path = RSYNC_NAME;
  31.  
  32. int make_backups = 0;
  33. int preserve_links = 0;
  34. int preserve_hard_links = 0;
  35. int preserve_perms = 0;
  36. int preserve_devices = 0;
  37. int preserve_uid = 0;
  38. int preserve_gid = 0;
  39. int preserve_times = 0;
  40. int update_only = 0;
  41. int cvs_exclude = 0;
  42. int dry_run=0;
  43. int local_server=0;
  44. int ignore_times=0;
  45. int delete_mode=0;
  46. int one_file_system=0;
  47. int remote_version=0;
  48. int sparse_files=0;
  49. int do_compression=0;
  50. int am_root=0;
  51. int orig_umask=0;
  52.  
  53. extern int csum_length;
  54.  
  55. int am_server = 0;
  56. static int sender = 0;
  57. int recurse = 0;
  58.  
  59. static void usage(FILE *f);
  60.  
  61. static void report(int f)
  62. {
  63.   int in,out,tsize;
  64.   time_t t = time(NULL);
  65.   
  66.   if (!verbose) return;
  67.  
  68.   if (am_server && sender) {
  69.     write_int(f,read_total());
  70.     write_int(f,write_total());
  71.     write_int(f,total_size);
  72.     write_flush(f);
  73.     return;
  74.   }
  75.     
  76.   if (sender) {
  77.     in = read_total();
  78.     out = write_total();
  79.     tsize = (int)total_size;
  80.   } else {
  81.     in = read_int(f);
  82.     out = read_int(f);
  83.     tsize = read_int(f);
  84.   }
  85.  
  86.   printf("wrote %d bytes  read %d bytes  %g bytes/sec\n",
  87.      out,in,(in+out)/(0.5 + (t-starttime)));        
  88.   printf("total size is %d  speedup is %g\n",
  89.      tsize,(1.0*tsize)/(in+out));
  90. }
  91.  
  92.  
  93. static void server_options(char **args,int *argc)
  94. {
  95.   int ac = *argc;
  96.   static char argstr[50];
  97.   static char bsize[30];
  98.   int i, x;
  99.  
  100.   args[ac++] = "--server";
  101.  
  102.   if (!sender)
  103.     args[ac++] = "--sender";
  104.  
  105.   x = 1;
  106.   argstr[0] = '-';
  107.   for (i=0;i<verbose;i++)
  108.     argstr[x++] = 'v';
  109.   if (make_backups)
  110.     argstr[x++] = 'b';
  111.   if (update_only)
  112.     argstr[x++] = 'u';
  113.   if (dry_run)
  114.     argstr[x++] = 'n';
  115.   if (preserve_links)
  116.     argstr[x++] = 'l';
  117.   if (preserve_hard_links)
  118.     argstr[x++] = 'H';
  119.   if (preserve_uid)
  120.     argstr[x++] = 'o';
  121.   if (preserve_gid)
  122.     argstr[x++] = 'g';
  123.   if (preserve_devices)
  124.     argstr[x++] = 'D';
  125.   if (preserve_times)
  126.     argstr[x++] = 't';
  127.   if (preserve_perms)
  128.     argstr[x++] = 'p';
  129.   if (recurse)
  130.     argstr[x++] = 'r';
  131.   if (always_checksum)
  132.     argstr[x++] = 'c';
  133.   if (cvs_exclude)
  134.     argstr[x++] = 'C';
  135.   if (ignore_times)
  136.     argstr[x++] = 'I';
  137.   if (one_file_system)
  138.     argstr[x++] = 'x';
  139.   if (sparse_files)
  140.     argstr[x++] = 'S';
  141.   if (do_compression)
  142.     argstr[x++] = 'z';
  143.   argstr[x] = 0;
  144.  
  145.   if (x != 1) args[ac++] = argstr;
  146.  
  147.   if (block_size != BLOCK_SIZE) {
  148.     sprintf(bsize,"-B%d",block_size);
  149.     args[ac++] = bsize;
  150.   }    
  151.  
  152.   if (delete_mode)
  153.     args[ac++] = "--delete";
  154.  
  155.   *argc = ac;
  156. }
  157.  
  158.  
  159.  
  160. int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
  161. {
  162.   char *args[100];
  163.   int i,argc=0;
  164.   char *tok,*p;
  165.  
  166.   if (!local_server) {
  167.     if (!cmd)
  168.       cmd = getenv(RSYNC_RSH_ENV);
  169.     if (!cmd)
  170.       cmd = RSYNC_RSH;
  171.     cmd = strdup(cmd);
  172.     if (!cmd) 
  173.       goto oom;
  174.  
  175.     for (tok=strtok(cmd," ");tok;tok=strtok(NULL," ")) {
  176.       args[argc++] = tok;
  177.     }
  178.  
  179. #if HAVE_REMSH
  180.     /* remsh (on HPUX) takes the arguments the other way around */
  181.     args[argc++] = machine;
  182.     if (user) {
  183.       args[argc++] = "-l";
  184.       args[argc++] = user;
  185.     }
  186. #else
  187.     if (user) {
  188.       args[argc++] = "-l";
  189.       args[argc++] = user;
  190.     }
  191.     args[argc++] = machine;
  192. #endif
  193.   }
  194.  
  195.   args[argc++] = rsync_path;
  196.  
  197.   server_options(args,&argc);
  198.  
  199.   if (path && *path) {
  200.     char *dir = strdup(path);
  201.     p = strrchr(dir,'/');
  202.     if (p) {
  203.       *p = 0;
  204.       if (!dir[0])
  205.     args[argc++] = "/";
  206.       else
  207.     args[argc++] = dir;
  208.       p++;
  209.     } else {
  210.       args[argc++] = ".";
  211.       p = dir;
  212.     }
  213.     if (p[0])
  214.       args[argc++] = path;
  215.   }
  216.  
  217.   args[argc] = NULL;
  218.  
  219.   if (verbose > 3) {
  220.     fprintf(FERROR,"cmd=");
  221.     for (i=0;i<argc;i++)
  222.       fprintf(FERROR,"%s ",args[i]);
  223.     fprintf(FERROR,"\n");
  224.   }
  225.  
  226.   return piped_child(args,f_in,f_out);
  227.  
  228. oom:
  229.   out_of_memory("do_cmd");
  230.   return 0; /* not reached */
  231. }
  232.  
  233.  
  234.  
  235.  
  236. static char *get_local_name(struct file_list *flist,char *name)
  237. {
  238.   struct stat st;
  239.  
  240.   if (stat(name,&st) == 0) {
  241.     if (S_ISDIR(st.st_mode)) {
  242.       if (chdir(name) != 0) {
  243.     fprintf(FERROR,"chdir %s : %s\n",name,strerror(errno));
  244.     exit_cleanup(1);
  245.       }
  246.       return NULL;
  247.     }
  248.     if (flist->count > 1) {
  249.       fprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n");
  250.       exit_cleanup(1);
  251.     }
  252.     return name;
  253.   }
  254.  
  255.   if (flist->count == 1)
  256.     return name;
  257.  
  258.   if (!name) 
  259.     return NULL;
  260.  
  261.   if (mkdir(name,0777 & ~orig_umask) != 0) {
  262.     fprintf(FERROR,"mkdir %s : %s\n",name,strerror(errno));
  263.     exit_cleanup(1);
  264.   } else {
  265.     fprintf(FINFO,"created directory %s\n",name);
  266.   }
  267.  
  268.   if (chdir(name) != 0) {
  269.     fprintf(FERROR,"chdir %s : %s\n",name,strerror(errno));
  270.     exit_cleanup(1);
  271.   }
  272.  
  273.   return NULL;
  274. }
  275.  
  276.  
  277.  
  278.  
  279. void do_server_sender(int argc,char *argv[])
  280. {
  281.   int i;
  282.   char *dir = argv[0];
  283.   struct file_list *flist;
  284.  
  285.   if (verbose > 2)
  286.     fprintf(FERROR,"server_sender starting pid=%d\n",(int)getpid());
  287.   
  288.   if (chdir(dir) != 0) {
  289.     fprintf(FERROR,"chdir %s: %s\n",dir,strerror(errno));
  290.     exit_cleanup(1);
  291.   }
  292.   argc--;
  293.   argv++;
  294.   
  295.   if (strcmp(dir,".")) {
  296.     int l = strlen(dir);
  297.     if (strcmp(dir,"/") == 0) 
  298.       l = 0;
  299.     for (i=0;i<argc;i++)
  300.       argv[i] += l+1;
  301.   }
  302.  
  303.   if (argc == 0 && recurse) {
  304.     argc=1;
  305.     argv--;
  306.     argv[0] = ".";
  307.   }
  308.     
  309.  
  310.   flist = send_file_list(STDOUT_FILENO,argc,argv);
  311.   send_files(flist,STDOUT_FILENO,STDIN_FILENO);
  312.   report(STDOUT_FILENO);
  313.   exit_cleanup(0);
  314. }
  315.  
  316.  
  317. static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
  318. {
  319.   int pid;
  320.   int status=0;
  321.   int recv_pipe[2];
  322.  
  323.   if (preserve_hard_links)
  324.     init_hard_links(flist);
  325.  
  326.   if (pipe(recv_pipe) < 0) {
  327.     fprintf(FERROR,"pipe failed in do_recv\n");
  328.     exit(1);
  329.   }
  330.   
  331.  
  332.   if ((pid=fork()) == 0) {
  333.     recv_files(f_in,flist,local_name,recv_pipe[1]);
  334.     if (preserve_hard_links)
  335.       do_hard_links(flist);
  336.     if (verbose > 2)
  337.       fprintf(FERROR,"receiver read %d\n",read_total());
  338.     exit_cleanup(0);
  339.   }
  340.  
  341.   generate_files(f_out,flist,local_name,recv_pipe[0]);
  342.  
  343. //  waitpid(pid, &status, 0);
  344.   wait3(&status, 0, NULL);
  345.  
  346.   return status;
  347. }
  348.  
  349.  
  350. void do_server_recv(int argc,char *argv[])
  351. {
  352.   int status;
  353.   char *dir = NULL;
  354.   struct file_list *flist;
  355.   char *local_name=NULL;
  356.   
  357.   if (verbose > 2)
  358.     fprintf(FERROR,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
  359.  
  360.   if (argc > 0) {
  361.     dir = argv[0];
  362.     argc--;
  363.     argv++;
  364.     if (chdir(dir) != 0) {
  365.       fprintf(FERROR,"chdir %s : %s\n",dir,strerror(errno));
  366.       exit_cleanup(1);
  367.     }    
  368.   }
  369.  
  370.   if (delete_mode)
  371.     recv_exclude_list(STDIN_FILENO);
  372.  
  373.   flist = recv_file_list(STDIN_FILENO);
  374.   if (!flist || flist->count == 0) {
  375.     fprintf(FERROR,"nothing to do\n");
  376.     exit_cleanup(1);
  377.   }
  378.  
  379.   if (argc > 0) {    
  380.     if (strcmp(dir,".")) {
  381.       argv[0] += strlen(dir);
  382.       if (argv[0][0] == '/') argv[0]++;
  383.     }
  384.     local_name = get_local_name(flist,argv[0]);
  385.   }
  386.  
  387.   status = do_recv(STDIN_FILENO,STDOUT_FILENO,flist,local_name);
  388.   exit_cleanup(status);
  389. }
  390.  
  391.  
  392. static void usage(FILE *f)
  393. {
  394.   fprintf(f,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
  395.       VERSION);
  396.   fprintf(f,"Usage:\t%s [options] src user@host:dest\nOR",RSYNC_NAME);
  397.   fprintf(f,"\t%s [options] user@host:src dest\n\n",RSYNC_NAME);
  398.   fprintf(f,"Options:\n");
  399.   fprintf(f,"-v, --verbose            increase verbosity\n");
  400.   fprintf(f,"-c, --checksum           always checksum\n");
  401.   fprintf(f,"-a, --archive            archive mode (same as -rlptDog)\n");
  402.   fprintf(f,"-r, --recursive          recurse into directories\n");
  403.   fprintf(f,"-b, --backup             make backups (default ~ extension)\n");
  404.   fprintf(f,"-u, --update             update only (don't overwrite newer files)\n");
  405.   fprintf(f,"-l, --links              preserve soft links\n");
  406.   fprintf(f,"-H, --hard-links         preserve hard links\n");
  407.   fprintf(f,"-p, --perms              preserve permissions\n");
  408.   fprintf(f,"-o, --owner              preserve owner (root only)\n");
  409.   fprintf(f,"-g, --group              preserve group\n");
  410.   fprintf(f,"-D, --devices            preserve devices (root only)\n");
  411.   fprintf(f,"-t, --times              preserve times\n");  
  412.   fprintf(f,"-S, --sparse             handle sparse files efficiently\n");
  413.   fprintf(f,"-n, --dry-run            show what would have been transferred\n");
  414.   fprintf(f,"-x, --one-file-system    don't cross filesystem boundaries\n");
  415.   fprintf(f,"-B, --block-size SIZE    checksum blocking size\n");  
  416.   fprintf(f,"-e, --rsh COMMAND        specify rsh replacement\n");
  417.   fprintf(f,"    --rsync-path PATH    specify path to rsync on the remote machine\n");
  418.   fprintf(f,"-C, --cvs-exclude        auto ignore files in the same way CVS does\n");
  419.   fprintf(f,"    --delete             delete files that don't exist on the sending side\n");
  420.   fprintf(f,"-I, --ignore-times       don't exclude files that match length and time\n");
  421.   fprintf(f,"-z, --compress           compress file data\n");
  422.   fprintf(f,"    --exclude FILE       exclude file FILE\n");
  423.   fprintf(f,"    --exclude-from FILE  exclude files listed in FILE\n");
  424.   fprintf(f,"    --suffix SUFFIX      override backup suffix\n");  
  425.   fprintf(f,"    --version            print version number\n");  
  426.  
  427.   fprintf(f,"\n");
  428.   fprintf(f,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
  429.   fprintf(f,"the block size defaults to %d\n",BLOCK_SIZE);  
  430. }
  431.  
  432. enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
  433.       OPT_EXCLUDE_FROM,OPT_DELETE,OPT_RSYNC_PATH};
  434.  
  435. static char *short_options = "oblHpguDCtcahvrIxnSe:B:z";
  436.  
  437. static struct option long_options[] = {
  438.   {"version",     0,     0,    OPT_VERSION},
  439.   {"server",      0,     0,    OPT_SERVER},
  440.   {"sender",      0,     0,    OPT_SENDER},
  441.   {"delete",      0,     0,    OPT_DELETE},
  442.   {"exclude",     1,     0,    OPT_EXCLUDE},
  443.   {"exclude-from",1,     0,    OPT_EXCLUDE_FROM},
  444.   {"rsync-path",  1,     0,    OPT_RSYNC_PATH},
  445.   {"one-file-system",0,  0,    'x'},
  446.   {"ignore-times",0,     0,    'I'},
  447.   {"help",        0,     0,    'h'},
  448.   {"dry-run",     0,     0,    'n'},
  449.   {"sparse",      0,     0,    'S'},
  450.   {"cvs-exclude", 0,     0,    'C'},
  451.   {"archive",     0,     0,    'a'},
  452.   {"checksum",    0,     0,    'c'},
  453.   {"backup",      0,     0,    'b'},
  454.   {"update",      0,     0,    'u'},
  455.   {"verbose",     0,     0,    'v'},
  456.   {"recursive",   0,     0,    'r'},
  457.   {"devices",     0,     0,    'D'},
  458.   {"perms",       0,     0,    'p'},
  459.   {"links",       0,     0,    'l'},
  460.   {"hard-links",  0,     0,    'H'},
  461.   {"owner",       0,     0,    'o'},
  462.   {"group",       0,     0,    'g'},
  463.   {"times",       0,     0,    't'},
  464.   {"rsh",         1,     0,    'e'},
  465.   {"suffix",      1,     0,    OPT_SUFFIX},
  466.   {"block-size",  1,     0,    'B'},
  467.   {"compress",      0,     0,    'z'},
  468.   {0,0,0,0}};
  469.  
  470. int main(int argc,char *argv[])
  471. {
  472.     int pid, status = 0, status2 = 0;
  473.     int opt;
  474.     int option_index;
  475.     char *shell_cmd = NULL;
  476.     char *shell_machine = NULL;
  477.     char *shell_path = NULL;
  478.     char *shell_user = NULL;
  479.     char *p;
  480.     int f_in,f_out;
  481.     struct file_list *flist;
  482.     char *local_name = NULL;
  483.  
  484.     starttime = time(NULL);
  485.     am_root = (getuid() == 0);
  486.  
  487.     /* we set a 0 umask so that correct file permissions can be
  488.        carried across */
  489.     orig_umask = umask(0);
  490.  
  491.     while ((opt = getopt_long(argc, argv, 
  492.                   short_options, long_options, &option_index)) 
  493.        != -1) {
  494.       switch (opt) 
  495.     {
  496.     case OPT_VERSION:
  497.       printf("rsync version %s  protocol version %d\n",
  498.          VERSION,PROTOCOL_VERSION);
  499.       exit_cleanup(0);
  500.  
  501.     case OPT_SUFFIX:
  502.       backup_suffix = optarg;
  503.       break;
  504.  
  505.     case OPT_RSYNC_PATH:
  506.       rsync_path = optarg;
  507.       break;
  508.  
  509.     case 'I':
  510.       ignore_times = 1;
  511.       break;
  512.  
  513.     case 'x':
  514.       one_file_system=1;
  515.       break;
  516.  
  517.     case OPT_DELETE:
  518.       delete_mode = 1;
  519.       break;
  520.  
  521.     case OPT_EXCLUDE:
  522.       add_exclude(optarg);
  523.       break;
  524.  
  525.     case OPT_EXCLUDE_FROM:
  526.       add_exclude_file(optarg,1);
  527.       break;
  528.  
  529.     case 'h':
  530.       usage(FINFO);
  531.       exit_cleanup(0);
  532.  
  533.     case 'b':
  534.       make_backups=1;
  535.       break;
  536.  
  537.     case 'n':
  538.       dry_run=1;
  539.       break;
  540.  
  541.     case 'S':
  542.       sparse_files=1;
  543.       break;
  544.  
  545.     case 'C':
  546.       cvs_exclude=1;
  547.       break;
  548.  
  549.     case 'u':
  550.       update_only=1;
  551.       break;
  552.  
  553.     case 'l':
  554. #if SUPPORT_LINKS
  555.       preserve_links=1;
  556. #endif
  557.       break;
  558.  
  559.     case 'H':
  560. #if SUPPORT_HARD_LINKS
  561.       preserve_hard_links=1;
  562. #endif
  563.       break;
  564.  
  565.     case 'p':
  566.       preserve_perms=1;
  567.       break;
  568.  
  569.     case 'o':
  570.       preserve_uid=1;
  571.       break;
  572.  
  573.     case 'g':
  574.       preserve_gid=1;
  575.       break;
  576.  
  577.     case 'D':
  578.       preserve_devices=1;
  579.       break;
  580.  
  581.     case 't':
  582.       preserve_times=1;
  583.       break;
  584.  
  585.     case 'c':
  586.       always_checksum=1;
  587.       break;
  588.  
  589.     case 'v':
  590.       verbose++;
  591.       break;
  592.  
  593.     case 'a':
  594.       recurse=1;
  595. #if SUPPORT_LINKS
  596.       preserve_links=1;
  597. #endif
  598.       preserve_perms=1;
  599.       preserve_times=1;
  600.       preserve_gid=1;
  601.       if (am_root) {
  602.         preserve_devices=1;
  603.         preserve_uid=1;
  604.       }
  605.       break;
  606.  
  607.     case OPT_SERVER:
  608.       am_server = 1;
  609.       break;
  610.  
  611.     case OPT_SENDER:
  612.       if (!am_server) {
  613.         usage(FERROR);
  614.         exit_cleanup(1);
  615.       }
  616.       sender = 1;
  617.       break;
  618.  
  619.     case 'r':
  620.       recurse = 1;
  621.       break;
  622.  
  623.     case 'e':
  624.       shell_cmd = optarg;
  625.       break;
  626.  
  627.     case 'B':
  628.       block_size = atoi(optarg);
  629.       break;
  630.  
  631.         case 'z':
  632.       do_compression = 1;
  633.       break;
  634.  
  635.     default:
  636.       /* fprintf(FERROR,"bad option -%c\n",opt); */
  637.       exit_cleanup(1);
  638.     }
  639.     }
  640.  
  641.     while (optind--) {
  642.       argc--;
  643.       argv++;
  644.     }
  645.  
  646.     signal(SIGCHLD,SIG_IGN);
  647.     signal(SIGINT,SIGNAL_CAST sig_int);
  648.     signal(SIGPIPE,SIGNAL_CAST sig_int);
  649.     signal(SIGHUP,SIGNAL_CAST sig_int);
  650.  
  651.     if (dry_run)
  652.       verbose = MAX(verbose,1);
  653.  
  654.     if (am_server) {
  655.       setup_protocol(STDOUT_FILENO,STDIN_FILENO);
  656.     
  657.       if (sender) {
  658.     recv_exclude_list(STDIN_FILENO);
  659.     if (cvs_exclude)
  660.       add_cvs_excludes();
  661.     do_server_sender(argc,argv);
  662.       } else {
  663.     do_server_recv(argc,argv);
  664.       }
  665.       exit_cleanup(0);
  666.     }
  667.  
  668.     if (argc < 2) {
  669.       usage(FERROR);
  670.       exit_cleanup(1);
  671.     }
  672.  
  673.     p = strchr(argv[0],':');
  674.  
  675.     if (p) {
  676.       sender = 0;
  677.       *p = 0;
  678.       shell_machine = argv[0];
  679.       shell_path = p+1;
  680.       argc--;
  681.       argv++;
  682.     } else {
  683.       sender = 1;
  684.  
  685.       p = strchr(argv[argc-1],':');
  686.       if (!p) {
  687.     local_server = 1;
  688.       }
  689.  
  690.       if (local_server) {
  691.     shell_machine = NULL;
  692.     shell_path = argv[argc-1];
  693.       } else {
  694.     *p = 0;
  695.     shell_machine = argv[argc-1];
  696.     shell_path = p+1;
  697.       }
  698.       argc--;
  699.     }
  700.  
  701.     if (shell_machine) {
  702.       p = strchr(shell_machine,'@');
  703.       if (p) {
  704.     *p = 0;
  705.     shell_user = shell_machine;
  706.     shell_machine = p+1;
  707.       }
  708.     }
  709.  
  710.     if (verbose > 3) {
  711.       fprintf(FERROR,"cmd=%s machine=%s user=%s path=%s\n",
  712.           shell_cmd?shell_cmd:"",
  713.           shell_machine?shell_machine:"",
  714.           shell_user?shell_user:"",
  715.           shell_path?shell_path:"");
  716.     }
  717.     
  718.     if (!sender && argc != 1) {
  719.       usage(FERROR);
  720.       exit_cleanup(1);
  721.     }
  722.  
  723.     pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
  724.  
  725.     setup_protocol(f_out,f_in);
  726.  
  727.     if (verbose > 3) 
  728.       fprintf(FERROR,"parent=%d child=%d sender=%d recurse=%d\n",
  729.           (int)getpid(),pid,sender,recurse);
  730.  
  731.     if (sender) {
  732.       if (cvs_exclude)
  733.     add_cvs_excludes();
  734.       if (delete_mode) 
  735.     send_exclude_list(f_out);
  736.       flist = send_file_list(f_out,argc,argv);
  737.       if (verbose > 3) 
  738.     fprintf(FERROR,"file list sent\n");
  739.       send_files(flist,f_out,f_in);
  740.       if (verbose > 3)
  741.     fprintf(FERROR,"waiting on %d\n",pid);
  742.       wait3(&status, 0, NULL); //     waitpid(pid, &status, 0);
  743.       report(-1);
  744.       exit_cleanup(status);
  745.     }
  746.  
  747.     send_exclude_list(f_out);
  748.  
  749.     flist = recv_file_list(f_in);
  750.     if (!flist || flist->count == 0) {
  751.       fprintf(FERROR,"nothing to do\n");
  752.       exit_cleanup(0);
  753.     }
  754.  
  755.     local_name = get_local_name(flist,argv[0]);
  756.  
  757.     status2 = do_recv(f_in,f_out,flist,local_name);
  758.  
  759.     report(f_in);
  760.  
  761.     wait3(&status, 0, NULL); //    waitpid(pid, &status, 0);
  762.  
  763.     return status | status2;
  764. }
  765.