Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added insure debug support
[rsync/rsync.git]
/
main.c
diff --git
a/main.c
b/main.c
index
db9201a
..
6a4d103
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-23,8
+23,6
@@
time_t starttime = 0;
struct stats stats;
struct stats stats;
-extern int csum_length;
-
extern int verbose;
static void report(int f)
extern int verbose;
static void report(int f)
@@
-114,6
+112,7
@@
static int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f
char *tok,*dir=NULL;
extern int local_server;
extern char *rsync_path;
char *tok,*dir=NULL;
extern int local_server;
extern char *rsync_path;
+ extern int blocking_io;
if (!local_server) {
if (!cmd)
if (!local_server) {
if (!cmd)
@@
-146,6
+145,9
@@
static int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f
args[argc++] = rsync_path;
server_options(args,&argc);
args[argc++] = rsync_path;
server_options(args,&argc);
+
+
+ if (strcmp(cmd, RSYNC_RSH) == 0) blocking_io = 1;
}
args[argc++] = ".";
}
args[argc++] = ".";
@@
-263,10
+265,6
@@
static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
argv[0] = ".";
}
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);
flist = send_file_list(f_out,argc,argv);
if (!flist || flist->count == 0) {
exit_cleanup(0);
@@
-284,45
+282,79
@@
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 pid;
int status=0;
int recv_pipe[2];
+ int error_pipe[2];
extern int preserve_hard_links;
extern int preserve_hard_links;
+ extern int delete_after;
+ extern int recurse;
+ extern int delete_mode;
+ extern int remote_version;
if (preserve_hard_links)
init_hard_links(flist);
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);
}
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]);
io_flush();
if ((pid=do_fork()) == 0) {
close(recv_pipe[0]);
+ close(error_pipe[0]);
if (f_in != f_out) close(f_out);
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);
recv_files(f_in,flist,local_name,recv_pipe[1]);
report(f_in);
+ write_int(recv_pipe[1],1);
+ close(recv_pipe[1]);
io_flush();
io_flush();
- _exit(0);
+ /* finally we go to sleep until our parent kills us
+ with a USR2 signal. We sleepp for a short time as on
+ some OSes a signal won't interrupt a sleep! */
+ while (1) sleep(1);
}
close(recv_pipe[1]);
}
close(recv_pipe[1]);
+ close(error_pipe[1]);
io_close_input(f_in);
if (f_in != f_out) close(f_in);
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_start_buffering(f_out);
+ io_set_error_fd(error_pipe[0]);
+
generate_files(f_out,flist,local_name,recv_pipe[0]);
generate_files(f_out,flist,local_name,recv_pipe[0]);
+ read_int(recv_pipe[0]);
+ close(recv_pipe[0]);
+ if (remote_version >= 24) {
+ /* send a final goodbye message */
+ write_int(f_out, -1);
+ }
io_flush();
io_flush();
- waitpid(pid, &status, 0);
+
+ kill(pid, SIGUSR2);
+ wait_process(pid, &status);
return status;
}
return status;
}
@@
-336,9
+368,18
@@
static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
extern int delete_mode;
extern int delete_excluded;
extern int am_daemon;
extern int delete_mode;
extern int delete_excluded;
extern int am_daemon;
+ extern int module_id;
+ extern int am_sender;
if (verbose > 2)
rprintf(FINFO,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
if (verbose > 2)
rprintf(FINFO,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
+
+ if (am_daemon && lp_read_only(module_id) && !am_sender) {
+ rprintf(FERROR,"ERROR: module is read only\n");
+ exit_cleanup(RERR_SYNTAX);
+ return;
+ }
+
if (argc > 0) {
dir = argv[0];
if (argc > 0) {
dir = argv[0];
@@
-377,13
+418,16
@@
void start_server(int f_in, int f_out, int argc, char *argv[])
{
extern int cvs_exclude;
extern int am_sender;
{
extern int cvs_exclude;
extern int am_sender;
+ extern int remote_version;
- set_nonblocking(f_out);
- if (f_in != f_out)
- set_nonblocking(f_in);
-
setup_protocol(f_out, f_in);
setup_protocol(f_out, f_in);
+ set_nonblocking(f_in);
+ set_nonblocking(f_out);
+
+ if (remote_version >= 23)
+ io_start_multiplex_out(f_out);
+
if (am_sender) {
recv_exclude_list(f_in);
if (cvs_exclude)
if (am_sender) {
recv_exclude_list(f_in);
if (cvs_exclude)
@@
-402,8
+446,15
@@
int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
char *local_name = NULL;
extern int am_sender;
extern int list_only;
char *local_name = NULL;
extern int am_sender;
extern int list_only;
+ extern int remote_version;
+
+ set_nonblocking(f_in);
+ set_nonblocking(f_out);
setup_protocol(f_out,f_in);
setup_protocol(f_out,f_in);
+
+ if (remote_version >= 23)
+ io_start_multiplex_in(f_in);
if (am_sender) {
extern int cvs_exclude;
if (am_sender) {
extern int cvs_exclude;
@@
-417,18
+468,18
@@
int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
if (verbose > 3)
rprintf(FINFO,"file list sent\n");
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();
send_files(flist,f_out,f_in);
if (pid != -1) {
if (verbose > 3)
rprintf(FINFO,"client_run waiting on %d\n",pid);
io_flush();
- wait
pid(pid, &status, 0
);
+ wait
_process(pid, &status
);
}
report(-1);
}
report(-1);
+ if (remote_version >= 24) {
+ /* final goodbye message */
+ read_int(f_in);
+ }
exit_cleanup(status);
}
exit_cleanup(status);
}
@@
-450,7
+501,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();
if (verbose > 3)
rprintf(FINFO,"client_run2 waiting on %d\n",pid);
io_flush();
- wait
pid(pid, &status, 0
);
+ wait
_process(pid, &status
);
}
return status | status2;
}
return status | status2;
@@
-586,6
+637,10
@@
static RETSIGTYPE sigusr1_handler(int val) {
exit_cleanup(RERR_SIGNAL);
}
exit_cleanup(RERR_SIGNAL);
}
+static RETSIGTYPE sigusr2_handler(int val) {
+ _exit(0);
+}
+
int main(int argc,char *argv[])
{
extern int am_root;
int main(int argc,char *argv[])
{
extern int am_root;
@@
-595,6
+650,7
@@
int main(int argc,char *argv[])
extern int am_server;
signal(SIGUSR1, sigusr1_handler);
extern int am_server;
signal(SIGUSR1, sigusr1_handler);
+ signal(SIGUSR2, sigusr2_handler);
starttime = time(NULL);
am_root = (getuid() == 0);
starttime = time(NULL);
am_root = (getuid() == 0);
@@
-650,6
+706,8
@@
int main(int argc,char *argv[])
#endif
if (am_server) {
#endif
if (am_server) {
+ set_nonblocking(STDIN_FILENO);
+ set_nonblocking(STDOUT_FILENO);
start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
}
start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
}