X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/8a0123e50e05c471997f5999ce3347689e54ef8c..d16b5fd621aac6ff4e7d2cdf9bb75c49096ec7c2:/threaded-receiver.diff diff --git a/threaded-receiver.diff b/threaded-receiver.diff index 6cdf480..b107ed0 100644 --- a/threaded-receiver.diff +++ b/threaded-receiver.diff @@ -13,14 +13,20 @@ this code works fine using the GNU pth library without any code changes if you configured it with --enable-syscall-soft --enable-pthread (you may need to twiddle the Makefile options if you didn't install the library, though). +NOTE: we still need to duplicate the partial_fname static in util.c! + If you try this out, please send some email to wayned@samba.org or the rsync mailing list with your results, build changes, bug reports, etc. Thanks! -Be sure to run "make proto" before running "make". +To use this patch, run these commands for a successful build: + + patch -p1 3) { - rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n", - code, safe_fname(file), line); -@@ -127,8 +124,6 @@ void _exit_cleanup(int code, const char - io_flush(FULL_FLUSH); - if (cleanup_fname) - do_unlink(cleanup_fname); -- if (code) -- kill_all(SIGUSR1); - if (cleanup_pid && cleanup_pid == getpid()) { - char *pidf = lp_pid_file(); - if (pidf && *pidf) ---- orig/errcode.h 2005-12-16 23:48:43 -+++ errcode.h 2005-12-16 23:50:02 + /** + * Close all open sockets and files, allowing a (somewhat) graceful + * shutdown() of socket connections. This eliminates the abortive +@@ -98,9 +94,6 @@ NORETURN void _exit_cleanup(int code, co + static int exit_code = 0; + static int unmodified_code = 0; + +- SIGACTION(SIGUSR1, SIG_IGN); +- SIGACTION(SIGUSR2, SIG_IGN); +- + if (exit_code) /* Preserve first error code when recursing. */ + code = exit_code; + +@@ -157,8 +150,6 @@ NORETURN void _exit_cleanup(int code, co + + if (cleanup_fname) + do_unlink(cleanup_fname); +- if (code) +- kill_all(SIGUSR1); + if (cleanup_pid && cleanup_pid == getpid()) { + char *pidf = lp_pid_file(); + if (pidf && *pidf) +--- old/errcode.h ++++ new/errcode.h @@ -37,7 +37,6 @@ #define RERR_CRASHED 15 /* sibling crashed */ #define RERR_TERMINATED 16 /* sibling terminated abnormally */ @@ -60,9 +77,9 @@ Be sure to run "make proto" before running "make". #define RERR_SIGNAL 20 /* status returned when sent SIGINT, SIGTERM, SIGHUP */ #define RERR_WAITCHILD 21 /* some error returned by waitpid() */ #define RERR_MALLOC 22 /* error allocating core memory buffers */ ---- orig/generator.c 2005-12-16 04:03:06 -+++ generator.c 2005-12-08 23:17:08 -@@ -65,7 +65,6 @@ extern OFF_T min_size; +--- old/generator.c ++++ new/generator.c +@@ -66,7 +66,6 @@ extern OFF_T min_size; extern int io_error; extern int allowed_lull; extern int sock_f_out; @@ -70,19 +87,19 @@ Be sure to run "make proto" before running "make". extern int protocol_version; extern int fuzzy_basis; extern int always_checksum; -@@ -96,6 +95,11 @@ static int deletion_count = 0; /* used t - static int can_link_symlinks = 1; /* start out optimistic */ - static int can_link_devices = 1; +@@ -98,6 +97,11 @@ int non_perishable_cnt = 0; + + static int deletion_count = 0; /* used to implement --max-delete */ +/* These vars are local copies so that the receiver can use the originals. */ +static int GEN_append_mode; +static int GEN_make_backups; +static int GEN_csum_length; + - /* For calling delete_file() */ - #define DEL_FORCE_RECURSE (1<<1) /* recurse even w/o --force */ - #define DEL_TERSE (1<<3) -@@ -445,8 +449,8 @@ static void sum_sizes_sqroot(struct sum_ + /* For calling delete_item() and delete_dir_contents(). */ + #define DEL_RECURSE (1<<1) /* recurse */ + #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */ +@@ -508,8 +512,8 @@ static void sum_sizes_sqroot(struct sum_ } if (protocol_version < 27) { @@ -93,8 +110,8 @@ Be sure to run "make proto" before running "make". s2length = SUM_LENGTH; } else { int32 c; -@@ -456,7 +460,7 @@ static void sum_sizes_sqroot(struct sum_ - for (c = blength; c >>= 1 && b; b--) {} +@@ -519,7 +523,7 @@ static void sum_sizes_sqroot(struct sum_ + for (c = blength; (c >>= 1) && b; b--) {} /* add a bit, subtract rollsum, round up. */ s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */ - s2length = MAX(s2length, csum_length); @@ -102,7 +119,7 @@ Be sure to run "make proto" before running "make". s2length = MIN(s2length, SUM_LENGTH); } -@@ -490,7 +494,7 @@ static void generate_and_send_sums(int f +@@ -553,7 +557,7 @@ static void generate_and_send_sums(int f sum_sizes_sqroot(&sum, len); write_sum_head(f_out, &sum); @@ -111,7 +128,7 @@ Be sure to run "make proto" before running "make". return; if (len > 0) -@@ -509,7 +513,7 @@ static void generate_and_send_sums(int f +@@ -572,7 +576,7 @@ static void generate_and_send_sums(int f if (f_copy >= 0) { full_write(f_copy, map, n1); @@ -120,7 +137,7 @@ Be sure to run "make proto" before running "make". continue; } -@@ -1143,7 +1147,7 @@ static void recv_generator(char *fname, +@@ -1347,7 +1351,7 @@ static void recv_generator(char *fname, return; } @@ -129,7 +146,7 @@ Be sure to run "make proto" before running "make". return; if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH) -@@ -1198,7 +1202,7 @@ static void recv_generator(char *fname, +@@ -1410,7 +1414,7 @@ static void recv_generator(char *fname, goto notify_others; } @@ -138,19 +155,21 @@ Be sure to run "make proto" before running "make". if (!(backupptr = get_backup_name(fname))) { close(fd); return; -@@ -1288,7 +1292,10 @@ void generate_files(int f_out, struct fi +@@ -1501,9 +1505,12 @@ void generate_files(int f_out, struct fi int save_ignore_existing = ignore_existing; int save_ignore_non_existing = ignore_non_existing; int save_do_progress = do_progress; - int save_make_backups = make_backups; + int save_make_backups = GEN_make_backups = make_backups; -+ + int dir_tweaking = !(list_only || local_name || dry_run); + + GEN_append_mode = append_mode; + GEN_csum_length = csum_length; - ++ if (protocol_version >= 29) { itemizing = 1; -@@ -1317,7 +1324,7 @@ void generate_files(int f_out, struct fi + maybe_ATTRS_REPORT = stdout_format_has_i ? 0 : ATTRS_REPORT; +@@ -1531,7 +1538,7 @@ void generate_files(int f_out, struct fi do_delete_pass(flist); do_progress = 0; @@ -159,7 +178,7 @@ Be sure to run "make proto" before running "make". whole_file = 0; if (verbose >= 2) { rprintf(FINFO, "delta-transmission %s\n", -@@ -1326,12 +1333,6 @@ void generate_files(int f_out, struct fi +@@ -1540,12 +1547,6 @@ void generate_files(int f_out, struct fi : "enabled"); } @@ -172,8 +191,8 @@ Be sure to run "make proto" before running "make". for (i = 0; i < flist->count; i++) { struct file_struct *file = flist->files[i]; -@@ -1375,23 +1376,34 @@ void generate_files(int f_out, struct fi - delete_in_dir(NULL, NULL, NULL); +@@ -1589,23 +1590,34 @@ void generate_files(int f_out, struct fi + delete_in_dir(NULL, NULL, NULL, NULL); phase++; - csum_length = SUM_LENGTH; @@ -213,7 +232,7 @@ Be sure to run "make proto" before running "make". if (local_name) strlcpy(fbuf, local_name, sizeof fbuf); else -@@ -1403,27 +1415,43 @@ void generate_files(int f_out, struct fi +@@ -1617,27 +1629,43 @@ void generate_files(int f_out, struct fi phase++; ignore_non_existing = save_ignore_non_existing; ignore_existing = save_ignore_existing; @@ -264,9 +283,9 @@ Be sure to run "make proto" before running "make". } do_progress = save_do_progress; ---- orig/io.c 2005-12-08 21:19:31 -+++ io.c 2005-12-10 19:03:08 -@@ -47,7 +47,6 @@ extern int allowed_lull; +--- old/io.c ++++ new/io.c +@@ -40,20 +40,17 @@ extern int allowed_lull; extern int am_server; extern int am_daemon; extern int am_sender; @@ -274,7 +293,12 @@ Be sure to run "make proto" before running "make". extern int eol_nulls; extern int read_batch; extern int csum_length; -@@ -60,7 +59,6 @@ extern struct stats stats; + extern int checksum_seed; + extern int protocol_version; +-extern int remove_source_files; + extern int preserve_hard_links; + extern char *filesfrom_host; + extern struct stats stats; extern struct file_list *the_file_list; const char phase_unknown[] = "unknown"; @@ -282,7 +306,7 @@ Be sure to run "make proto" before running "make". int batch_fd = -1; int batch_gen_fd = -1; -@@ -84,7 +82,6 @@ const char *io_read_phase = phase_unknow +@@ -61,7 +58,6 @@ int batch_gen_fd = -1; int kluge_around_eof = 0; int msg_fd_in = -1; @@ -290,7 +314,7 @@ Be sure to run "make proto" before running "make". int sock_f_in = -1; int sock_f_out = -1; -@@ -109,27 +106,32 @@ static int select_timeout = SELECT_TIMEO +@@ -88,27 +84,31 @@ static OFF_T active_bytecnt = 0; static void read_loop(int fd, char *buf, size_t len); struct flist_ndx_item { @@ -312,10 +336,9 @@ Be sure to run "make proto" before running "make". struct msg_list_item { - struct msg_list_item *next; + volatile struct msg_list_item *next; -+ pthread_mutex_t mutex; - char *buf; int len; + enum msgcode code; + char buf[1]; }; struct msg_list { @@ -324,12 +347,12 @@ Be sure to run "make proto" before running "make". + pthread_mutex_t mutex; }; --static struct msg_list msg_list; +-static struct msg_list msg2genr, msg2sndr; +static struct msg_list msg_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER }; static void flist_ndx_push(struct flist_ndx_list *lp, int ndx) { -@@ -139,27 +141,31 @@ static void flist_ndx_push(struct flist_ +@@ -118,27 +118,31 @@ static void flist_ndx_push(struct flist_ out_of_memory("flist_ndx_push"); item->next = NULL; item->ndx = ndx; @@ -367,7 +390,7 @@ Be sure to run "make proto" before running "make". return ndx; } -@@ -168,7 +174,7 @@ static void check_timeout(void) +@@ -147,7 +151,7 @@ static void check_timeout(void) { time_t t; @@ -376,7 +399,7 @@ Be sure to run "make proto" before running "make". return; if (!last_io_in) { -@@ -209,45 +215,40 @@ void set_io_timeout(int secs) +@@ -188,44 +192,38 @@ void set_io_timeout(int secs) /* Setup the fd used to receive MSG_* messages. Only needed during the * early stages of being a local sender (up through the sending of the @@ -397,31 +420,34 @@ Be sure to run "make proto" before running "make". -} - /* Add a message to the pending MSG_* list. */ - static void msg_list_add(int code, char *buf, int len) +-static void msg_list_add(struct msg_list *lst, int code, char *buf, int len) ++static void msg_list_add(int code, char *buf, int len) { - struct msg_list_item *ml; + struct msg_list_item *m; +- int sz = len + 4 + sizeof m[0] - 1; ++ int sz = len + sizeof m[0] - 1; + assert(am_receiver()); - if (!(ml = new(struct msg_list_item))) + if (!(m = (struct msg_list_item *)new_array(char, sz))) out_of_memory("msg_list_add"); - ml->next = NULL; -- if (!(ml->buf = new_array(char, len+4))) -+ /* NOTE: the "+ 1" allows rwrite() to use the buf! */ -+ if (!(ml->buf = new_array(char, len + 1))) - out_of_memory("msg_list_add"); -- SIVAL(ml->buf, 0, ((code+MPLEX_BASE)<<24) | len); -- memcpy(ml->buf+4, buf, len); -- ml->len = len+4; -+ memcpy(ml->buf, buf, len); -+ ml->len = len; -+ ml->code = code; + m->next = NULL; +- m->len = len + 4; +- SIVAL(m->buf, 0, ((code+MPLEX_BASE)<<24) | len); +- memcpy(m->buf + 4, buf, len); +- if (lst->tail) +- lst->tail->next = m; ++ m->len = len; ++ m->code = code; ++ memcpy(m->buf, buf, len); + + pthread_mutex_lock(&msg_list.mutex); - if (msg_list.tail) - msg_list.tail->next = ml; ++ if (msg_list.tail) ++ msg_list.tail->next = m; else - msg_list.head = ml; - msg_list.tail = ml; +- lst->head = m; +- lst->tail = m; ++ msg_list.head = m; ++ msg_list.tail = m; + pthread_mutex_unlock(&msg_list.mutex); } @@ -434,7 +460,7 @@ Be sure to run "make proto" before running "make". static void read_msg_fd(void) { char buf[2048]; -@@ -266,40 +267,6 @@ static void read_msg_fd(void) +@@ -244,51 +242,6 @@ static void read_msg_fd(void) tag = (tag >> 24) - MPLEX_BASE; switch (tag) { @@ -451,6 +477,8 @@ Be sure to run "make proto" before running "make". - exit_cleanup(RERR_STREAMIO); - } - read_loop(fd, buf, 4); +- if (remove_source_files) +- decrement_active_files(IVAL(buf,0)); - flist_ndx_push(&redo_list, IVAL(buf,0)); - break; - case MSG_DELETED: @@ -459,7 +487,7 @@ Be sure to run "make proto" before running "make". - exit_cleanup(RERR_STREAMIO); - } - read_loop(fd, buf, len); -- io_multiplex_write(MSG_DELETED, buf, len); +- send_msg(MSG_DELETED, buf, len); - break; - case MSG_SUCCESS: - if (len != 4 || !am_generator) { @@ -467,37 +495,48 @@ Be sure to run "make proto" before running "make". - exit_cleanup(RERR_STREAMIO); - } - read_loop(fd, buf, len); -- if (remove_sent_files) -- io_multiplex_write(MSG_SUCCESS, buf, len); +- if (remove_source_files) { +- decrement_active_files(IVAL(buf,0)); +- send_msg(MSG_SUCCESS, buf, len); +- } - if (preserve_hard_links) - flist_ndx_push(&hlink_list, IVAL(buf,0)); - break; +- case MSG_SOCKERR: +- if (!am_generator) { +- rprintf(FERROR, "invalid message %d:%d\n", tag, len); +- exit_cleanup(RERR_STREAMIO); +- } +- close_multiplexing_out(); +- /* FALL THROUGH */ case MSG_INFO: case MSG_ERROR: case MSG_LOG: -@@ -320,71 +287,72 @@ static void read_msg_fd(void) - msg_fd_in = fd; +@@ -332,75 +285,80 @@ void decrement_active_files(int ndx) + active_bytecnt -= the_file_list->files[ndx]->length; } -/* Try to push messages off the list onto the wire. If we leave with more +/* Try to pop messages off the list onto the wire. If we leave with more * to do, return 0. On error, return -1. If everything flushed, return 1. - * This is only active in the receiver. */ +-static int msg2genr_flush(int flush_it_all) + * This is only called by the generator. */ - static int msg_list_flush(int flush_it_all) ++static void msg_list_flush(void) { - static int written = 0; - struct timeval tv; - fd_set fds; -- ++ assert(am_generator()); + - if (msg_fd_out < 0) - return -1; -- -+ assert(am_generator()); -+ no_flush++; - while (msg_list.head) { -- struct msg_list_item *ml = msg_list.head; -- int n = write(msg_fd_out, ml->buf + written, ml->len - written); ++ if (defer_forwarding_messages) ++ return; + +- while (msg2genr.head) { +- struct msg_list_item *m = msg2genr.head; +- int n = write(msg_fd_out, m->buf + written, m->len - written); - if (n < 0) { - if (errno == EINTR) - continue; @@ -511,49 +550,55 @@ Be sure to run "make proto" before running "make". - tv.tv_usec = 0; - if (!select(msg_fd_out+1, NULL, &fds, NULL, &tv)) - check_timeout(); -- } else if ((written += n) == ml->len) { -- free(ml->buf); -- msg_list.head = ml->next; -- if (!msg_list.head) -- msg_list.tail = NULL; -- free(ml); +- } else if ((written += n) == m->len) { +- msg2genr.head = m->next; +- if (!msg2genr.head) +- msg2genr.tail = NULL; +- free(m); - written = 0; -+ struct msg_list_item *ml = (struct msg_list_item *)msg_list.head; -+ switch (ml->code) { ++ no_flush++; ++ defer_forwarding_messages = 1; ++ while (msg_list.head) { ++ struct msg_list_item *m = (struct msg_list_item *)msg_list.head; ++ pthread_mutex_lock(&msg_list.mutex); ++ if (!(msg_list.head = m->next)) ++ msg_list.tail = NULL; ++ pthread_mutex_unlock(&msg_list.mutex); ++ switch (m->code) { ++ case MSG_SOCKERR: ++ close_multiplexing_out(); ++ /* FALL THROUGH */ + case MSG_INFO: + case MSG_ERROR: + case MSG_LOG: -+ rwrite(ml->code, ml->buf, ml->len); ++ rwrite(m->code, m->buf, m->len); + break; + default: -+ io_multiplex_write(ml->code, ml->buf, ml->len); ++ io_multiplex_write(m->code, m->buf, m->len); + break; } -+ pthread_mutex_lock(&msg_list.mutex); -+ if (!(msg_list.head = ml->next)) -+ msg_list.tail = NULL; -+ pthread_mutex_unlock(&msg_list.mutex); -+ free(ml->buf); -+ free(ml); -+ if (!flush_it_all) -+ break; ++ free(m); } +- return 1; ++ defer_forwarding_messages = 0; + no_flush--; -+ - return 1; } - void send_msg(enum msgcode code, char *buf, int len) + int send_msg(enum msgcode code, char *buf, int len) { - if (msg_fd_out < 0) { -+ if (am_receiver()) -+ msg_list_add(code, buf, len); -+ else - io_multiplex_write(code, buf, len); -- return; -- } -- msg_list_add(code, buf, len); -- msg_list_flush(NORMAL_FLUSH); ++ if (!am_receiver()) { + if (!defer_forwarding_messages) + return io_multiplex_write(code, buf, len); + if (!io_multiplexing_out) + return 0; +- msg_list_add(&msg2sndr, code, buf, len); +- return 1; + } +- msg_list_add(&msg2genr, code, buf, len); +- msg2genr_flush(NORMAL_FLUSH); ++ msg_list_add(code, buf, len); + return 1; } -int get_redo_num(int itemizing, enum logcode code) @@ -592,11 +637,11 @@ Be sure to run "make proto" before running "make". return flist_ndx_pop(&hlink_list); } -@@ -465,11 +433,6 @@ static int read_timeout(int fd, char *bu +@@ -480,11 +438,6 @@ static int read_timeout(int fd, char *bu FD_ZERO(&r_fds); FD_ZERO(&w_fds); FD_SET(fd, &r_fds); -- if (msg_list.head) { +- if (msg2genr.head) { - FD_SET(msg_fd_out, &w_fds); - if (msg_fd_out > maxfd) - maxfd = msg_fd_out; @@ -604,17 +649,17 @@ Be sure to run "make proto" before running "make". if (io_filesfrom_f_out >= 0) { int new_fd; if (io_filesfrom_buflen == 0) { -@@ -502,9 +465,6 @@ static int read_timeout(int fd, char *bu +@@ -517,9 +470,6 @@ static int read_timeout(int fd, char *bu continue; } -- if (msg_list.head && FD_ISSET(msg_fd_out, &w_fds)) -- msg_list_flush(NORMAL_FLUSH); +- if (msg2genr.head && FD_ISSET(msg_fd_out, &w_fds)) +- msg2genr_flush(NORMAL_FLUSH); - if (io_filesfrom_f_out >= 0) { if (io_filesfrom_buflen) { if (FD_ISSET(io_filesfrom_f_out, &w_fds)) { -@@ -832,6 +792,8 @@ static void readfd(int fd, char *buffer, +@@ -847,6 +797,8 @@ static void readfd(int fd, char *buffer, } if (fd == write_batch_monitor_in) { @@ -623,7 +668,7 @@ Be sure to run "make proto" before running "make". if ((size_t)write(batch_fd, buffer, total) != total) exit_cleanup(RERR_FILEIO); } -@@ -1091,7 +1053,6 @@ static void writefd_unbuffered(int fd,ch +@@ -1115,7 +1067,6 @@ static void writefd_unbuffered(int fd,ch * to grab any messages they sent before they died. */ while (fd == sock_f_out && io_multiplexing_in) { set_io_timeout(30); @@ -631,59 +676,60 @@ Be sure to run "make proto" before running "make". readfd_unbuffered(sock_f_in, io_filesfrom_buf, sizeof io_filesfrom_buf); } -@@ -1101,7 +1062,7 @@ static void writefd_unbuffered(int fd,ch - total += ret; +@@ -1126,7 +1077,7 @@ static void writefd_unbuffered(int fd,ch + defer_forwarding_messages = 1; if (fd == sock_f_out) { - if (io_timeout || am_generator) + if (io_timeout || am_generator()) last_io_out = time(NULL); - sleep_for_bwlimit(ret); + sleep_for_bwlimit(cnt); } -@@ -1126,7 +1087,7 @@ static void mplex_write(enum msgcode cod - * cause output to occur down the socket. Setting contiguous_write_len - * prevents the reading of msg_fd_in once we actually start to write - * this sequence of data (though we might read it before the start). */ -- if (am_generator && msg_fd_in >= 0) -+ if (am_generator() && msg_fd_in >= 0) - contiguous_write_len = len + 4; - - if (n > sizeof buffer - 4) -@@ -1141,33 +1102,31 @@ static void mplex_write(enum msgcode cod - if (len) - writefd_unbuffered(sock_f_out, buf, len); - -- if (am_generator && msg_fd_in >= 0) -+ if (am_generator() && msg_fd_in >= 0) - contiguous_write_len = 0; +@@ -1136,23 +1087,6 @@ static void writefd_unbuffered(int fd,ch + no_flush--; } - - void io_flush(int flush_it_all) - { -- msg_list_flush(flush_it_all); +-static void msg2sndr_flush(void) +-{ +- if (defer_forwarding_messages) +- return; - -- if (!iobuf_out_cnt || no_flush) -+ if (no_flush) - return; +- while (msg2sndr.head && io_multiplexing_out) { +- struct msg_list_item *m = msg2sndr.head; +- if (!(msg2sndr.head = m->next)) +- msg2sndr.tail = NULL; +- stats.total_written += m->len; +- defer_forwarding_messages = 1; +- writefd_unbuffered(sock_f_out, m->buf, m->len); +- defer_forwarding_messages = 0; +- free(m); +- } +-} +- + /** + * Write an message to a multiplexed stream. If this fails then rsync + * exits. +@@ -1178,14 +1112,15 @@ static void mplex_write(enum msgcode cod + defer_forwarding_messages = 1; + writefd_unbuffered(sock_f_out, buf, len); + defer_forwarding_messages = 0; +- msg2sndr_flush(); ++ if (am_generator()) ++ msg_list_flush(); + } + } -- if (io_multiplexing_out) -- mplex_write(MSG_DATA, iobuf_out, iobuf_out_cnt); -- else -- writefd_unbuffered(sock_f_out, iobuf_out, iobuf_out_cnt); -- iobuf_out_cnt = 0; -+ if (iobuf_out_cnt) { -+ if (io_multiplexing_out) -+ mplex_write(MSG_DATA, iobuf_out, iobuf_out_cnt); -+ else -+ writefd_unbuffered(sock_f_out, iobuf_out, iobuf_out_cnt); -+ iobuf_out_cnt = 0; -+ } -+ +-void io_flush(int flush_it_all) ++void io_flush(UNUSED(int flush_it_all)) + { +- msg2genr_flush(flush_it_all); +- msg2sndr_flush(); + if (am_generator()) -+ msg_list_flush(flush_it_all); - } ++ msg_list_flush(); + if (!iobuf_out_cnt || no_flush) + return; +@@ -1199,11 +1134,6 @@ void io_flush(int flush_it_all) static void writefd(int fd,char *buf,size_t len) { @@ -695,7 +741,7 @@ Be sure to run "make proto" before running "make". if (fd == sock_f_out) stats.total_written += len; -@@ -1387,9 +1346,3 @@ void start_write_batch(int fd) +@@ -1409,9 +1339,3 @@ void start_write_batch(int fd) else write_batch_monitor_in = fd; } @@ -705,17 +751,17 @@ Be sure to run "make proto" before running "make". - write_batch_monitor_out = -1; - write_batch_monitor_in = -1; -} ---- orig/log.c 2005-12-16 23:48:44 -+++ log.c 2005-12-16 23:49:57 -@@ -35,7 +35,6 @@ extern int am_sender; +--- old/log.c ++++ new/log.c +@@ -33,7 +33,6 @@ extern int am_sender; extern int local_server; extern int quiet; extern int module_id; -extern int msg_fd_out; + extern int allow_8bit_chars; extern int protocol_version; extern int preserve_times; - extern int log_format_has_i; -@@ -68,7 +67,6 @@ struct { +@@ -75,7 +74,6 @@ struct { { RERR_IPC , "error in IPC code" }, { RERR_CRASHED , "sibling process crashed" }, { RERR_TERMINATED , "sibling process terminated abnormally" }, @@ -723,9 +769,9 @@ Be sure to run "make proto" before running "make". { RERR_SIGNAL , "received SIGINT, SIGTERM, or SIGHUP" }, { RERR_WAITCHILD , "waitpid() failed" }, { RERR_MALLOC , "error allocating core memory buffers" }, -@@ -206,8 +204,8 @@ void rwrite(enum logcode code, char *buf - - buf[len] = 0; +@@ -241,8 +239,8 @@ void rwrite(enum logcode code, char *buf + if (len < 0) + exit_cleanup(RERR_MESSAGEIO); - if (am_server && msg_fd_out >= 0) { - /* Pass the message to our sibling. */ @@ -734,17 +780,17 @@ Be sure to run "make proto" before running "make". send_msg((enum msgcode)code, buf, len); return; } ---- orig/main.c 2005-12-16 23:48:44 -+++ main.c 2005-12-16 23:50:33 -@@ -30,7 +30,6 @@ extern int list_only; +--- old/main.c ++++ new/main.c +@@ -32,7 +32,6 @@ extern int list_only; extern int am_root; extern int am_server; extern int am_sender; -extern int am_generator; extern int am_daemon; extern int blocking_io; - extern int remove_sent_files; -@@ -75,9 +74,20 @@ struct pid_status { + extern int remove_source_files; +@@ -96,9 +95,20 @@ struct pid_status { static time_t starttime, endtime; static int64 total_read, total_written; @@ -763,9 +809,9 @@ Be sure to run "make proto" before running "make". +} + /* Works like waitpid(), but if we already harvested the child pid in our - * sigchld_handler(), we succeed instead of returning an error. */ + * remember_children(), we succeed instead of returning an error. */ pid_t wait_process(pid_t pid, int *status_ptr, int flags) -@@ -154,7 +164,7 @@ static void handle_stats(int f) +@@ -175,7 +185,7 @@ static void handle_stats(int f) show_flist_stats(); } @@ -774,7 +820,7 @@ Be sure to run "make proto" before running "make". return; if (am_daemon) { -@@ -558,12 +568,30 @@ static void do_server_sender(int f_in, i +@@ -683,12 +693,30 @@ static void do_server_sender(int f_in, i exit_cleanup(0); } @@ -808,12 +854,19 @@ Be sure to run "make proto" before running "make". /* The receiving side mustn't obey this, or an existing symlink that * points to an identical file won't be replaced by the referent. */ -@@ -572,70 +600,16 @@ static int do_recv(int f_in,int f_out,st +@@ -697,70 +725,16 @@ static int do_recv(int f_in,int f_out,st if (preserve_hard_links) init_hard_links(); - if (fd_pair(error_pipe) < 0) { - rsyserr(FERROR, errno, "pipe failed in do_recv"); +- exit_cleanup(RERR_IPC); +- } +- +- io_flush(NORMAL_FLUSH); +- +- if ((pid = do_fork()) == -1) { +- rsyserr(FERROR, errno, "fork failed in do_recv"); + args.f_in = f_in; + args.flist = flist; + args.local_name = local_name; @@ -822,13 +875,6 @@ Be sure to run "make proto" before running "make". exit_cleanup(RERR_IPC); } -- io_flush(NORMAL_FLUSH); -- -- if ((pid = do_fork()) == -1) { -- rsyserr(FERROR, errno, "fork failed in do_recv"); -- exit_cleanup(RERR_IPC); -- } -- - if (pid == 0) { - close(error_pipe[0]); - if (f_in != f_out) @@ -884,7 +930,7 @@ Be sure to run "make proto" before running "make". generate_files(f_out, flist, local_name); handle_stats(-1); -@@ -646,10 +620,13 @@ static int do_recv(int f_in,int f_out,st +@@ -771,10 +745,13 @@ static int do_recv(int f_in,int f_out,st } io_flush(FULL_FLUSH); @@ -902,7 +948,7 @@ Be sure to run "make proto" before running "make". } -@@ -1011,22 +988,6 @@ static int start_client(int argc, char * +@@ -1176,22 +1153,6 @@ static int start_client(int argc, char * return ret; } @@ -922,30 +968,30 @@ Be sure to run "make proto" before running "make". - _exit(0); -} - - static RETSIGTYPE sigchld_handler(UNUSED(int val)) + RETSIGTYPE remember_children(UNUSED(int val)) { #ifdef WNOHANG -@@ -1109,8 +1070,6 @@ int main(int argc,char *argv[]) - int orig_argc = argc; - char **orig_argv = argv; - -- signal(SIGUSR1, sigusr1_handler); -- signal(SIGUSR2, sigusr2_handler); - signal(SIGCHLD, sigchld_handler); +@@ -1283,8 +1244,6 @@ int main(int argc,char *argv[]) + # endif + sigact.sa_flags = SA_NOCLDSTOP; + #endif +- SIGACTMASK(SIGUSR1, sigusr1_handler); +- SIGACTMASK(SIGUSR2, sigusr2_handler); + SIGACTMASK(SIGCHLD, remember_children); #ifdef MAINTAINER_MODE - signal(SIGSEGV, rsync_panic_handler); ---- orig/match.c 2005-11-10 16:58:36 -+++ match.c 2005-12-08 23:17:09 -@@ -21,7 +21,7 @@ + SIGACTMASK(SIGSEGV, rsync_panic_handler); +--- old/match.c ++++ new/match.c +@@ -23,7 +23,7 @@ + #include "rsync.h" extern int verbose; - extern int am_server; -extern int do_progress; +extern int recv_progress; extern int checksum_seed; extern int append_mode; -@@ -133,7 +133,7 @@ static void matched(int f, struct sum_st +@@ -113,7 +113,7 @@ static void matched(int f, struct sum_st else last_match = offset; @@ -954,7 +1000,7 @@ Be sure to run "make proto" before running "make". show_progress(last_match, buf->file_size); } -@@ -333,7 +333,7 @@ void match_sums(int f, struct sum_struct +@@ -317,7 +317,7 @@ void match_sums(int f, struct sum_struct if (append_mode) { OFF_T j = 0; for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) { @@ -963,7 +1009,7 @@ Be sure to run "make proto" before running "make". show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, CHUNK_SIZE), CHUNK_SIZE); -@@ -341,7 +341,7 @@ void match_sums(int f, struct sum_struct +@@ -325,7 +325,7 @@ void match_sums(int f, struct sum_struct } if (last_match < s->flength) { int32 len = s->flength - last_match; @@ -972,17 +1018,17 @@ Be sure to run "make proto" before running "make". show_progress(last_match, buf->file_size); sum_update(map_ptr(buf, last_match, len), len); last_match = s->flength; ---- orig/options.c 2005-12-16 23:48:44 -+++ options.c 2005-12-08 23:17:09 -@@ -69,7 +69,6 @@ int def_compress_level = Z_DEFAULT_COMPR +--- old/options.c ++++ new/options.c +@@ -74,7 +74,6 @@ int def_compress_level = Z_DEFAULT_COMPR int am_root = 0; int am_server = 0; int am_sender = 0; -int am_generator = 0; int am_starting_up = 1; - int orig_umask = 0; int relative_paths = -1; -@@ -89,6 +88,7 @@ int am_daemon = 0; + int implied_dirs = 1; +@@ -95,6 +94,7 @@ int am_daemon = 0; int daemon_over_rsh = 0; int do_stats = 0; int do_progress = 0; @@ -990,17 +1036,17 @@ Be sure to run "make proto" before running "make". int keep_partial = 0; int safe_symlinks = 0; int copy_unsafe_links = 0; -@@ -1236,6 +1236,7 @@ int parse_arguments(int *argc, const cha - if ((do_progress || dry_run) && !verbose && !log_before_transfer - && !am_server) +@@ -1306,6 +1306,7 @@ int parse_arguments(int *argc, const cha + + if (do_progress && !verbose && !log_before_transfer && !am_server) verbose = 1; + recv_progress = do_progress; if (dry_run) do_xfers = 0; ---- orig/pipe.c 2005-10-24 21:04:45 -+++ pipe.c 2005-12-08 23:17:09 -@@ -55,7 +55,7 @@ pid_t piped_child(char **command, int *f +--- old/pipe.c ++++ new/pipe.c +@@ -59,7 +59,7 @@ pid_t piped_child(char **command, int *f exit_cleanup(RERR_IPC); } @@ -1009,7 +1055,7 @@ Be sure to run "make proto" before running "make". if (pid == -1) { rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); -@@ -117,7 +117,7 @@ pid_t local_child(int argc, char **argv, +@@ -123,7 +123,7 @@ pid_t local_child(int argc, char **argv, exit_cleanup(RERR_IPC); } @@ -1018,18 +1064,18 @@ Be sure to run "make proto" before running "make". if (pid == -1) { rsyserr(FERROR, errno, "fork"); exit_cleanup(RERR_IPC); ---- orig/receiver.c 2005-11-10 16:58:36 -+++ receiver.c 2005-12-08 23:17:10 -@@ -24,7 +24,7 @@ extern int verbose; +--- old/receiver.c ++++ new/receiver.c +@@ -25,7 +25,7 @@ + extern int verbose; extern int do_xfers; - extern int am_daemon; extern int am_server; -extern int do_progress; +extern int recv_progress; extern int log_before_transfer; - extern int log_format_has_i; - extern int daemon_log_format_has_i; -@@ -220,7 +220,7 @@ static int receive_data(int f_in, char * + extern int stdout_format_has_i; + extern int logfile_format_has_i; +@@ -157,7 +157,7 @@ static int receive_data(int f_in, char * if (sum.remainder) sum.flength -= sum.blength - sum.remainder; for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) { @@ -1038,7 +1084,7 @@ Be sure to run "make proto" before running "make". show_progress(offset, total_size); sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE), CHUNK_SIZE); -@@ -228,7 +228,7 @@ static int receive_data(int f_in, char * +@@ -165,7 +165,7 @@ static int receive_data(int f_in, char * } if (offset < sum.flength) { int32 len = sum.flength - offset; @@ -1047,7 +1093,7 @@ Be sure to run "make proto" before running "make". show_progress(offset, total_size); sum_update(map_ptr(mapbuf, offset, len), len); offset = sum.flength; -@@ -241,7 +241,7 @@ static int receive_data(int f_in, char * +@@ -178,7 +178,7 @@ static int receive_data(int f_in, char * } while ((i = recv_token(f_in, &data)) != 0) { @@ -1056,7 +1102,7 @@ Be sure to run "make proto" before running "make". show_progress(offset, total_size); if (i > 0) { -@@ -309,7 +309,7 @@ static int receive_data(int f_in, char * +@@ -248,7 +248,7 @@ static int receive_data(int f_in, char * ftruncate(fd, offset); #endif @@ -1065,26 +1111,23 @@ Be sure to run "make proto" before running "make". end_progress(total_size); if (fd != -1 && offset > 0 && sparse_end(fd) != 0) { -@@ -362,14 +362,13 @@ static void handle_delayed_updates(struc - full_fname(fname), - safe_fname(partialptr)); +@@ -299,12 +299,12 @@ static void handle_delayed_updates(struc + "rename failed for %s (from %s)", + full_fname(fname), partialptr); } else { -- if (remove_sent_files +- if (remove_source_files - || (preserve_hard_links - && file->link_u.links)) { -+ if (remove_sent_files) { ++ if (remove_source_files) { SIVAL(numbuf, 0, i); send_msg(MSG_SUCCESS,numbuf,4); } -- handle_partial_dir(partialptr, -- PDIR_DELETE); + if (preserve_hard_links && file->link_u.links) + push_hlink_num(i); -+ handle_partial_dir(partialptr, PDIR_DELETE); + handle_partial_dir(partialptr, PDIR_DELETE); } } - } -@@ -419,11 +418,6 @@ int recv_files(int f_in, struct file_lis +@@ -355,11 +355,6 @@ int recv_files(int f_in, struct file_lis if (verbose > 2) rprintf(FINFO,"recv_files(%d) starting\n",flist->count); @@ -1094,9 +1137,9 @@ Be sure to run "make proto" before running "make". - } - if (delay_updates) - init_delayed_bits(flist->count); + delayed_bits = bitbag_create(flist->count); -@@ -444,7 +438,7 @@ int recv_files(int f_in, struct file_lis +@@ -382,7 +377,7 @@ int recv_files(int f_in, struct file_lis rprintf(FINFO, "recv_files phase=%d\n", phase); if (phase == 2 && delay_updates) handle_delayed_updates(flist, local_name); @@ -1105,22 +1148,23 @@ Be sure to run "make proto" before running "make". if (keep_partial && !partial_dir) make_backups = 0; /* prevents double backup */ if (append_mode) { -@@ -665,7 +659,7 @@ int recv_files(int f_in, struct file_lis +@@ -607,7 +602,7 @@ int recv_files(int f_in, struct file_lis /* log the transfer */ if (log_before_transfer) - log_item(file, &initial_stats, iflags, NULL); + log_item(FCLIENT, file, &initial_stats, iflags, NULL); - else if (!am_server && verbose && do_progress) + else if (!am_server && verbose && recv_progress) - rprintf(FINFO, "%s\n", safe_fname(fname)); + rprintf(FINFO, "%s\n", fname); /* recv file data */ -@@ -705,11 +699,12 @@ int recv_files(int f_in, struct file_lis +@@ -654,11 +649,13 @@ int recv_files(int f_in, struct file_lis cleanup_disable(); if (recv_ok > 0) { -- if (remove_sent_files +- if (remove_source_files - || (preserve_hard_links && file->link_u.links)) { -+ if (remove_sent_files) { ++ if (remove_source_files) { ++ decrement_active_files(i); SIVAL(numbuf, 0, i); send_msg(MSG_SUCCESS, numbuf, 4); } @@ -1129,42 +1173,40 @@ Be sure to run "make proto" before running "make". } else if (!recv_ok) { int msgtype = phase || read_batch ? FERROR : FINFO; if (msgtype == FERROR || verbose) { -@@ -732,10 +727,8 @@ int recv_files(int f_in, struct file_lis - errstr, safe_fname(fname), - keptstr, redostr); +@@ -681,8 +678,8 @@ int recv_files(int f_in, struct file_lis + errstr, fname, keptstr, redostr); } -- if (!phase) { + if (!phase) { - SIVAL(numbuf, 0, i); - send_msg(MSG_REDO, numbuf, 4); -- } -+ if (!phase) ++ decrement_active_files(i); + push_redo_num(i); + } } } - make_backups = save_make_backups; ---- orig/rsync.c 2005-07-27 23:31:12 -+++ rsync.c 2005-12-08 23:17:10 -@@ -30,7 +30,6 @@ extern int omit_dir_times; +--- old/rsync.c ++++ new/rsync.c +@@ -39,7 +39,6 @@ extern int omit_dir_times; extern int am_root; extern int am_server; extern int am_sender; -extern int am_generator; extern int am_starting_up; + extern int allow_8bit_chars; extern int preserve_uid; - extern int preserve_gid; -@@ -210,5 +209,5 @@ const char *who_am_i(void) +@@ -305,5 +304,5 @@ const char *who_am_i(void) { if (am_starting_up) return am_server ? "server" : "client"; - return am_sender ? "sender" : am_generator ? "generator" : "receiver"; + return am_sender ? "sender" : am_generator() ? "generator" : "receiver"; } ---- orig/rsync.h 2005-12-15 23:00:49 -+++ rsync.h 2005-12-10 19:02:58 -@@ -165,10 +165,8 @@ enum msgcode { +--- old/rsync.h ++++ new/rsync.h +@@ -170,10 +170,8 @@ enum msgcode { MSG_DATA=0, /* raw data on the multiplexed stream */ MSG_ERROR=FERROR, MSG_INFO=FINFO, /* remote logging */ - MSG_LOG=FLOG, MSG_FCLIENT=FCLIENT, /* sibling logging */ + MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR, /* sibling logging */ - MSG_REDO=9, /* reprocess indicated flist index */ MSG_SUCCESS=100,/* successfully updated indicated flist index */ MSG_DELETED=101,/* successfully deleted a file on receiving side */ @@ -1172,7 +1214,7 @@ Be sure to run "make proto" before running "make". }; #include "errcode.h" -@@ -319,6 +317,7 @@ enum msgcode { +@@ -330,6 +328,7 @@ enum msgcode { #endif #include @@ -1180,13 +1222,12 @@ Be sure to run "make proto" before running "make". #include "lib/pool_alloc.h" ---- orig/util.c 2005-11-12 20:13:05 -+++ util.c 2005-12-08 23:17:10 -@@ -405,51 +405,6 @@ int robust_rename(char *from, char *to, +--- old/util.c ++++ new/util.c +@@ -415,49 +415,6 @@ int robust_rename(char *from, char *to, return -1; } -- -static pid_t all_pids[10]; -static int num_pids; - @@ -1229,7 +1270,6 @@ Be sure to run "make proto" before running "make". - kill(p, sig); - } -} -- - /** Turn a user name into a uid */ int name_to_uid(char *name, uid_t *uid)