X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/f855a7d01ab8401a307bb02cdcdee546df3e2423..08f15335b5b469b29cbdacd0fc5ba48d76acf280:/main.c diff --git a/main.c b/main.c index 807409e3..80839de3 100644 --- a/main.c +++ b/main.c @@ -261,10 +261,6 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[]) argv[0] = "."; } - set_nonblocking(f_out); - if (f_in != f_out) - set_nonblocking(f_in); - flist = send_file_list(f_out,argc,argv); if (!flist || flist->count == 0) { exit_cleanup(0); @@ -282,24 +278,44 @@ 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]; + int error_pipe[2]; extern int preserve_hard_links; + extern int delete_after; + extern int recurse; + extern int delete_mode; if (preserve_hard_links) init_hard_links(flist); - if (pipe(recv_pipe) < 0) { + if (!delete_after) { + /* I moved this here from recv_files() to prevent a race condition */ + if (recurse && delete_mode && !local_name && flist->count>0) { + delete_files(flist); + } + } + + if (fd_pair(recv_pipe) < 0) { rprintf(FERROR,"pipe failed in do_recv\n"); exit_cleanup(RERR_SOCKETIO); } + + if (fd_pair(error_pipe) < 0) { + rprintf(FERROR,"error pipe failed in do_recv\n"); + exit_cleanup(RERR_SOCKETIO); + } io_flush(); if ((pid=do_fork()) == 0) { close(recv_pipe[0]); + close(error_pipe[0]); if (f_in != f_out) close(f_out); - set_nonblocking(f_in); - set_nonblocking(recv_pipe[1]); + /* we can't let two processes write to the socket at one time */ + io_multiplexing_close(); + + /* set place to send errors */ + set_error_fd(error_pipe[1]); recv_files(f_in,flist,local_name,recv_pipe[1]); report(f_in); @@ -309,18 +325,18 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name) } close(recv_pipe[1]); + close(error_pipe[1]); io_close_input(f_in); if (f_in != f_out) close(f_in); - set_nonblocking(f_out); - set_nonblocking(recv_pipe[0]); - io_start_buffering(f_out); + io_set_error_fd(error_pipe[0]); + generate_files(f_out,flist,local_name,recv_pipe[0]); io_flush(); - waitpid(pid, &status, 0); + wait_process(pid, &status); return status; } @@ -376,10 +392,6 @@ void start_server(int f_in, int f_out, int argc, char *argv[]) extern int cvs_exclude; extern int am_sender; - set_nonblocking(f_out); - if (f_in != f_out) - set_nonblocking(f_in); - setup_protocol(f_out, f_in); if (am_sender) { @@ -415,16 +427,12 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) if (verbose > 3) rprintf(FINFO,"file list sent\n"); - set_nonblocking(f_out); - if (f_in != f_out) - set_nonblocking(f_in); - 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); + wait_process(pid, &status); } report(-1); exit_cleanup(status); @@ -448,7 +456,7 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[]) if (verbose > 3) rprintf(FINFO,"client_run2 waiting on %d\n",pid); io_flush(); - waitpid(pid, &status, 0); + wait_process(pid, &status); } return status | status2;