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