Moved the generic list-growing function into util.c so that the
[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
7cf8a551 40@@ -28,10 +28,6 @@ extern int keep_partial;
bc5988ec
WD
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
7cf8a551 51@@ -100,9 +96,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);
7cf8a551 61@@ -134,8 +127,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;
7cf8a551
WD
90@@ -95,6 +94,11 @@ extern struct filter_list_struct server_
91
92 static int deletion_count = 0; /* used to implement --max-delete */
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)
7cf8a551 102@@ -443,8 +447,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;
7cf8a551 113@@ -454,7 +458,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
7cf8a551 122@@ -488,7 +492,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)
7cf8a551 131@@ -507,7 +511,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
7cf8a551 140@@ -1175,7 +1179,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)
7cf8a551 149@@ -1230,7 +1234,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;
7cf8a551 158@@ -1321,9 +1325,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 171 maybe_ATTRS_REPORT = log_format_has_i ? 0 : ATTRS_REPORT;
7cf8a551 172@@ -1351,7 +1358,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",
7cf8a551 181@@ -1360,12 +1367,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
7cf8a551 194@@ -1409,23 +1410,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
7cf8a551 235@@ -1437,27 +1449,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
7cf8a551 288@@ -40,20 +40,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
7cf8a551 309@@ -61,7 +58,6 @@ int batch_gen_fd = -1;
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
7cf8a551 317@@ -88,27 +84,31 @@ static OFF_T active_bytecnt = 0;
3ca259e2
WD
318 static void read_loop(int fd, char *buf, size_t len);
319
320 struct flist_ndx_item {
321- struct flist_ndx_item *next;
322+ volatile struct flist_ndx_item *next;
323 int ndx;
324 };
325
326 struct flist_ndx_list {
327- struct flist_ndx_item *head, *tail;
328+ volatile struct flist_ndx_item *head, *tail;
329+ pthread_mutex_t mutex;
330 };
331
332-static struct flist_ndx_list redo_list, hlink_list;
333+static struct flist_ndx_list redo_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
334+static struct flist_ndx_list hlink_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
335
336 struct msg_list_item {
337- struct msg_list_item *next;
338+ volatile struct msg_list_item *next;
3ca259e2
WD
339 int len;
340+ enum msgcode code;
3a748b26 341 char buf[1];
3ca259e2
WD
342 };
343
344 struct msg_list {
345- struct msg_list_item *head, *tail;
346+ volatile struct msg_list_item *head, *tail;
347+ pthread_mutex_t mutex;
348 };
349
3a748b26 350-static struct msg_list msg2genr, msg2sndr;
3ca259e2
WD
351+static struct msg_list msg_list = { NULL, NULL, PTHREAD_MUTEX_INITIALIZER };
352
353 static void flist_ndx_push(struct flist_ndx_list *lp, int ndx)
354 {
7cf8a551 355@@ -118,27 +118,31 @@ static void flist_ndx_push(struct flist_
3ca259e2
WD
356 out_of_memory("flist_ndx_push");
357 item->next = NULL;
358 item->ndx = ndx;
359+ pthread_mutex_lock(&redo_list.mutex);
360 if (lp->tail)
361 lp->tail->next = item;
362 else
363 lp->head = item;
364 lp->tail = item;
365+ pthread_mutex_unlock(&redo_list.mutex);
366 }
367
368 static int flist_ndx_pop(struct flist_ndx_list *lp)
369 {
370- struct flist_ndx_item *next;
371+ struct flist_ndx_item *head, *next;
372 int ndx;
373
374 if (!lp->head)
375 return -1;
376
377- ndx = lp->head->ndx;
378- next = lp->head->next;
379- free(lp->head);
380- lp->head = next;
381- if (!next)
382+ pthread_mutex_lock(&hlink_list.mutex);
383+ head = (struct flist_ndx_item *)lp->head;
384+ next = (struct flist_ndx_item *)head->next;
385+ ndx = head->ndx;
386+ if (!(lp->head = next))
387 lp->tail = NULL;
388+ pthread_mutex_unlock(&hlink_list.mutex);
389+ free(head);
390
391 return ndx;
392 }
7cf8a551 393@@ -147,7 +151,7 @@ static void check_timeout(void)
3ca259e2
WD
394 {
395 time_t t;
396
397- if (!io_timeout || ignore_timeout)
398+ if (!io_timeout)
399 return;
400
401 if (!last_io_in) {
7cf8a551 402@@ -188,44 +192,38 @@ void set_io_timeout(int secs)
3ca259e2
WD
403
404 /* Setup the fd used to receive MSG_* messages. Only needed during the
405 * early stages of being a local sender (up through the sending of the
406- * file list) or when we're the generator (to fetch the messages from
407- * the receiver). */
408+ * file list). */
409 void set_msg_fd_in(int fd)
410 {
411 msg_fd_in = fd;
412 }
413
414-/* Setup the fd used to send our MSG_* messages. Only needed when
415- * we're the receiver (to send our messages to the generator). */
416-void set_msg_fd_out(int fd)
417-{
418- msg_fd_out = fd;
419- set_nonblocking(msg_fd_out);
420-}
421-
422 /* Add a message to the pending MSG_* list. */
3a748b26
WD
423-static void msg_list_add(struct msg_list *lst, int code, char *buf, int len)
424+static void msg_list_add(int code, char *buf, int len)
3ca259e2 425 {
3a748b26
WD
426 struct msg_list_item *m;
427- int sz = len + 4 + sizeof m[0] - 1;
428+ int sz = len + sizeof m[0] - 1;
3ca259e2
WD
429
430+ assert(am_receiver());
3a748b26 431 if (!(m = (struct msg_list_item *)new_array(char, sz)))
3ca259e2 432 out_of_memory("msg_list_add");
3a748b26
WD
433 m->next = NULL;
434- m->len = len + 4;
435- SIVAL(m->buf, 0, ((code+MPLEX_BASE)<<24) | len);
436- memcpy(m->buf + 4, buf, len);
437- if (lst->tail)
438- lst->tail->next = m;
439+ m->len = len;
440+ m->code = code;
441+ memcpy(m->buf, buf, len);
3ca259e2
WD
442+
443+ pthread_mutex_lock(&msg_list.mutex);
3a748b26
WD
444+ if (msg_list.tail)
445+ msg_list.tail->next = m;
3ca259e2 446 else
3a748b26
WD
447- lst->head = m;
448- lst->tail = m;
449+ msg_list.head = m;
450+ msg_list.tail = m;
3ca259e2
WD
451+ pthread_mutex_unlock(&msg_list.mutex);
452 }
453
454-/* Read a message from the MSG_* fd and handle it. This is called either
455+/* Read a message from the MSG_* fd and handle it. This is only called
456 * during the early stages of being a local sender (up through the sending
457- * of the file list) or when we're the generator (to fetch the messages
458- * from the receiver). */
459+ * of the file list). */
460 static void read_msg_fd(void)
461 {
462 char buf[2048];
7cf8a551 463@@ -244,57 +242,6 @@ static void read_msg_fd(void)
3ca259e2
WD
464 tag = (tag >> 24) - MPLEX_BASE;
465
466 switch (tag) {
467- case MSG_DONE:
468- if (len != 0 || !am_generator) {
469- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
470- exit_cleanup(RERR_STREAMIO);
471- }
472- flist_ndx_push(&redo_list, -1);
473- break;
474- case MSG_REDO:
475- if (len != 4 || !am_generator) {
476- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
477- exit_cleanup(RERR_STREAMIO);
478- }
479- read_loop(fd, buf, 4);
fb0b1cab
WD
480- if (remove_sent_files)
481- decrement_active_files(IVAL(buf,0));
3ca259e2
WD
482- flist_ndx_push(&redo_list, IVAL(buf,0));
483- break;
484- case MSG_DELETED:
485- if (len >= (int)sizeof buf || !am_generator) {
486- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
487- exit_cleanup(RERR_STREAMIO);
488- }
489- read_loop(fd, buf, len);
3a748b26
WD
490- if (defer_forwarding_messages)
491- msg_list_add(&msg2sndr, MSG_DELETED, buf, len);
492- else
493- io_multiplex_write(MSG_DELETED, buf, len);
3ca259e2
WD
494- break;
495- case MSG_SUCCESS:
496- if (len != 4 || !am_generator) {
497- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
498- exit_cleanup(RERR_STREAMIO);
499- }
500- read_loop(fd, buf, len);
fb0b1cab
WD
501- if (remove_sent_files) {
502- decrement_active_files(IVAL(buf,0));
3a748b26
WD
503- if (defer_forwarding_messages)
504- msg_list_add(&msg2sndr, MSG_SUCCESS, buf, len);
505- else
506- io_multiplex_write(MSG_SUCCESS, buf, len);
fb0b1cab 507- }
3ca259e2
WD
508- if (preserve_hard_links)
509- flist_ndx_push(&hlink_list, IVAL(buf,0));
510- break;
e89d5d9a
WD
511- case MSG_SOCKERR:
512- if (!am_generator) {
513- rprintf(FERROR, "invalid message %d:%d\n", tag, len);
514- exit_cleanup(RERR_STREAMIO);
515- }
516- close_multiplexing_out();
517- /* FALL THROUGH */
3ca259e2
WD
518 case MSG_INFO:
519 case MSG_ERROR:
520 case MSG_LOG:
7cf8a551 521@@ -303,10 +250,7 @@ static void read_msg_fd(void)
3a748b26
WD
522 if (n >= sizeof buf)
523 n = sizeof buf - 1;
524 read_loop(fd, buf, n);
525- if (am_generator && am_server && defer_forwarding_messages)
526- msg_list_add(&msg2sndr, tag, buf, n);
527- else
528- rwrite((enum logcode)tag, buf, n);
529+ rwrite((enum logcode)tag, buf, n);
530 len -= n;
531 }
532 break;
7cf8a551 533@@ -341,70 +285,76 @@ void decrement_active_files(int ndx)
fb0b1cab 534 active_bytecnt -= the_file_list->files[ndx]->length;
3ca259e2
WD
535 }
536
537-/* Try to push messages off the list onto the wire. If we leave with more
538+/* Try to pop messages off the list onto the wire. If we leave with more
539 * to do, return 0. On error, return -1. If everything flushed, return 1.
540- * This is only active in the receiver. */
3a748b26 541-static int msg2genr_flush(int flush_it_all)
3ca259e2 542+ * This is only called by the generator. */
b06103cc 543+static void msg_list_flush(void)
3ca259e2
WD
544 {
545- static int written = 0;
546- struct timeval tv;
547- fd_set fds;
b06103cc
WD
548+ assert(am_generator());
549
3ca259e2
WD
550- if (msg_fd_out < 0)
551- return -1;
b06103cc
WD
552+ if (defer_forwarding_messages)
553+ return;
554
3a748b26
WD
555- while (msg2genr.head) {
556- struct msg_list_item *m = msg2genr.head;
557- int n = write(msg_fd_out, m->buf + written, m->len - written);
3ca259e2
WD
558- if (n < 0) {
559- if (errno == EINTR)
560- continue;
561- if (errno != EWOULDBLOCK && errno != EAGAIN)
562- return -1;
563- if (!flush_it_all)
564- return 0;
565- FD_ZERO(&fds);
566- FD_SET(msg_fd_out, &fds);
567- tv.tv_sec = select_timeout;
568- tv.tv_usec = 0;
569- if (!select(msg_fd_out+1, NULL, &fds, NULL, &tv))
570- check_timeout();
3a748b26
WD
571- } else if ((written += n) == m->len) {
572- msg2genr.head = m->next;
573- if (!msg2genr.head)
574- msg2genr.tail = NULL;
575- free(m);
3ca259e2 576- written = 0;
3a748b26 577+ no_flush++;
b06103cc 578+ defer_forwarding_messages = 1;
3a748b26
WD
579+ while (msg_list.head) {
580+ struct msg_list_item *m = (struct msg_list_item *)msg_list.head;
b06103cc
WD
581+ pthread_mutex_lock(&msg_list.mutex);
582+ if (!(msg_list.head = m->next))
583+ msg_list.tail = NULL;
584+ pthread_mutex_unlock(&msg_list.mutex);
3a748b26 585+ switch (m->code) {
e89d5d9a
WD
586+ case MSG_SOCKERR:
587+ close_multiplexing_out();
588+ /* FALL THROUGH */
3ca259e2
WD
589+ case MSG_INFO:
590+ case MSG_ERROR:
591+ case MSG_LOG:
3a748b26 592+ rwrite(m->code, m->buf, m->len);
3ca259e2
WD
593+ break;
594+ default:
3a748b26 595+ io_multiplex_write(m->code, m->buf, m->len);
3ca259e2
WD
596+ break;
597 }
3a748b26 598+ free(m);
3ca259e2 599 }
b06103cc
WD
600- return 1;
601+ defer_forwarding_messages = 0;
3ca259e2 602+ no_flush--;
3ca259e2
WD
603 }
604
605 void send_msg(enum msgcode code, char *buf, int len)
606 {
607- if (msg_fd_out < 0) {
608+ if (am_receiver())
609+ msg_list_add(code, buf, len);
610+ else
611 io_multiplex_write(code, buf, len);
612- return;
613- }
3a748b26
WD
614- msg_list_add(&msg2genr, code, buf, len);
615- msg2genr_flush(NORMAL_FLUSH);
3ca259e2
WD
616 }
617
618-int get_redo_num(int itemizing, enum logcode code)
619+/* This is only used by the receiver. */
620+void push_redo_num(int ndx)
621 {
622- while (1) {
623- if (hlink_list.head)
624- check_for_finished_hlinks(itemizing, code);
625- if (redo_list.head)
626- break;
627- read_msg_fd();
628- }
629+ assert(am_receiver());
630+ flist_ndx_push(&redo_list, ndx);
631+}
632
633+/* This is only used by the generator. */
634+int get_redo_num(void)
635+{
636+ assert(am_generator());
637 return flist_ndx_pop(&redo_list);
638 }
639
640+/* This is only used by the receiver. */
641+void push_hlink_num(int ndx)
642+{
643+ assert(am_receiver());
644+ flist_ndx_push(&hlink_list, ndx);
645+}
646+
647+/* This is only used by the generator. */
648 int get_hlink_num(void)
649 {
650+ assert(am_generator());
651 return flist_ndx_pop(&hlink_list);
652 }
653
7cf8a551 654@@ -484,11 +434,6 @@ static int read_timeout(int fd, char *bu
3ca259e2
WD
655 FD_ZERO(&r_fds);
656 FD_ZERO(&w_fds);
657 FD_SET(fd, &r_fds);
3a748b26 658- if (msg2genr.head) {
3ca259e2
WD
659- FD_SET(msg_fd_out, &w_fds);
660- if (msg_fd_out > maxfd)
661- maxfd = msg_fd_out;
662- }
663 if (io_filesfrom_f_out >= 0) {
664 int new_fd;
665 if (io_filesfrom_buflen == 0) {
7cf8a551 666@@ -521,9 +466,6 @@ static int read_timeout(int fd, char *bu
3ca259e2
WD
667 continue;
668 }
669
3a748b26
WD
670- if (msg2genr.head && FD_ISSET(msg_fd_out, &w_fds))
671- msg2genr_flush(NORMAL_FLUSH);
3ca259e2
WD
672-
673 if (io_filesfrom_f_out >= 0) {
674 if (io_filesfrom_buflen) {
675 if (FD_ISSET(io_filesfrom_f_out, &w_fds)) {
7cf8a551 676@@ -845,6 +787,8 @@ static void readfd(int fd, char *buffer,
3ca259e2
WD
677 }
678
679 if (fd == write_batch_monitor_in) {
680+ if (am_generator())
681+ rprintf(FINFO, "writing %d bytes to batch file from generator\n", total);
682 if ((size_t)write(batch_fd, buffer, total) != total)
683 exit_cleanup(RERR_FILEIO);
684 }
7cf8a551 685@@ -1106,7 +1050,6 @@ static void writefd_unbuffered(int fd,ch
3ca259e2
WD
686 * to grab any messages they sent before they died. */
687 while (fd == sock_f_out && io_multiplexing_in) {
688 set_io_timeout(30);
689- ignore_timeout = 0;
690 readfd_unbuffered(sock_f_in, io_filesfrom_buf,
691 sizeof io_filesfrom_buf);
692 }
7cf8a551 693@@ -1117,7 +1060,7 @@ static void writefd_unbuffered(int fd,ch
b06103cc 694 defer_forwarding_messages = 1;
3ca259e2
WD
695
696 if (fd == sock_f_out) {
697- if (io_timeout || am_generator)
698+ if (io_timeout || am_generator())
699 last_io_out = time(NULL);
e89d5d9a 700 sleep_for_bwlimit(cnt);
3ca259e2 701 }
7cf8a551 702@@ -1127,23 +1070,6 @@ static void writefd_unbuffered(int fd,ch
3a748b26 703 no_flush--;
3ca259e2 704 }
b06103cc
WD
705
706-static void msg2sndr_flush(void)
707-{
708- if (defer_forwarding_messages)
709- return;
710-
711- while (msg2sndr.head && io_multiplexing_out) {
712- struct msg_list_item *m = msg2sndr.head;
713- if (!(msg2sndr.head = m->next))
714- msg2sndr.tail = NULL;
715- stats.total_written += m->len;
716- defer_forwarding_messages = 1;
717- writefd_unbuffered(sock_f_out, m->buf, m->len);
718- defer_forwarding_messages = 0;
719- free(m);
720- }
721-}
722-
723 /**
724 * Write an message to a multiplexed stream. If this fails then rsync
725 * exits.
7cf8a551 726@@ -1169,14 +1095,15 @@ static void mplex_write(enum msgcode cod
b06103cc
WD
727 defer_forwarding_messages = 1;
728 writefd_unbuffered(sock_f_out, buf, len);
729 defer_forwarding_messages = 0;
730- msg2sndr_flush();
731+ if (am_generator())
732+ msg_list_flush();
733 }
734 }
3ca259e2 735
3ca259e2
WD
736 void io_flush(int flush_it_all)
737 {
3a748b26 738- msg2genr_flush(flush_it_all);
b06103cc 739- msg2sndr_flush();
3ca259e2 740+ if (am_generator())
b06103cc
WD
741+ msg_list_flush();
742
743 if (!iobuf_out_cnt || no_flush)
744 return;
7cf8a551 745@@ -1190,11 +1117,6 @@ void io_flush(int flush_it_all)
3ca259e2 746
3ca259e2
WD
747 static void writefd(int fd,char *buf,size_t len)
748 {
749- if (fd == msg_fd_out) {
750- rprintf(FERROR, "Internal error: wrong write used in receiver.\n");
751- exit_cleanup(RERR_PROTOCOL);
752- }
753-
754 if (fd == sock_f_out)
755 stats.total_written += len;
756
7cf8a551 757@@ -1400,9 +1322,3 @@ void start_write_batch(int fd)
3ca259e2
WD
758 else
759 write_batch_monitor_in = fd;
760 }
761-
762-void stop_write_batch(void)
763-{
764- write_batch_monitor_out = -1;
765- write_batch_monitor_in = -1;
766-}
9a7eef96
WD
767--- old/log.c
768+++ new/log.c
7cf8a551 769@@ -33,7 +33,6 @@ extern int am_sender;
3ca259e2
WD
770 extern int local_server;
771 extern int quiet;
772 extern int module_id;
773-extern int msg_fd_out;
577db5e2 774 extern int allow_8bit_chars;
3ca259e2
WD
775 extern int protocol_version;
776 extern int preserve_times;
7cf8a551 777@@ -71,7 +70,6 @@ struct {
3ca259e2
WD
778 { RERR_IPC , "error in IPC code" },
779 { RERR_CRASHED , "sibling process crashed" },
780 { RERR_TERMINATED , "sibling process terminated abnormally" },
8a0123e5
WD
781- { RERR_SIGNAL1 , "received SIGUSR1" },
782 { RERR_SIGNAL , "received SIGINT, SIGTERM, or SIGHUP" },
3ca259e2
WD
783 { RERR_WAITCHILD , "waitpid() failed" },
784 { RERR_MALLOC , "error allocating core memory buffers" },
7cf8a551 785@@ -227,8 +225,8 @@ void rwrite(enum logcode code, char *buf
e89d5d9a
WD
786 if (quiet && code == FINFO)
787 return;
3ca259e2
WD
788
789- if (am_server && msg_fd_out >= 0) {
790- /* Pass the message to our sibling. */
791+ if (am_receiver()) {
792+ /* Pass the message to the generator thread. */
793 send_msg((enum msgcode)code, buf, len);
794 return;
795 }
9a7eef96
WD
796--- old/main.c
797+++ new/main.c
7cf8a551 798@@ -32,7 +32,6 @@ extern int list_only;
3ca259e2
WD
799 extern int am_root;
800 extern int am_server;
801 extern int am_sender;
802-extern int am_generator;
803 extern int am_daemon;
804 extern int blocking_io;
805 extern int remove_sent_files;
7cf8a551 806@@ -87,9 +86,20 @@ struct pid_status {
3ca259e2
WD
807
808 static time_t starttime, endtime;
809 static int64 total_read, total_written;
810+static pthread_t receiver_tid;
811
812 static void show_malloc_stats(void);
813
814+int am_generator()
815+{
816+ return receiver_tid != 0 && pthread_self() != receiver_tid;
817+}
818+
819+int am_receiver()
820+{
821+ return receiver_tid != 0 && pthread_self() == receiver_tid;
822+}
823+
824 /* Works like waitpid(), but if we already harvested the child pid in our
c769ea2c 825 * remember_children(), we succeed instead of returning an error. */
3ca259e2 826 pid_t wait_process(pid_t pid, int *status_ptr, int flags)
7cf8a551 827@@ -166,7 +176,7 @@ static void handle_stats(int f)
3ca259e2
WD
828 show_flist_stats();
829 }
830
831- if (am_generator)
832+ if (am_generator())
833 return;
834
835 if (am_daemon) {
7cf8a551 836@@ -630,12 +640,30 @@ static void do_server_sender(int f_in, i
3ca259e2
WD
837 exit_cleanup(0);
838 }
839
840+struct thread_args {
841+ struct file_list *flist;
842+ char *local_name;
843+ int f_in;
844+};
845+
846+static void *start_receiver_thread(void *arg)
847+{
848+ static int exit_code;
849+ struct thread_args *ta = (struct thread_args *)arg;
850+
851+ recv_files(ta->f_in, ta->flist, ta->local_name);
852+ handle_stats(ta->f_in);
853+
854+ push_redo_num(-2);
855+
856+ exit_code = log_got_error ? RERR_PARTIAL : 0;
857+ return &exit_code;
858+}
859
860 static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
861 {
862- int pid;
863- int exit_code = 0;
864- int error_pipe[2];
865+ void *value_ptr;
866+ struct thread_args args;
867
868 /* The receiving side mustn't obey this, or an existing symlink that
869 * points to an identical file won't be replaced by the referent. */
7cf8a551 870@@ -644,70 +672,16 @@ static int do_recv(int f_in,int f_out,st
3ca259e2
WD
871 if (preserve_hard_links)
872 init_hard_links();
873
874- if (fd_pair(error_pipe) < 0) {
875- rsyserr(FERROR, errno, "pipe failed in do_recv");
876+ args.f_in = f_in;
877+ args.flist = flist;
878+ args.local_name = local_name;
879+ if (pthread_create(&receiver_tid, NULL, start_receiver_thread, &args) < 0) {
880+ rsyserr(FERROR, errno, "pthread_create failed in do_recv");
881 exit_cleanup(RERR_IPC);
882 }
883
884- io_flush(NORMAL_FLUSH);
885-
886- if ((pid = do_fork()) == -1) {
887- rsyserr(FERROR, errno, "fork failed in do_recv");
888- exit_cleanup(RERR_IPC);
889- }
890-
891- if (pid == 0) {
892- close(error_pipe[0]);
893- if (f_in != f_out)
894- close(f_out);
895-
896- /* we can't let two processes write to the socket at one time */
897- close_multiplexing_out();
898-
899- /* set place to send errors */
900- set_msg_fd_out(error_pipe[1]);
901-
902- recv_files(f_in, flist, local_name);
903- io_flush(FULL_FLUSH);
904- handle_stats(f_in);
905-
906- send_msg(MSG_DONE, "", 0);
907- io_flush(FULL_FLUSH);
908-
909- /* Handle any keep-alive packets from the post-processing work
910- * that the generator does. */
911- if (protocol_version >= 29) {
912- kluge_around_eof = -1;
913-
914- /* This should only get stopped via a USR2 signal. */
915- while (read_int(f_in) == flist->count
916- && read_shortint(f_in) == ITEM_IS_NEW) {}
917-
918- rprintf(FERROR, "Invalid packet at end of run [%s]\n",
919- who_am_i());
920- exit_cleanup(RERR_PROTOCOL);
921- }
922-
923- /* Finally, we go to sleep until our parent kills us with a
924- * USR2 signal. We sleep for a short time, as on some OSes
925- * a signal won't interrupt a sleep! */
926- while (1)
927- msleep(20);
928- }
929-
930- am_generator = 1;
931- close_multiplexing_in();
932- if (write_batch && !am_server)
933- stop_write_batch();
934-
935- close(error_pipe[1]);
936- if (f_in != f_out)
937- close(f_in);
938-
939 io_start_buffering_out();
940
941- set_msg_fd_in(error_pipe[0]);
942-
943 generate_files(f_out, flist, local_name);
944
945 handle_stats(-1);
7cf8a551 946@@ -718,10 +692,13 @@ static int do_recv(int f_in,int f_out,st
3ca259e2
WD
947 }
948 io_flush(FULL_FLUSH);
949
950- set_msg_fd_in(-1);
951- kill(pid, SIGUSR2);
952- wait_process_with_flush(pid, &exit_code);
953- return exit_code;
954+ pthread_join(receiver_tid, &value_ptr);
955+ if (!am_server)
956+ output_summary();
957+
958+ close_all();
959+
960+ return *(int*)value_ptr;
961 }
962
963
7cf8a551 964@@ -1091,22 +1068,6 @@ static int start_client(int argc, char *
3ca259e2
WD
965 return ret;
966 }
967
968-
969-static RETSIGTYPE sigusr1_handler(UNUSED(int val))
970-{
8a0123e5 971- exit_cleanup(RERR_SIGNAL1);
3ca259e2
WD
972-}
973-
974-static RETSIGTYPE sigusr2_handler(UNUSED(int val))
975-{
976- if (!am_server)
977- output_summary();
978- close_all();
979- if (log_got_error)
980- _exit(RERR_PARTIAL);
981- _exit(0);
982-}
983-
c769ea2c 984 RETSIGTYPE remember_children(UNUSED(int val))
3ca259e2
WD
985 {
986 #ifdef WNOHANG
7cf8a551 987@@ -1198,8 +1159,6 @@ int main(int argc,char *argv[])
8857e5dd 988 # endif
bc5988ec
WD
989 sigact.sa_flags = SA_NOCLDSTOP;
990 #endif
991- SIGACTMASK(SIGUSR1, sigusr1_handler);
992- SIGACTMASK(SIGUSR2, sigusr2_handler);
c769ea2c 993 SIGACTMASK(SIGCHLD, remember_children);
3ca259e2 994 #ifdef MAINTAINER_MODE
bc5988ec 995 SIGACTMASK(SIGSEGV, rsync_panic_handler);
9a7eef96
WD
996--- old/match.c
997+++ new/match.c
7cf8a551 998@@ -23,7 +23,7 @@
d42637db 999 #include "rsync.h"
3ca259e2
WD
1000
1001 extern int verbose;
3ca259e2
WD
1002-extern int do_progress;
1003+extern int recv_progress;
1004 extern int checksum_seed;
1005 extern int append_mode;
1006
7cf8a551 1007@@ -113,7 +113,7 @@ static void matched(int f, struct sum_st
3ca259e2
WD
1008 else
1009 last_match = offset;
1010
1011- if (buf && do_progress)
1012+ if (buf && recv_progress)
1013 show_progress(last_match, buf->file_size);
1014 }
1015
7cf8a551 1016@@ -317,7 +317,7 @@ void match_sums(int f, struct sum_struct
3ca259e2
WD
1017 if (append_mode) {
1018 OFF_T j = 0;
1019 for (j = CHUNK_SIZE; j < s->flength; j += CHUNK_SIZE) {
1020- if (buf && do_progress)
1021+ if (buf && recv_progress)
1022 show_progress(last_match, buf->file_size);
1023 sum_update(map_ptr(buf, last_match, CHUNK_SIZE),
1024 CHUNK_SIZE);
7cf8a551 1025@@ -325,7 +325,7 @@ void match_sums(int f, struct sum_struct
3ca259e2
WD
1026 }
1027 if (last_match < s->flength) {
1028 int32 len = s->flength - last_match;
1029- if (buf && do_progress)
1030+ if (buf && recv_progress)
1031 show_progress(last_match, buf->file_size);
1032 sum_update(map_ptr(buf, last_match, len), len);
1033 last_match = s->flength;
9a7eef96
WD
1034--- old/options.c
1035+++ new/options.c
d42637db 1036@@ -74,7 +74,6 @@ int def_compress_level = Z_DEFAULT_COMPR
3ca259e2
WD
1037 int am_root = 0;
1038 int am_server = 0;
1039 int am_sender = 0;
1040-int am_generator = 0;
1041 int am_starting_up = 1;
3ca259e2 1042 int relative_paths = -1;
d42637db 1043 int implied_dirs = 1;
577db5e2 1044@@ -95,6 +94,7 @@ int am_daemon = 0;
3ca259e2
WD
1045 int daemon_over_rsh = 0;
1046 int do_stats = 0;
1047 int do_progress = 0;
1048+int recv_progress = 0;
1049 int keep_partial = 0;
1050 int safe_symlinks = 0;
1051 int copy_unsafe_links = 0;
7cf8a551 1052@@ -1300,6 +1300,7 @@ int parse_arguments(int *argc, const cha
afcb578c
WD
1053
1054 if (do_progress && !verbose && !log_before_transfer && !am_server)
3ca259e2
WD
1055 verbose = 1;
1056+ recv_progress = do_progress;
1057
1058 if (dry_run)
1059 do_xfers = 0;
9a7eef96
WD
1060--- old/pipe.c
1061+++ new/pipe.c
7cf8a551 1062@@ -58,7 +58,7 @@ pid_t piped_child(char **command, int *f
3ca259e2
WD
1063 exit_cleanup(RERR_IPC);
1064 }
1065
1066- pid = do_fork();
1067+ pid = fork();
1068 if (pid == -1) {
1069 rsyserr(FERROR, errno, "fork");
1070 exit_cleanup(RERR_IPC);
7cf8a551 1071@@ -122,7 +122,7 @@ pid_t local_child(int argc, char **argv,
3ca259e2
WD
1072 exit_cleanup(RERR_IPC);
1073 }
1074
1075- pid = do_fork();
1076+ pid = fork();
1077 if (pid == -1) {
1078 rsyserr(FERROR, errno, "fork");
1079 exit_cleanup(RERR_IPC);
9a7eef96
WD
1080--- old/receiver.c
1081+++ new/receiver.c
7cf8a551 1082@@ -26,7 +26,7 @@ extern int verbose;
3ca259e2
WD
1083 extern int do_xfers;
1084 extern int am_daemon;
1085 extern int am_server;
1086-extern int do_progress;
1087+extern int recv_progress;
1088 extern int log_before_transfer;
1089 extern int log_format_has_i;
1090 extern int daemon_log_format_has_i;
7cf8a551 1091@@ -155,7 +155,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1092 if (sum.remainder)
1093 sum.flength -= sum.blength - sum.remainder;
1094 for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) {
1095- if (do_progress)
1096+ if (recv_progress)
1097 show_progress(offset, total_size);
1098 sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE),
1099 CHUNK_SIZE);
7cf8a551 1100@@ -163,7 +163,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1101 }
1102 if (offset < sum.flength) {
1103 int32 len = sum.flength - offset;
1104- if (do_progress)
1105+ if (recv_progress)
1106 show_progress(offset, total_size);
1107 sum_update(map_ptr(mapbuf, offset, len), len);
1108 offset = sum.flength;
7cf8a551 1109@@ -176,7 +176,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1110 }
1111
1112 while ((i = recv_token(f_in, &data)) != 0) {
1113- if (do_progress)
1114+ if (recv_progress)
1115 show_progress(offset, total_size);
1116
1117 if (i > 0) {
7cf8a551 1118@@ -244,7 +244,7 @@ static int receive_data(int f_in, char *
3ca259e2
WD
1119 ftruncate(fd, offset);
1120 #endif
1121
1122- if (do_progress)
1123+ if (recv_progress)
1124 end_progress(total_size);
1125
1126 if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
7cf8a551 1127@@ -295,12 +295,12 @@ static void handle_delayed_updates(struc
93ca4d27
WD
1128 "rename failed for %s (from %s)",
1129 full_fname(fname), partialptr);
3ca259e2
WD
1130 } else {
1131- if (remove_sent_files
1132- || (preserve_hard_links
1133- && file->link_u.links)) {
1134+ if (remove_sent_files) {
1135 SIVAL(numbuf, 0, i);
1136 send_msg(MSG_SUCCESS,numbuf,4);
1137 }
3ca259e2
WD
1138+ if (preserve_hard_links && file->link_u.links)
1139+ push_hlink_num(i);
93ca4d27 1140 handle_partial_dir(partialptr, PDIR_DELETE);
3ca259e2
WD
1141 }
1142 }
7cf8a551 1143@@ -351,11 +351,6 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1144 if (verbose > 2)
1145 rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
1146
1147- if (flist->hlink_pool) {
1148- pool_destroy(flist->hlink_pool);
1149- flist->hlink_pool = NULL;
1150- }
1151-
1152 if (delay_updates)
577db5e2 1153 delayed_bits = bitbag_create(flist->count);
3ca259e2 1154
7cf8a551 1155@@ -376,7 +371,7 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1156 rprintf(FINFO, "recv_files phase=%d\n", phase);
1157 if (phase == 2 && delay_updates)
1158 handle_delayed_updates(flist, local_name);
1159- send_msg(MSG_DONE, "", 0);
1160+ push_redo_num(-2);
1161 if (keep_partial && !partial_dir)
1162 make_backups = 0; /* prevents double backup */
1163 if (append_mode) {
7cf8a551 1164@@ -598,7 +593,7 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1165 /* log the transfer */
1166 if (log_before_transfer)
1167 log_item(file, &initial_stats, iflags, NULL);
1168- else if (!am_server && verbose && do_progress)
1169+ else if (!am_server && verbose && recv_progress)
93ca4d27 1170 rprintf(FINFO, "%s\n", fname);
3ca259e2
WD
1171
1172 /* recv file data */
7cf8a551 1173@@ -641,11 +636,13 @@ int recv_files(int f_in, struct file_lis
3ca259e2
WD
1174 cleanup_disable();
1175
1176 if (recv_ok > 0) {
1177- if (remove_sent_files
1178- || (preserve_hard_links && file->link_u.links)) {
1179+ if (remove_sent_files) {
fb0b1cab 1180+ decrement_active_files(i);
3ca259e2
WD
1181 SIVAL(numbuf, 0, i);
1182 send_msg(MSG_SUCCESS, numbuf, 4);
1183 }
1184+ if (preserve_hard_links && file->link_u.links)
1185+ push_hlink_num(i);
1186 } else if (!recv_ok) {
1187 int msgtype = phase || read_batch ? FERROR : FINFO;
1188 if (msgtype == FERROR || verbose) {
7cf8a551 1189@@ -668,8 +665,8 @@ int recv_files(int f_in, struct file_lis
93ca4d27 1190 errstr, fname, keptstr, redostr);
3ca259e2 1191 }
fb0b1cab 1192 if (!phase) {
3ca259e2
WD
1193- SIVAL(numbuf, 0, i);
1194- send_msg(MSG_REDO, numbuf, 4);
fb0b1cab 1195+ decrement_active_files(i);
3ca259e2 1196+ push_redo_num(i);
fb0b1cab 1197 }
3ca259e2
WD
1198 }
1199 }
9a7eef96
WD
1200--- old/rsync.c
1201+++ new/rsync.c
d42637db 1202@@ -40,7 +40,6 @@ extern int omit_dir_times;
3ca259e2
WD
1203 extern int am_root;
1204 extern int am_server;
1205 extern int am_sender;
1206-extern int am_generator;
1207 extern int am_starting_up;
577db5e2 1208 extern int allow_8bit_chars;
3ca259e2 1209 extern int preserve_uid;
c769ea2c 1210@@ -303,5 +302,5 @@ const char *who_am_i(void)
3ca259e2
WD
1211 {
1212 if (am_starting_up)
1213 return am_server ? "server" : "client";
1214- return am_sender ? "sender" : am_generator ? "generator" : "receiver";
1215+ return am_sender ? "sender" : am_generator() ? "generator" : "receiver";
1216 }
9a7eef96
WD
1217--- old/rsync.h
1218+++ new/rsync.h
7cf8a551 1219@@ -168,10 +168,8 @@ enum msgcode {
3ca259e2
WD
1220 MSG_DATA=0, /* raw data on the multiplexed stream */
1221 MSG_ERROR=FERROR, MSG_INFO=FINFO, /* remote logging */
e89d5d9a 1222 MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR, /* sibling logging */
3ca259e2
WD
1223- MSG_REDO=9, /* reprocess indicated flist index */
1224 MSG_SUCCESS=100,/* successfully updated indicated flist index */
1225 MSG_DELETED=101,/* successfully deleted a file on receiving side */
1226- MSG_DONE=86 /* current phase is done */
1227 };
1228
1229 #include "errcode.h"
7cf8a551 1230@@ -322,6 +320,7 @@ enum msgcode {
3ca259e2
WD
1231 #endif
1232
1233 #include <assert.h>
1234+#include <pthread.h>
1235
1236 #include "lib/pool_alloc.h"
1237
9a7eef96
WD
1238--- old/util.c
1239+++ new/util.c
7cf8a551 1240@@ -410,49 +410,6 @@ int robust_rename(char *from, char *to,
3ca259e2
WD
1241 return -1;
1242 }
1243
3ca259e2
WD
1244-static pid_t all_pids[10];
1245-static int num_pids;
1246-
1247-/** Fork and record the pid of the child. **/
1248-pid_t do_fork(void)
1249-{
1250- pid_t newpid = fork();
1251-
1252- if (newpid != 0 && newpid != -1) {
1253- all_pids[num_pids++] = newpid;
1254- }
1255- return newpid;
1256-}
1257-
1258-/**
1259- * Kill all children.
1260- *
1261- * @todo It would be kind of nice to make sure that they are actually
1262- * all our children before we kill them, because their pids may have
1263- * been recycled by some other process. Perhaps when we wait for a
1264- * child, we should remove it from this array. Alternatively we could
1265- * perhaps use process groups, but I think that would not work on
1266- * ancient Unix versions that don't support them.
1267- **/
1268-void kill_all(int sig)
1269-{
1270- int i;
1271-
1272- for (i = 0; i < num_pids; i++) {
1273- /* Let's just be a little careful where we
1274- * point that gun, hey? See kill(2) for the
1275- * magic caused by negative values. */
1276- pid_t p = all_pids[i];
1277-
1278- if (p == getpid())
1279- continue;
1280- if (p <= 0)
1281- continue;
1282-
1283- kill(p, sig);
1284- }
1285-}
3ca259e2
WD
1286-
1287 /** Turn a user name into a uid */
1288 int name_to_uid(char *name, uid_t *uid)
1289 {