preparing for release of 2.0.9
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 188cf41..bcc292b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -35,9 +35,9 @@ 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;
        }
 
@@ -218,8 +218,13 @@ 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);
 }
 
@@ -230,29 +235,40 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
        int status=0;
        int recv_pipe[2];
        extern int preserve_hard_links;
-       extern int am_daemon;
+       extern int am_server;
 
        if (preserve_hard_links)
                init_hard_links(flist);
 
        if (pipe(recv_pipe) < 0) {
                rprintf(FERROR,"pipe failed in do_recv\n");
-               exit(1);
+               exit_cleanup(1);
        }
   
+       io_flush();
 
        if ((pid=do_fork()) == 0) {
                close(recv_pipe[0]);
+               if (f_in != f_out) close(f_out);
+
                recv_files(f_in,flist,local_name,recv_pipe[1]);
-               if (am_daemon) report(-1);
-               exit_cleanup(0);
+               if (!am_server)
+                       report(f_in);
+
+               if (verbose > 3)
+                       rprintf(FINFO,"do_recv waiting on %d\n",pid);
+
+               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;
 }
 
@@ -285,7 +301,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);
        }
        
@@ -342,7 +358,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);
@@ -353,7 +370,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);
        }
        
@@ -361,9 +378,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);
        }
        
@@ -481,7 +499,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
@@ -494,11 +512,6 @@ int main(int argc,char *argv[])
        argv += optind;
        optind = 0;
 
-       if (argc < 1) {
-               usage(FERROR);
-               exit(1);
-       }
-
        signal(SIGCHLD,SIG_IGN);
        signal(SIGINT,SIGNAL_CAST sig_int);
        signal(SIGPIPE,SIGNAL_CAST sig_int);
@@ -508,6 +521,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);