Updated to work with the newest io.c code.
[rsync/rsync-patches.git] / threaded-receiver.diff
CommitLineData
3ca259e2
WD
1This patch changes the receiving side to have the receiving code use a thread
2instead of a forked process. This extra thread does read from the socket, but
3it sends any stdout/stderr messages to the generator (main thread) to output.
4
5** This is very new code. ** Yes, it passes the "make test" testsuite, but
6there may still be some problems, especially in some of the untested features.
7(For one thing, I haven't yet added code to properly handle any keep-alive
8messages that arrive on the receiving side during the --delete-after phase!)
9
10This code just uses pthread.h directly, so configure changes will probably be
11needed to make this compatible with more systems. I have also tested that
12this code works fine using the GNU pth library without any code changes if
13you configured it with --enable-syscall-soft --enable-pthread (you may need
14to twiddle the Makefile options if you didn't install the library, though).
15
4a65fe72
WD
16NOTE: we still need to duplicate the partial_fname static in util.c!
17
3ca259e2
WD
18If you try this out, please send some email to wayned@samba.org or the rsync
19mailing list with your results, build changes, bug reports, etc. Thanks!
20
27e96866 21After applying this patch, run these commands for a successful build:
3ca259e2 22
27e96866
WD
23 ./prepare-source
24 ./configure (optional if already run)
25 make
26
9a7eef96
WD
27--- old/Makefile.in
28+++ new/Makefile.in
3ca259e2
WD
29@@ -6,7 +6,7 @@ exec_prefix=@exec_prefix@
30 bindir=@bindir@
31 mandir=@mandir@
32
33-LIBS=@LIBS@
34+LIBS=@LIBS@ -lpthread
35 CC=@CC@
36 CFLAGS=@CFLAGS@
37 CPPFLAGS=@CPPFLAGS@
9a7eef96
WD
38--- old/cleanup.c
39+++ new/cleanup.c
bc5988ec
WD
40@@ -26,10 +26,6 @@ extern int keep_partial;
41 extern int log_got_error;
42 extern char *partial_dir;
43
8857e5dd 44-#ifdef HAVE_SIGACTION
bc5988ec
WD
45-static struct sigaction sigact;
46-#endif
47-
48 /**
49 * Close all open sockets and files, allowing a (somewhat) graceful
50 * shutdown() of socket connections. This eliminates the abortive
51@@ -98,9 +94,6 @@ void _exit_cleanup(int code, const char
3ca259e2
WD
52 }
53 inside_cleanup++;
54
bc5988ec
WD
55- SIGACTION(SIGUSR1, SIG_IGN);
56- SIGACTION(SIGUSR2, SIG_IGN);
3ca259e2
WD
57-
58 if (verbose > 3) {
59 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n",
93ca4d27 60 code, file, line);
bc5988ec 61@@ -132,8 +125,6 @@ void _exit_cleanup(int code, const char
3ca259e2
WD
62 io_flush(FULL_FLUSH);
63 if (cleanup_fname)
64 do_unlink(cleanup_fname);
65- if (code)
66- kill_all(SIGUSR1);
67 if (cleanup_pid && cleanup_pid == getpid()) {
68 char *pidf = lp_pid_file();
69 if (pidf && *pidf)
9a7eef96
WD
70--- old/errcode.h
71+++ new/errcode.h
8a0123e5
WD
72@@ -37,7 +37,6 @@
73 #define RERR_CRASHED 15 /* sibling crashed */
74 #define RERR_TERMINATED 16 /* sibling terminated abnormally */
75
76-#define RERR_SIGNAL1 19 /* status returned when sent SIGUSR1 */
77 #define RERR_SIGNAL 20 /* status returned when sent SIGINT, SIGTERM, SIGHUP */
78 #define RERR_WAITCHILD 21 /* some error returned by waitpid() */
79 #define RERR_MALLOC 22 /* error allocating core memory buffers */
9a7eef96
WD
80--- old/generator.c
81+++ new/generator.c
27e96866 82@@ -67,7 +67,6 @@ extern OFF_T min_size;
3ca259e2
WD
83 extern int io_error;
84 extern int allowed_lull;
85 extern int sock_f_out;
86-extern int ignore_timeout;
87 extern int protocol_version;
88 extern int fuzzy_basis;
89 extern int always_checksum;
d42637db 90@@ -97,6 +96,11 @@ static int deletion_count = 0; /* used t
14824301
WD
91 static int can_link_symlinks = 1; /* start out optimistic */
92 static int can_link_devices = 1;
3ca259e2
WD
93
94+/* These vars are local copies so that the receiver can use the originals. */
95+static int GEN_append_mode;
96+static int GEN_make_backups;
97+static int GEN_csum_length;
98+
99 /* For calling delete_file() */
100 #define DEL_FORCE_RECURSE (1<<1) /* recurse even w/o --force */
101 #define DEL_TERSE (1<<3)
d42637db 102@@ -445,8 +449,8 @@ static void sum_sizes_sqroot(struct sum_
3ca259e2
WD
103 }
104
105 if (protocol_version < 27) {
106- s2length = csum_length;
107- } else if (csum_length == SUM_LENGTH) {
108+ s2length = GEN_csum_length;
109+ } else if (GEN_csum_length == SUM_LENGTH) {
110 s2length = SUM_LENGTH;
111 } else {
112 int32 c;
d42637db 113@@ -456,7 +460,7 @@ static void sum_sizes_sqroot(struct sum_
3ca259e2
WD
114 for (c = blength; c >>= 1 && b; b--) {}
115 /* add a bit, subtract rollsum, round up. */
116 s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */
117- s2length = MAX(s2length, csum_length);
118+ s2length = MAX(s2length, GEN_csum_length);
119 s2length = MIN(s2length, SUM_LENGTH);
120 }
121
d42637db 122@@ -490,7 +494,7 @@ static void generate_and_send_sums(int f
3ca259e2
WD
123 sum_sizes_sqroot(&sum, len);
124 write_sum_head(f_out, &sum);
125
126- if (append_mode > 0 && f_copy < 0)
127+ if (GEN_append_mode > 0 && f_copy < 0)
128 return;
129
130 if (len > 0)
d42637db 131@@ -509,7 +513,7 @@ static void generate_and_send_sums(int f
3ca259e2
WD
132
133 if (f_copy >= 0) {
134 full_write(f_copy, map, n1);
135- if (append_mode > 0)
136+ if (GEN_append_mode > 0)
137 continue;
138 }
139
d42637db 140@@ -1152,7 +1156,7 @@ static void recv_generator(char *fname,
3ca259e2
WD
141 return;
142 }
143
144- if (append_mode && st.st_size > file->length)
145+ if (GEN_append_mode && st.st_size > file->length)
146 return;
147
14824301 148 if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
d42637db 149@@ -1207,7 +1211,7 @@ static void recv_generator(char *fname,
3ca259e2
WD
150 goto notify_others;
151 }
152
153- if (inplace && make_backups && fnamecmp_type == FNAMECMP_FNAME) {
154+ if (inplace && GEN_make_backups && fnamecmp_type == FNAMECMP_FNAME) {
155 if (!(backupptr = get_backup_name(fname))) {
156 close(fd);
157 return;
3809b131 158@@ -1298,9 +1302,12 @@ void generate_files(int f_out, struct fi
3ca259e2
WD
159 int save_ignore_existing = ignore_existing;
160 int save_ignore_non_existing = ignore_non_existing;
161 int save_do_progress = do_progress;
162- int save_make_backups = make_backups;
163+ int save_make_backups = GEN_make_backups = make_backups;
3809b131
WD
164 int dir_tweaking = !(list_only || local_name || dry_run);
165
3ca259e2
WD
166+ GEN_append_mode = append_mode;
167+ GEN_csum_length = csum_length;
3809b131 168+
3ca259e2
WD
169 if (protocol_version >= 29) {
170 itemizing = 1;
3809b131
WD
171 maybe_ATTRS_REPORT = log_format_has_i ? 0 : ATTRS_REPORT;
172@@ -1328,7 +1335,7 @@ void generate_files(int f_out, struct fi
3ca259e2
WD
173 do_delete_pass(flist);
174 do_progress = 0;
175
176- if (append_mode || whole_file < 0)
177+ if (GEN_append_mode || whole_file < 0)
178 whole_file = 0;
179 if (verbose >= 2) {
180 rprintf(FINFO, "delta-transmission %s\n",
3809b131 181@@ -1337,12 +1344,6 @@ void generate_files(int f_out, struct fi
3ca259e2
WD
182 : "enabled");
183 }
184
185- /* Since we often fill up the outgoing socket and then just sit around
186- * waiting for the other 2 processes to do their thing, we don't want
187- * to exit on a timeout. If the data stops flowing, the receiver will
188- * notice that and let us know via the redo pipe (or its closing). */
189- ignore_timeout = 1;
190-
191 for (i = 0; i < flist->count; i++) {
192 struct file_struct *file = flist->files[i];
193
3809b131 194@@ -1386,23 +1387,34 @@ void generate_files(int f_out, struct fi
4a65fe72 195 delete_in_dir(NULL, NULL, NULL, NULL);
3ca259e2
WD
196
197 phase++;
198- csum_length = SUM_LENGTH;
199+ GEN_csum_length = SUM_LENGTH; /* csum_length is set by the receiver */
200 max_size = min_size = ignore_existing = ignore_non_existing = 0;
201 update_only = always_checksum = size_only = 0;
202 ignore_times = 1;
203- if (append_mode) /* resend w/o append mode */
204- append_mode = -1; /* ... but only longer files */
205- make_backups = 0; /* avoid a duplicate backup for inplace processing */
206+ if (GEN_append_mode) /* resend w/o append mode */
207+ GEN_append_mode = -1; /* ... but only longer files */
208+ GEN_make_backups = 0; /* avoid a duplicate backup for inplace processing */
209
210 if (verbose > 2)
211 rprintf(FINFO,"generate_files phase=%d\n",phase);
212
213 write_int(f_out, -1);
214+ io_flush(NORMAL_FLUSH);
215
216 /* files can cycle through the system more than once
217 * to catch initial checksum errors */
218- while ((i = get_redo_num(itemizing, code)) != -1) {
219- struct file_struct *file = flist->files[i];
220+ while (1) {
221+ struct file_struct *file;
222+ if (preserve_hard_links)
223+ check_for_finished_hlinks(itemizing, code);
224+ if ((i = get_redo_num()) < 0) {
225+ if (i == -2)
226+ break;
227+ io_flush(NORMAL_FLUSH);
228+ msleep(20);
229+ continue;
230+ }
231+ file = flist->files[i];
232 if (local_name)
233 strlcpy(fbuf, local_name, sizeof fbuf);
234 else
3809b131 235@@ -1414,27 +1426,43 @@ void generate_files(int f_out, struct fi
3ca259e2
WD
236 phase++;
237 ignore_non_existing = save_ignore_non_existing;
238 ignore_existing = save_ignore_existing;
239- make_backups = save_make_backups;
240+ GEN_make_backups = save_make_backups;
241
242 if (verbose > 2)
243 rprintf(FINFO,"generate_files phase=%d\n",phase);
244
245 write_int(f_out, -1);
246+ io_flush(NORMAL_FLUSH);
247+
248 /* Reduce round-trip lag-time for a useless delay-updates phase. */
249- if (protocol_version >= 29 && !delay_updates)
250+ if (protocol_version >= 29 && !delay_updates) {
251 write_int(f_out, -1);
252+ io_flush(NORMAL_FLUSH);
253+ }
254
255- /* Read MSG_DONE for the redo phase (and any prior messages). */
256- get_redo_num(itemizing, code);
257+ /* Read end marker for the redo phase (and any prior messages). */
258+ while (1) {
259+ if (preserve_hard_links)
260+ check_for_finished_hlinks(itemizing, code);
261+ if (get_redo_num() == -2)
262+ break;
263+ io_flush(NORMAL_FLUSH);
264+ msleep(20);
265+ }
266
267 if (protocol_version >= 29) {
268 phase++;
269 if (verbose > 2)
270 rprintf(FINFO, "generate_files phase=%d\n", phase);
271- if (delay_updates)
272+ if (delay_updates) {
273 write_int(f_out, -1);
274- /* Read MSG_DONE for delay-updates phase & prior messages. */
275- get_redo_num(itemizing, code);
276+ io_flush(NORMAL_FLUSH);
277+ }
278+ /* Read end marker for delay-updates phase & prior messages. */
279+ while (get_redo_num() != -2) {
280+ io_flush(NORMAL_FLUSH);
281+ msleep(20);
282+ }
283 }
284
285 do_progress = save_do_progress;
9a7eef96
WD
286--- old/io.c
287+++ new/io.c
d42637db 288@@ -46,20 +46,17 @@ extern int allowed_lull;
3ca259e2
WD
289 extern int am_server;
290 extern int am_daemon;
291 extern int am_sender;
292-extern int am_generator;
293 extern int eol_nulls;
294 extern int read_batch;
295 extern int csum_length;
fb0b1cab
WD
296 extern int checksum_seed;
297 extern int protocol_version;
298-extern int remove_sent_files;
299 extern int preserve_hard_links;
300 extern char *filesfrom_host;
301 extern struct stats stats;
3ca259e2
WD
302 extern struct file_list *the_file_list;
303
304 const char phase_unknown[] = "unknown";
305-int ignore_timeout = 0;
306 int batch_fd = -1;
307 int batch_gen_fd = -1;
308
d42637db 309@@ -83,7 +80,6 @@ const char *io_read_phase = phase_unknow
3ca259e2
WD
310 int kluge_around_eof = 0;
311
312 int msg_fd_in = -1;
313-int msg_fd_out = -1;
314 int sock_f_in = -1;
315 int sock_f_out = -1;
316
3a748b26
WD
317@@ -102,7 +98,6 @@ static char io_filesfrom_buf[2048];
318 static char *io_filesfrom_bp;
319 static char io_filesfrom_lastchar;
320 static int io_filesfrom_buflen;
321-static int defer_forwarding_messages = 0;
322 static int select_timeout = SELECT_TIMEOUT;
323 static int active_filecnt = 0;
324 static OFF_T active_bytecnt = 0;
325@@ -110,27 +105,31 @@ static OFF_T active_bytecnt = 0;
3ca259e2
WD
326 static void read_loop(int fd, char *buf, size_t len);
327
328 struct flist_ndx_item {
329- struct flist_ndx_item *next;
330+ volatile struct flist_ndx_item *next;
331 int ndx;
332 };
333
334 struct flist_ndx_list {
335- struct flist_ndx_item *head, *tail;
336+ volatile struct flist_ndx_item *head, *tail;
337+ pthread_mutex_t mutex;
338 };
339
340-static struct flist_ndx_list redo_list, hlink_list;
341+static struct flist_ndx_list redo_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
342+static struct flist_ndx_list hlink_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
343
344 struct msg_list_item {
345- struct msg_list_item *next;
346+ volatile struct msg_list_item *next;
3ca259e2
WD
347 int len;
348+ enum msgcode code;
3a748b26 349 char buf[1];
3ca259e2
WD
350 };
351
352 struct msg_list {
353- struct msg_list_item *head, *tail;
354+ volatile struct msg_list_item *head, *tail;
355+ pthread_mutex_t mutex;
356 };
357
3a748b26 358-static struct msg_list msg2genr, msg2sndr;
3ca259e2
WD
359+static struct msg_list msg_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
360
361 static void flist_ndx_push(struct flist_ndx_list *lp, int ndx)
362 {
3a748b26 363@@ -140,27 +139,31 @@ static void flist_ndx_push(struct flist_
3ca259e2
WD
364 out_of_memory("flist_ndx_push");
365 item->next = NULL;
366 item->ndx = ndx;
367+ pthread_mutex_lock(&redo_list.mutex);
368 if (lp->tail)
369 lp->tail->next = item;
370 else
371 lp->head = item;
372 lp->tail = item;
373+ pthread_mutex_unlock(&redo_list.mutex);
374 }
375
376 static int flist_ndx_pop(struct flist_ndx_list *lp)
377 {
378- struct flist_ndx_item *next;
379+ struct flist_ndx_item *head, *next;
380 int ndx;
381
382 if (!lp->head)
383 return -1;
384
385- ndx = lp->head->ndx;
386- next = lp->head->next;
387- free(lp->head);
388- lp->head = next;
389- if (!next)
390+ pthread_mutex_lock(&hlink_list.mutex);
391+ head = (struct flist_ndx_item *)lp->head;
392+ next = (struct flist_ndx_item *)head->next;
393+ ndx = head->ndx;
394+ if (!(lp->head = next))
395 lp->tail = NULL;
396+ pthread_mutex_unlock(&hlink_list.mutex);
397+ free(head);
398
399 return ndx;
400 }
3a748b26 401@@ -169,7 +172,7 @@ static void check_timeout(void)
3ca259e2
WD
402 {
403 time_t t;
404
405- if (!io_timeout || ignore_timeout)
406+ if (!io_timeout)
407 return;
408
409 if (!last_io_in) {
3a748b26 410@@ -210,44 +213,38 @@ void set_io_timeout(int secs)
3ca259e2
WD
411
412 /* Setup the fd used to receive MSG_* messages. Only needed during the
413 * early stages of being a local sender (up through the sending of the
414- * file list) or when we're the generator (to fetch the messages from
415- * the receiver). */
416+ * file list). */
417 void set_msg_fd_in(int fd)
418 {
419 msg_fd_in = fd;
420 }
421
422-/* Setup the fd used to send our MSG_* messages. Only needed when
423- * we're the receiver (to send our messages to the generator). */
424-void set_msg_fd_out(int fd)
425-{
426- msg_fd_out = fd;
427- set_nonblocking(msg_fd_out);
428-}
429-
430 /* Add a message to the pending MSG_* list. */
3a748b26
WD
431-static void msg_list_add(struct msg_list *lst, int code, char *buf, int len)
432+static void msg_list_add(int code, char *buf, int len)
3ca259e2 433 {
3a748b26
WD
434 struct msg_list_item *m;
435- int sz = len + 4 + sizeof m[0] - 1;
436+ int sz = len + sizeof m[0] - 1;
3ca259e2
WD
437
438+ assert(am_receiver());
3a748b26 439 if (!(m = (struct msg_list_item *)new_array(char, sz)))
3ca259e2 440 out_of_memory("msg_list_add");
3a748b26
WD
441 m->next = NULL;
442- m->len = len + 4;
443- SIVAL(m->buf, 0, ((code+MPLEX_BASE)<<24) | len);
444- memcpy(m->buf + 4, buf, len);
445- if (lst->tail)
446- lst->tail->next = m;
447+ m->len = len;
448+ m->code = code;
449+ memcpy(m->buf, buf, len);
3ca259e2
WD
450+
451+ pthread_mutex_lock(&msg_list.mutex);
3a748b26
WD
452+ if (msg_list.tail)
453+ msg_list.tail->next = m;
3ca259e2 454 else
3a748b26
WD
455- lst->head = m;
456- lst->tail = m;
457+ msg_list.head = m;
458+ msg_list.tail = m;
3ca259e2
WD
459+ pthread_mutex_unlock(&msg_list.mutex);
460 }
461
462-/* Read a message from the MSG_* fd and handle it. This is called either
463+/* Read a message from the MSG_* fd and handle it. This is only called
464 * during the early stages of being a local sender (up through the sending
465- * of the file list) or when we're the generator (to fetch the messages
466- * from the receiver). */
467+ * of the file list). */
468 static void read_msg_fd(void)
469 {
470 char buf[2048];
3a748b26 471@@ -266,57 +263,6 @@ static void read_msg_fd(void)
3ca259e2
WD
472 tag = (tag >> 24) - MPLEX_BASE;
473
474 switch (tag) {
475- case MSG_DONE:
476- if (len != 0 || !am_generator) {
477- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
478- exit_cleanup(RERR_STREAMIO);
479- }
480- flist_ndx_push(&redo_list, -1);
481- break;
482- case MSG_REDO:
483- if (len != 4 || !am_generator) {
484- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
485- exit_cleanup(RERR_STREAMIO);
486- }
487- read_loop(fd, buf, 4);
fb0b1cab
WD
488- if (remove_sent_files)
489- decrement_active_files(IVAL(buf,0));
3ca259e2
WD
490- flist_ndx_push(&redo_list, IVAL(buf,0));
491- break;
492- case MSG_DELETED:
493- if (len >= (int)sizeof buf || !am_generator) {
494- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
495- exit_cleanup(RERR_STREAMIO);
496- }
497- read_loop(fd, buf, len);
3a748b26
WD
498- if (defer_forwarding_messages)
499- msg_list_add(&msg2sndr, MSG_DELETED, buf, len);
500- else
501- io_multiplex_write(MSG_DELETED, buf, len);
3ca259e2
WD
502- break;
503- case MSG_SUCCESS:
504- if (len != 4 || !am_generator) {
505- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
506- exit_cleanup(RERR_STREAMIO);
507- }
508- read_loop(fd, buf, len);
fb0b1cab
WD
509- if (remove_sent_files) {
510- decrement_active_files(IVAL(buf,0));
3a748b26
WD
511- if (defer_forwarding_messages)
512- msg_list_add(&msg2sndr, MSG_SUCCESS, buf, len);
513- else
514- io_multiplex_write(MSG_SUCCESS, buf, len);
fb0b1cab 515- }
3ca259e2
WD
516- if (preserve_hard_links)
517- flist_ndx_push(&hlink_list, IVAL(buf,0));
518- break;
e89d5d9a
WD
519- case MSG_SOCKERR:
520- if (!am_generator) {
521- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
522- exit_cleanup(RERR_STREAMIO);
523- }
524- close_multiplexing_out();
525- /* FALL THROUGH */
3ca259e2
WD
526 case MSG_INFO:
527 case MSG_ERROR:
528 case MSG_LOG:
3a748b26
WD
529@@ -325,10 +271,7 @@ static void read_msg_fd(void)
530 if (n >= sizeof buf)
531 n = sizeof buf - 1;
532 read_loop(fd, buf, n);
533- if (am_generator && am_server && defer_forwarding_messages)
534- msg_list_add(&msg2sndr, tag, buf, n);
535- else
536- rwrite((enum logcode)tag, buf, n);
537+ rwrite((enum logcode)tag, buf, n);
538 len -= n;
539 }
540 break;
541@@ -362,70 +305,74 @@ void decrement_active_files(int ndx)
fb0b1cab 542 active_bytecnt -= the_file_list->files[ndx]->length;
3ca259e2
WD
543 }
544
545-/* Try to push messages off the list onto the wire. If we leave with more
546+/* Try to pop messages off the list onto the wire. If we leave with more
547 * to do, return 0. On error, return -1. If everything flushed, return 1.
548- * This is only active in the receiver. */
3a748b26 549-static int msg2genr_flush(int flush_it_all)
3ca259e2 550+ * This is only called by the generator. */
3a748b26 551+static int msg_list_flush(int flush_it_all)
3ca259e2
WD
552 {
553- static int written = 0;
554- struct timeval tv;
555- fd_set fds;
556-
557- if (msg_fd_out < 0)
558- return -1;
559-
3a748b26
WD
560- while (msg2genr.head) {
561- struct msg_list_item *m = msg2genr.head;
562- int n = write(msg_fd_out, m->buf + written, m->len - written);
3ca259e2
WD
563- if (n < 0) {
564- if (errno == EINTR)
565- continue;
566- if (errno != EWOULDBLOCK && errno != EAGAIN)
567- return -1;
568- if (!flush_it_all)
569- return 0;
570- FD_ZERO(&fds);
571- FD_SET(msg_fd_out, &fds);
572- tv.tv_sec = select_timeout;
573- tv.tv_usec = 0;
574- if (!select(msg_fd_out+1, NULL, &fds, NULL, &tv))
575- check_timeout();
3a748b26
WD
576- } else if ((written += n) == m->len) {
577- msg2genr.head = m->next;
578- if (!msg2genr.head)
579- msg2genr.tail = NULL;
580- free(m);
3ca259e2 581- written = 0;
3a748b26
WD
582+ assert(am_generator());
583+ no_flush++;
584+ while (msg_list.head) {
585+ struct msg_list_item *m = (struct msg_list_item *)msg_list.head;
586+ switch (m->code) {
e89d5d9a
WD
587+ case MSG_SOCKERR:
588+ close_multiplexing_out();
589+ /* FALL THROUGH */
3ca259e2
WD
590+ case MSG_INFO:
591+ case MSG_ERROR:
592+ case MSG_LOG:
3a748b26 593+ rwrite(m->code, m->buf, m->len);
3ca259e2
WD
594+ break;
595+ default:
3a748b26 596+ io_multiplex_write(m->code, m->buf, m->len);
3ca259e2
WD
597+ break;
598 }
599+ pthread_mutex_lock(&msg_list.mutex);
3a748b26 600+ if (!(msg_list.head = m->next))
3ca259e2
WD
601+ msg_list.tail = NULL;
602+ pthread_mutex_unlock(&msg_list.mutex);
3a748b26 603+ free(m);
3ca259e2
WD
604+ if (!flush_it_all)
605+ break;
606 }
607+ no_flush--;
608+
609 return 1;
610 }
611
612 void send_msg(enum msgcode code, char *buf, int len)
613 {
614- if (msg_fd_out < 0) {
615+ if (am_receiver())
616+ msg_list_add(code, buf, len);
617+ else
618 io_multiplex_write(code, buf, len);
619- return;
620- }
3a748b26
WD
621- msg_list_add(&msg2genr, code, buf, len);
622- msg2genr_flush(NORMAL_FLUSH);
3ca259e2
WD
623 }
624
625-int get_redo_num(int itemizing, enum logcode code)
626+/* This is only used by the receiver. */
627+void push_redo_num(int ndx)
628 {
629- while (1) {
630- if (hlink_list.head)
631- check_for_finished_hlinks(itemizing, code);
632- if (redo_list.head)
633- break;
634- read_msg_fd();
635- }
636+ assert(am_receiver());
637+ flist_ndx_push(&redo_list, ndx);
638+}
639
640+/* This is only used by the generator. */
641+int get_redo_num(void)
642+{
643+ assert(am_generator());
644 return flist_ndx_pop(&redo_list);
645 }
646
647+/* This is only used by the receiver. */
648+void push_hlink_num(int ndx)
649+{
650+ assert(am_receiver());
651+ flist_ndx_push(&hlink_list, ndx);
652+}
653+
654+/* This is only used by the generator. */
655 int get_hlink_num(void)
656 {
657+ assert(am_generator());
658 return flist_ndx_pop(&hlink_list);
659 }
660
3a748b26 661@@ -505,11 +452,6 @@ static int read_timeout(int fd, char *bu
3ca259e2
WD
662 FD_ZERO(&r_fds);
663 FD_ZERO(&w_fds);
664 FD_SET(fd, &r_fds);
3a748b26 665- if (msg2genr.head) {
3ca259e2
WD
666- FD_SET(msg_fd_out, &w_fds);
667- if (msg_fd_out > maxfd)
668- maxfd = msg_fd_out;
669- }
670 if (io_filesfrom_f_out >= 0) {
671 int new_fd;
672 if (io_filesfrom_buflen == 0) {
3a748b26 673@@ -542,9 +484,6 @@ static int read_timeout(int fd, char *bu
3ca259e2
WD
674 continue;
675 }
676
3a748b26
WD
677- if (msg2genr.head && FD_ISSET(msg_fd_out, &w_fds))
678- msg2genr_flush(NORMAL_FLUSH);
3ca259e2
WD
679-
680 if (io_filesfrom_f_out >= 0) {
681 if (io_filesfrom_buflen) {
682 if (FD_ISSET(io_filesfrom_f_out, &w_fds)) {
3a748b26 683@@ -866,6 +805,8 @@ static void readfd(int fd, char *buffer,
3ca259e2
WD
684 }
685
686 if (fd == write_batch_monitor_in) {
687+ if (am_generator())
688+ rprintf(FINFO, "writing %d bytes to batch file from generator\n", total);
689 if ((size_t)write(batch_fd, buffer, total) != total)
690 exit_cleanup(RERR_FILEIO);
691 }
3a748b26
WD
692@@ -1101,18 +1042,6 @@ static void writefd_unbuffered(int fd,ch
693 if (!FD_ISSET(fd, &w_fds))
694 continue;
695
696- if (msg2sndr.head && !defer_forwarding_messages) {
697- struct msg_list_item *m = msg2sndr.head;
698- int code = *((uchar*)m->buf+3) - MPLEX_BASE;
699- if (!(msg2sndr.head = m->next))
700- msg2sndr.tail = NULL;
701- defer_forwarding_messages = 1;
702- io_multiplex_write(code, m->buf+4, m->len-4);
703- defer_forwarding_messages = 0;
704- free(m);
705- continue;
706- }
707-
708 n = len - total;
709 if (bwlimit_writemax && n > bwlimit_writemax)
710 n = bwlimit_writemax;
711@@ -1138,7 +1067,6 @@ static void writefd_unbuffered(int fd,ch
3ca259e2
WD
712 * to grab any messages they sent before they died. */
713 while (fd == sock_f_out && io_multiplexing_in) {
714 set_io_timeout(30);
715- ignore_timeout = 0;
716 readfd_unbuffered(sock_f_in, io_filesfrom_buf,
717 sizeof io_filesfrom_buf);
718 }
3a748b26
WD
719@@ -1146,15 +1074,13 @@ static void writefd_unbuffered(int fd,ch
720 }
721
e89d5d9a 722 total += cnt;
3a748b26 723- defer_forwarding_messages = 1;
3ca259e2
WD
724
725 if (fd == sock_f_out) {
726- if (io_timeout || am_generator)
727+ if (io_timeout || am_generator())
728 last_io_out = time(NULL);
e89d5d9a 729 sleep_for_bwlimit(cnt);
3ca259e2 730 }
3a748b26
WD
731 }
732- defer_forwarding_messages = 0;
733
734 no_flush--;
3ca259e2 735 }
3a748b26 736@@ -1186,25 +1112,23 @@ static void mplex_write(enum msgcode cod
3ca259e2 737
3ca259e2
WD
738 void io_flush(int flush_it_all)
739 {
3a748b26 740- msg2genr_flush(flush_it_all);
3ca259e2
WD
741-
742- if (!iobuf_out_cnt || no_flush)
743+ if (no_flush)
744 return;
745
746- if (io_multiplexing_out)
747- mplex_write(MSG_DATA, iobuf_out, iobuf_out_cnt);
748- else
749- writefd_unbuffered(sock_f_out, iobuf_out, iobuf_out_cnt);
750- iobuf_out_cnt = 0;
751+ if (iobuf_out_cnt) {
752+ if (io_multiplexing_out)
753+ mplex_write(MSG_DATA, iobuf_out, iobuf_out_cnt);
754+ else
755+ writefd_unbuffered(sock_f_out, iobuf_out, iobuf_out_cnt);
756+ iobuf_out_cnt = 0;
757+ }
758+
759+ if (am_generator())
760+ msg_list_flush(flush_it_all);
761 }
762
3ca259e2
WD
763 static void writefd(int fd,char *buf,size_t len)
764 {
765- if (fd == msg_fd_out) {
766- rprintf(FERROR, "Internal error: wrong write used in receiver.\n");
767- exit_cleanup(RERR_PROTOCOL);
768- }
769-
770 if (fd == sock_f_out)
771 stats.total_written += len;
772
3a748b26 773@@ -1417,9 +1341,3 @@ void start_write_batch(int fd)
3ca259e2
WD
774 else
775 write_batch_monitor_in = fd;
776 }
777-
778-void stop_write_batch(void)
779-{
780- write_batch_monitor_out = -1;
781- write_batch_monitor_in = -1;
782-}
9a7eef96
WD
783--- old/log.c
784+++ new/log.c
8857e5dd 785@@ -38,7 +38,6 @@ extern int am_sender;
3ca259e2
WD
786 extern int local_server;
787 extern int quiet;
788 extern int module_id;
789-extern int msg_fd_out;
577db5e2 790 extern int allow_8bit_chars;
3ca259e2
WD
791 extern int protocol_version;
792 extern int preserve_times;
d42637db 793@@ -76,7 +75,6 @@ struct {
3ca259e2
WD
794 { RERR_IPC , "error in IPC code" },
795 { RERR_CRASHED , "sibling process crashed" },
796 { RERR_TERMINATED , "sibling process terminated abnormally" },
8a0123e5
WD
797- { RERR_SIGNAL1 , "received SIGUSR1" },
798 { RERR_SIGNAL , "received SIGINT, SIGTERM, or SIGHUP" },
3ca259e2
WD
799 { RERR_WAITCHILD , "waitpid() failed" },
800 { RERR_MALLOC , "error allocating core memory buffers" },
577db5e2 801@@ -232,8 +230,8 @@ void rwrite(enum logcode code, char *buf
e89d5d9a
WD
802 if (quiet && code == FINFO)
803 return;
3ca259e2
WD
804
805- if (am_server && msg_fd_out >= 0) {
806- /* Pass the message to our sibling. */
807+ if (am_receiver()) {
808+ /* Pass the message to the generator thread. */
809 send_msg((enum msgcode)code, buf, len);
810 return;
811 }
9a7eef96
WD
812--- old/main.c
813+++ new/main.c
3ca259e2
WD
814@@ -30,7 +30,6 @@ extern int list_only;
815 extern int am_root;
816 extern int am_server;
817 extern int am_sender;
818-extern int am_generator;
819 extern int am_daemon;
820 extern int blocking_io;
821 extern int remove_sent_files;
d42637db 822@@ -85,9 +84,20 @@ struct pid_status {
3ca259e2
WD
823
824 static time_t starttime, endtime;
825 static int64 total_read, total_written;
826+static pthread_t receiver_tid;
827
828 static void show_malloc_stats(void);
829
830+int am_generator()
831+{
832+ return receiver_tid != 0 && pthread_self() != receiver_tid;
833+}
834+
835+int am_receiver()
836+{
837+ return receiver_tid != 0 && pthread_self() == receiver_tid;
838+}
839+
840 /* Works like waitpid(), but if we already harvested the child pid in our
c769ea2c 841 * remember_children(), we succeed instead of returning an error. */
3ca259e2 842 pid_t wait_process(pid_t pid, int *status_ptr, int flags)
d42637db 843@@ -164,7 +174,7 @@ static void handle_stats(int f)
3ca259e2
WD
844 show_flist_stats();
845 }
846
847- if (am_generator)
848+ if (am_generator())
849 return;
850
851 if (am_daemon) {
3809b131 852@@ -628,12 +638,30 @@ static void do_server_sender(int f_in, i
3ca259e2
WD
853 exit_cleanup(0);
854 }
855
856+struct thread_args {
857+ struct file_list *flist;
858+ char *local_name;
859+ int f_in;
860+};
861+
862+static void *start_receiver_thread(void *arg)
863+{
864+ static int exit_code;
865+ struct thread_args *ta = (struct thread_args *)arg;
866+
867+ recv_files(ta->f_in, ta->flist, ta->local_name);
868+ handle_stats(ta->f_in);
869+
870+ push_redo_num(-2);
871+
872+ exit_code = log_got_error ? RERR_PARTIAL : 0;
873+ return &exit_code;
874+}
875
876 static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
877 {
878- int pid;
879- int exit_code = 0;
880- int error_pipe[2];
881+ void *value_ptr;
882+ struct thread_args args;
883
884 /* The receiving side mustn't obey this, or an existing symlink that
885 * points to an identical file won't be replaced by the referent. */
3809b131 886@@ -642,70 +670,16 @@ static int do_recv(int f_in,int f_out,st
3ca259e2
WD
887 if (preserve_hard_links)
888 init_hard_links();
889
890- if (fd_pair(error_pipe) < 0) {
891- rsyserr(FERROR, errno, "pipe failed in do_recv");
892+ args.f_in = f_in;
893+ args.flist = flist;
894+ args.local_name = local_name;
895+ if (pthread_create(&receiver_tid, NULL, start_receiver_thread, &args) < 0) {
896+ rsyserr(FERROR, errno, "pthread_create failed in do_recv");
897 exit_cleanup(RERR_IPC);
898 }
899
900- io_flush(NORMAL_FLUSH);
901-
902- if ((pid = do_fork()) == -1) {
903- rsyserr(FERROR, errno, "fork failed in do_recv");
904- exit_cleanup(RERR_IPC);
905- }
906-
907- if (pid == 0) {
908- close(error_pipe[0]);
909- if (f_in != f_out)
910- close(f_out);
911-
912- /* we can't let two processes write to the socket at one time */
913- close_multiplexing_out();
914-
915- /* set place to send errors */
916- set_msg_fd_out(error_pipe[1]);
917-
918- recv_files(f_in, flist, local_name);
919- io_flush(FULL_FLUSH);
920- handle_stats(f_in);
921-
922- send_msg(MSG_DONE, "", 0);
923- io_flush(FULL_FLUSH);
924-
925- /* Handle any keep-alive packets from the post-processing work
926- * that the generator does. */
927- if (protocol_version >= 29) {
928- kluge_around_eof = -1;
929-
930- /* This should only get stopped via a USR2 signal. */
931- while (read_int(f_in) == flist->count
932- && read_shortint(f_in) == ITEM_IS_NEW) {}
933-
934- rprintf(FERROR, "Invalid packet at end of run [%s]\n",
935- who_am_i());
936- exit_cleanup(RERR_PROTOCOL);
937- }
938-
939- /* Finally, we go to sleep until our parent kills us with a
940- * USR2 signal. We sleep for a short time, as on some OSes
941- * a signal won't interrupt a sleep! */
942- while (1)
943- msleep(20);
944- }
945-
946- am_generator = 1;
947- close_multiplexing_in();
948- if (write_batch && !am_server)
949- stop_write_batch();
950-
951- close(error_pipe[1]);
952- if (f_in != f_out)
953- close(f_in);
954-
955 io_start_buffering_out();
956
957- set_msg_fd_in(error_pipe[0]);
958-
959 generate_files(f_out, flist, local_name);
960
961 handle_stats(-1);
3809b131 962@@ -716,10 +690,13 @@ static int do_recv(int f_in,int f_out,st
3ca259e2
WD
963 }
964 io_flush(FULL_FLUSH);
965
966- set_msg_fd_in(-1);
967- kill(pid, SIGUSR2);
968- wait_process_with_flush(pid, &exit_code);
969- return exit_code;
970+ pthread_join(receiver_tid, &value_ptr);
971+ if (!am_server)
972+ output_summary();
973+
974+ close_all();
975+
976+ return *(int*)value_ptr;
977 }
978
979
3809b131 980@@ -1089,22 +1066,6 @@ static int start_client(int argc, char *
3ca259e2
WD
981 return ret;
982 }
983
984-
985-static RETSIGTYPE sigusr1_handler(UNUSED(int val))
986-{
8a0123e5 987- exit_cleanup(RERR_SIGNAL1);
3ca259e2
WD
988-}
989-
990-static RETSIGTYPE sigusr2_handler(UNUSED(int val))
991-{
992- if (!am_server)
993- output_summary();
994- close_all();
995- if (log_got_error)
996- _exit(RERR_PARTIAL);
997- _exit(0);
998-}
999-
c769ea2c 1000 RETSIGTYPE remember_children(UNUSED(int val))
3ca259e2
WD
1001 {
1002 #ifdef WNOHANG
3809b131 1003@@ -1196,8 +1157,6 @@ int main(int argc,char *argv[])
8857e5dd 1004 # endif
bc5988ec
WD
1005 sigact.sa_flags = SA_NOCLDSTOP;
1006 #endif
1007- SIGACTMASK(SIGUSR1, sigusr1_handler);
1008- SIGACTMASK(SIGUSR2, sigusr2_handler);
c769ea2c 1009 SIGACTMASK(SIGCHLD, remember_children);
3ca259e2 1010 #ifdef MAINTAINER_MODE
bc5988ec 1011 SIGACTMASK(SIGSEGV, rsync_panic_handler);
9a7eef96
WD
1012--- old/match.c
1013+++ new/match.c
d42637db
WD
1014@@ -20,7 +20,7 @@
1015 #include "rsync.h"
3ca259e2
WD
1016
1017 extern int verbose;
3ca259e2
WD
1018-extern int do_progress;
1019+extern int recv_progress;
1020 extern int checksum_seed;
1021 extern int append_mode;
1022
3809b131 1023@@ -110,7 +110,7 @@ static void matched(int f, struct sum_st
3ca259e2
WD
1024 else
1025 last_match = offset;
1026
1027- if (buf && do_progress)
1028+ if (buf && recv_progress)
1029 show_progress(last_match, buf->file_size);
1030 }
1031
3809b131 1032@@ -314,7 +314,7 @@ void match_sums(int f, struct sum_struct
3ca259e2
WD
1033 if (append_mode) {
1034 OFF_T j = 0;
1035 for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) {
1036- if (buf && do_progress)
1037+ if (buf && recv_progress)
1038 show_progress(last_match, buf->file_size);
1039 sum_update(map_ptr(buf, last_match, CHUNK_SIZE),
1040 CHUNK_SIZE);
3809b131 1041@@ -322,7 +322,7 @@ void match_sums(int f, struct sum_struct
3ca259e2
WD
1042 }
1043 if (last_match < s->flength) {
1044 int32 len = s->flength - last_match;
1045- if (buf && do_progress)
1046+ if (buf && recv_progress)
1047 show_progress(last_match, buf->file_size);
1048 sum_update(map_ptr(buf, last_match, len), len);
1049 last_match = s->flength;
9a7eef96
WD
1050--- old/options.c
1051+++ new/options.c
d42637db 1052@@ -74,7 +74,6 @@ int def_compress_level = Z_DEFAULT_COMPR
3ca259e2
WD
1053 int am_root = 0;
1054 int am_server = 0;
1055 int am_sender = 0;
1056-int am_generator = 0;
1057 int am_starting_up = 1;
3ca259e2 1058 int relative_paths = -1;
d42637db 1059 int implied_dirs = 1;
577db5e2 1060@@ -95,6 +94,7 @@ int am_daemon = 0;
3ca259e2
WD
1061 int daemon_over_rsh = 0;
1062 int do_stats = 0;
1063 int do_progress = 0;
1064+int recv_progress = 0;
1065 int keep_partial = 0;
1066 int safe_symlinks = 0;
1067 int copy_unsafe_links = 0;
3809b131 1068@@ -1301,6 +1301,7 @@ int parse_arguments(int *argc, const cha
afcb578c
WD
1069
1070 if (do_progress && !verbose && !log_before_transfer && !am_server)
3ca259e2
WD
1071 verbose = 1;
1072+ recv_progress = do_progress;
1073
1074 if (dry_run)
1075 do_xfers = 0;
9a7eef96
WD
1076--- old/pipe.c
1077+++ new/pipe.c
4a65fe72 1078@@ -56,7 +56,7 @@ pid_t piped_child(char **command, int *f
3ca259e2
WD
1079 exit_cleanup(RERR_IPC);
1080 }
1081
1082- pid = do_fork();
1083+ pid = fork();
1084 if (pid == -1) {
1085 rsyserr(FERROR, errno, "fork");
1086 exit_cleanup(RERR_IPC);
4a65fe72 1087@@ -120,7 +120,7 @@ pid_t local_child(int argc, char **argv,
3ca259e2
WD
1088 exit_cleanup(RERR_IPC);
1089 }
1090
1091- pid = do_fork();
1092+ pid = fork();
1093 if (pid == -1) {
1094 rsyserr(FERROR, errno, "fork");
1095 exit_cleanup(RERR_IPC);
9a7eef96
WD
1096--- old/receiver.c
1097+++ new/receiver.c
3ca259e2
WD
1098@@ -24,7 +24,7 @@ extern int verbose;
1099 extern int do_xfers;
1100 extern int am_daemon;
1101 extern int am_server;
1102-extern int do_progress;
1103+extern int recv_progress;
1104 extern int log_before_transfer;
1105 extern int log_format_has_i;
1106 extern int daemon_log_format_has_i;
d42637db 1107@@ -153,7 +153,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1108 if (sum.remainder)
1109 sum.flength -= sum.blength - sum.remainder;
1110 for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) {
1111- if (do_progress)
1112+ if (recv_progress)
1113 show_progress(offset, total_size);
1114 sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE),
1115 CHUNK_SIZE);
d42637db 1116@@ -161,7 +161,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1117 }
1118 if (offset < sum.flength) {
1119 int32 len = sum.flength - offset;
1120- if (do_progress)
1121+ if (recv_progress)
1122 show_progress(offset, total_size);
1123 sum_update(map_ptr(mapbuf, offset, len), len);
1124 offset = sum.flength;
d42637db 1125@@ -174,7 +174,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1126 }
1127
1128 while ((i = recv_token(f_in, &data)) != 0) {
1129- if (do_progress)
1130+ if (recv_progress)
1131 show_progress(offset, total_size);
1132
1133 if (i > 0) {
d42637db 1134@@ -242,7 +242,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1135 ftruncate(fd, offset);
1136 #endif
1137
1138- if (do_progress)
1139+ if (recv_progress)
1140 end_progress(total_size);
1141
1142 if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
d42637db 1143@@ -293,12 +293,12 @@ static void handle_delayed_updates(struc
93ca4d27
WD
1144 "rename failed for %s (from %s)",
1145 full_fname(fname), partialptr);
3ca259e2
WD
1146 } else {
1147- if (remove_sent_files
1148- || (preserve_hard_links
1149- && file->link_u.links)) {
1150+ if (remove_sent_files) {
1151 SIVAL(numbuf, 0, i);
1152 send_msg(MSG_SUCCESS,numbuf,4);
1153 }
3ca259e2
WD
1154+ if (preserve_hard_links && file->link_u.links)
1155+ push_hlink_num(i);
93ca4d27 1156 handle_partial_dir(partialptr, PDIR_DELETE);
3ca259e2
WD
1157 }
1158 }
d42637db 1159@@ -349,11 +349,6 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1160 if (verbose > 2)
1161 rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
1162
1163- if (flist->hlink_pool) {
1164- pool_destroy(flist->hlink_pool);
1165- flist->hlink_pool = NULL;
1166- }
1167-
1168 if (delay_updates)
577db5e2 1169 delayed_bits = bitbag_create(flist->count);
3ca259e2 1170
d42637db 1171@@ -374,7 +369,7 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1172 rprintf(FINFO, "recv_files phase=%d\n", phase);
1173 if (phase == 2 && delay_updates)
1174 handle_delayed_updates(flist, local_name);
1175- send_msg(MSG_DONE, "", 0);
1176+ push_redo_num(-2);
1177 if (keep_partial && !partial_dir)
1178 make_backups = 0; /* prevents double backup */
1179 if (append_mode) {
d42637db 1180@@ -596,7 +591,7 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1181 /* log the transfer */
1182 if (log_before_transfer)
1183 log_item(file, &initial_stats, iflags, NULL);
1184- else if (!am_server && verbose && do_progress)
1185+ else if (!am_server && verbose && recv_progress)
93ca4d27 1186 rprintf(FINFO, "%s\n", fname);
3ca259e2
WD
1187
1188 /* recv file data */
d42637db 1189@@ -639,11 +634,13 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1190 cleanup_disable();
1191
1192 if (recv_ok > 0) {
1193- if (remove_sent_files
1194- || (preserve_hard_links && file->link_u.links)) {
1195+ if (remove_sent_files) {
fb0b1cab 1196+ decrement_active_files(i);
3ca259e2
WD
1197 SIVAL(numbuf, 0, i);
1198 send_msg(MSG_SUCCESS, numbuf, 4);
1199 }
1200+ if (preserve_hard_links && file->link_u.links)
1201+ push_hlink_num(i);
1202 } else if (!recv_ok) {
1203 int msgtype = phase || read_batch ? FERROR : FINFO;
1204 if (msgtype == FERROR || verbose) {
d42637db 1205@@ -666,8 +663,8 @@ int recv_files(int f_in, struct file_lis
93ca4d27 1206 errstr, fname, keptstr, redostr);
3ca259e2 1207 }
fb0b1cab 1208 if (!phase) {
3ca259e2
WD
1209- SIVAL(numbuf, 0, i);
1210- send_msg(MSG_REDO, numbuf, 4);
fb0b1cab 1211+ decrement_active_files(i);
3ca259e2 1212+ push_redo_num(i);
fb0b1cab 1213 }
3ca259e2
WD
1214 }
1215 }
9a7eef96
WD
1216--- old/rsync.c
1217+++ new/rsync.c
d42637db 1218@@ -40,7 +40,6 @@ extern int omit_dir_times;
3ca259e2
WD
1219 extern int am_root;
1220 extern int am_server;
1221 extern int am_sender;
1222-extern int am_generator;
1223 extern int am_starting_up;
577db5e2 1224 extern int allow_8bit_chars;
3ca259e2 1225 extern int preserve_uid;
c769ea2c 1226@@ -303,5 +302,5 @@ const char *who_am_i(void)
3ca259e2
WD
1227 {
1228 if (am_starting_up)
1229 return am_server ? "server" : "client";
1230- return am_sender ? "sender" : am_generator ? "generator" : "receiver";
1231+ return am_sender ? "sender" : am_generator() ? "generator" : "receiver";
1232 }
9a7eef96
WD
1233--- old/rsync.h
1234+++ new/rsync.h
79d14d37 1235@@ -166,10 +166,8 @@ enum msgcode {
3ca259e2
WD
1236 MSG_DATA=0, /* raw data on the multiplexed stream */
1237 MSG_ERROR=FERROR, MSG_INFO=FINFO, /* remote logging */
e89d5d9a 1238 MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR, /* sibling logging */
3ca259e2
WD
1239- MSG_REDO=9, /* reprocess indicated flist index */
1240 MSG_SUCCESS=100,/* successfully updated indicated flist index */
1241 MSG_DELETED=101,/* successfully deleted a file on receiving side */
1242- MSG_DONE=86 /* current phase is done */
1243 };
1244
1245 #include "errcode.h"
79d14d37 1246@@ -320,6 +318,7 @@ enum msgcode {
3ca259e2
WD
1247 #endif
1248
1249 #include <assert.h>
1250+#include <pthread.h>
1251
1252 #include "lib/pool_alloc.h"
1253
9a7eef96
WD
1254--- old/util.c
1255+++ new/util.c
d42637db 1256@@ -420,49 +420,6 @@ int robust_rename(char *from, char *to,
3ca259e2
WD
1257 return -1;
1258 }
1259
3ca259e2
WD
1260-static pid_t all_pids[10];
1261-static int num_pids;
1262-
1263-/** Fork and record the pid of the child. **/
1264-pid_t do_fork(void)
1265-{
1266- pid_t newpid = fork();
1267-
1268- if (newpid != 0 && newpid != -1) {
1269- all_pids[num_pids++] = newpid;
1270- }
1271- return newpid;
1272-}
1273-
1274-/**
1275- * Kill all children.
1276- *
1277- * @todo It would be kind of nice to make sure that they are actually
1278- * all our children before we kill them, because their pids may have
1279- * been recycled by some other process. Perhaps when we wait for a
1280- * child, we should remove it from this array. Alternatively we could
1281- * perhaps use process groups, but I think that would not work on
1282- * ancient Unix versions that don't support them.
1283- **/
1284-void kill_all(int sig)
1285-{
1286- int i;
1287-
1288- for (i = 0; i < num_pids; i++) {
1289- /* Let's just be a little careful where we
1290- * point that gun, hey? See kill(2) for the
1291- * magic caused by negative values. */
1292- pid_t p = all_pids[i];
1293-
1294- if (p == getpid())
1295- continue;
1296- if (p <= 0)
1297- continue;
1298-
1299- kill(p, sig);
1300- }
1301-}
3ca259e2
WD
1302-
1303 /** Turn a user name into a uid */
1304 int name_to_uid(char *name, uid_t *uid)
1305 {