X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/7b372642ec1179dece1b0b0162189112b85018bf..2b6b4d539b0aab98b1cbb9d8c639cb12473aae94:/main.c diff --git a/main.c b/main.c index 0408f61e..4cf4cf60 100644 --- a/main.c +++ b/main.c @@ -35,14 +35,16 @@ static void report(int f) extern int am_daemon; if (am_daemon) { - rprintf(FINFO, "wrote %.0f bytes read %.0f bytes total size %.0f\n", - (double)write_total(),(double)read_total(), - (double)total_size); + syslog(LOG_INFO,"wrote %.0f bytes read %.0f bytes total size %.0f\n", + (double)write_total(),(double)read_total(), + (double)total_size); if (f == -1 || !am_sender) return; } if (!verbose) return; + if (am_server && !am_sender) return; + if (am_server && am_sender) { write_longint(f,read_total()); write_longint(f,write_total()); @@ -146,40 +148,41 @@ static char *get_local_name(struct file_list *flist,char *name) STRUCT_STAT st; extern int orig_umask; - if (do_stat(name,&st) == 0) { - if (S_ISDIR(st.st_mode)) { - if (chdir(name) != 0) { - rprintf(FERROR,"chdir %s : %s (1)\n",name,strerror(errno)); - exit_cleanup(1); - } - return NULL; - } - if (flist->count > 1) { - rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n"); - exit_cleanup(1); - } - return name; - } - - if (flist->count == 1) - return name; - - if (!name) - return NULL; - - if (do_mkdir(name,0777 & ~orig_umask) != 0) { - rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno)); - exit_cleanup(1); - } else { - rprintf(FINFO,"created directory %s\n",name); - } - - if (chdir(name) != 0) { - rprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno)); - exit_cleanup(1); - } - - return NULL; + if (do_stat(name,&st) == 0) { + if (S_ISDIR(st.st_mode)) { + if (chdir(name) != 0) { + rprintf(FERROR,"chdir %s : %s (1)\n", + name,strerror(errno)); + exit_cleanup(1); + } + return NULL; + } + if (flist->count > 1) { + rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n"); + exit_cleanup(1); + } + return name; + } + + if (flist->count == 1) + return name; + + if (!name) + return NULL; + + if (do_mkdir(name,0777 & ~orig_umask) != 0) { + rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno)); + exit_cleanup(1); + } else { + rprintf(FINFO,"created directory %s\n",name); + } + + if (chdir(name) != 0) { + rprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno)); + exit_cleanup(1); + } + + return NULL; } @@ -218,40 +221,56 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[]) } flist = send_file_list(f_out,argc,argv); + if (!flist || flist->count == 0) { + exit_cleanup(0); + } + send_files(flist,f_out,f_in); report(f_out); + io_flush(); exit_cleanup(0); } static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name) { - int pid; - int status=0; - int recv_pipe[2]; - extern int preserve_hard_links; - - if (preserve_hard_links) - init_hard_links(flist); - - if (pipe(recv_pipe) < 0) { - rprintf(FERROR,"pipe failed in do_recv\n"); - exit(1); - } + int pid; + int status=0; + int recv_pipe[2]; + extern int preserve_hard_links; + + if (preserve_hard_links) + init_hard_links(flist); + + if (pipe(recv_pipe) < 0) { + rprintf(FERROR,"pipe failed in do_recv\n"); + exit_cleanup(1); + } + io_flush(); - if ((pid=do_fork()) == 0) { - recv_files(f_in,flist,local_name,recv_pipe[1]); - if (verbose > 2) - rprintf(FINFO,"receiver read %ld\n",(long)read_total()); - exit_cleanup(0); - } + if ((pid=do_fork()) == 0) { + close(recv_pipe[0]); + if (f_in != f_out) close(f_out); - generate_files(f_out,flist,local_name,recv_pipe[0]); + recv_files(f_in,flist,local_name,recv_pipe[1]); + report(f_in); - waitpid(pid, &status, 0); + if (verbose > 3) + rprintf(FINFO,"do_recv waiting on %d\n",pid); - return status; + io_flush(); + _exit(0); + } + + close(recv_pipe[1]); + io_close_input(f_in); + if (f_in != f_out) close(f_in); + generate_files(f_out,flist,local_name,recv_pipe[0]); + + io_flush(); + waitpid(pid, &status, 0); + return status; } @@ -283,7 +302,7 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) flist = recv_file_list(f_in); if (!flist || flist->count == 0) { - rprintf(FERROR,"nothing to do\n"); + rprintf(FERROR,"server_recv: nothing to do\n"); exit_cleanup(1); } @@ -296,7 +315,6 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) } status = do_recv(f_in,f_out,flist,local_name); - report(-1); exit_cleanup(status); } @@ -341,7 +359,8 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) send_files(flist,f_out,f_in); if (pid != -1) { if (verbose > 3) - rprintf(FINFO,"waiting on %d\n",pid); + rprintf(FINFO,"client_run waiting on %d\n",pid); + io_flush(); waitpid(pid, &status, 0); } report(-1); @@ -352,7 +371,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) flist = recv_file_list(f_in); if (!flist || flist->count == 0) { - rprintf(FINFO,"nothing to do\n"); + rprintf(FINFO,"client: nothing to do\n"); exit_cleanup(0); } @@ -360,9 +379,10 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) status2 = do_recv(f_in,f_out,flist,local_name); - report(f_in); - if (pid != -1) { + if (verbose > 3) + rprintf(FINFO,"client_run2 waiting on %d\n",pid); + io_flush(); waitpid(pid, &status, 0); } @@ -480,7 +500,7 @@ int main(int argc,char *argv[]) if (argc < 2) { usage(FERROR); - exit(1); + exit_cleanup(1); } /* we set a 0 umask so that correct file permissions can be @@ -502,6 +522,11 @@ int main(int argc,char *argv[]) return daemon_main(); } + if (argc < 1) { + usage(FERROR); + exit_cleanup(1); + } + if (dry_run) verbose = MAX(verbose,1);