Updated to work with latest io.c changes.
[rsync/rsync-patches.git] / threaded-receiver.diff
1 This patch changes the receiving side to have the receiving code use a thread
2 instead of a forked process.  This extra thread does read from the socket, but
3 it 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
6 there 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
8 messages that arrive on the receiving side during the --delete-after phase!)
9
10 This code just uses pthread.h directly, so configure changes will probably be
11 needed to make this compatible with more systems.  I have also tested that
12 this code works fine using the GNU pth library without any code changes if
13 you configured it with --enable-syscall-soft --enable-pthread (you may need
14 to twiddle the Makefile options if you didn't install the library, though).
15
16 NOTE: we still need to duplicate the partial_fname static in util.c!
17
18 If you try this out, please send some email to wayned@samba.org or the rsync
19 mailing list with your results, build changes, bug reports, etc.  Thanks!
20
21 After applying this patch, run these commands for a successful build:
22
23     ./prepare-source
24     ./configure                      (optional if already run)
25     make
26
27 --- old/Makefile.in
28 +++ new/Makefile.in
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@
38 --- old/cleanup.c
39 +++ new/cleanup.c
40 @@ -26,10 +26,6 @@ extern int keep_partial;
41  extern int log_got_error;
42  extern char *partial_dir;
43  
44 -#ifdef HAVE_SIGACTION
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 
52         }
53         inside_cleanup++;
54  
55 -       SIGACTION(SIGUSR1, SIG_IGN);
56 -       SIGACTION(SIGUSR2, SIG_IGN);
57 -
58         if (verbose > 3) {
59                 rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n",
60                         code, file, line);
61 @@ -132,8 +125,6 @@ void _exit_cleanup(int code, const char 
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)
70 --- old/errcode.h
71 +++ new/errcode.h
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 */
80 --- old/generator.c
81 +++ new/generator.c
82 @@ -67,7 +67,6 @@ extern OFF_T min_size;
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;
90 @@ -97,6 +96,11 @@ static int deletion_count = 0; /* used t
91  static int can_link_symlinks = 1; /* start out optimistic */
92  static int can_link_devices = 1;
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)
102 @@ -445,8 +449,8 @@ static void sum_sizes_sqroot(struct sum_
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;
113 @@ -456,7 +460,7 @@ static void sum_sizes_sqroot(struct sum_
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  
122 @@ -490,7 +494,7 @@ static void generate_and_send_sums(int f
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)
131 @@ -509,7 +513,7 @@ static void generate_and_send_sums(int f
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  
140 @@ -1152,7 +1156,7 @@ static void recv_generator(char *fname, 
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  
148         if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
149 @@ -1207,7 +1211,7 @@ static void recv_generator(char *fname, 
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;
158 @@ -1298,9 +1302,12 @@ void generate_files(int f_out, struct fi
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;
164         int dir_tweaking = !(list_only || local_name || dry_run);
165  
166 +       GEN_append_mode = append_mode;
167 +       GEN_csum_length = csum_length;
168 +
169         if (protocol_version >= 29) {
170                 itemizing = 1;
171                 maybe_ATTRS_REPORT = log_format_has_i ? 0 : ATTRS_REPORT;
172 @@ -1328,7 +1335,7 @@ void generate_files(int f_out, struct fi
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",
181 @@ -1337,12 +1344,6 @@ void generate_files(int f_out, struct fi
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  
194 @@ -1386,23 +1387,34 @@ void generate_files(int f_out, struct fi
195                 delete_in_dir(NULL, NULL, NULL, NULL);
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
235 @@ -1414,27 +1426,43 @@ void generate_files(int f_out, struct fi
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;
286 --- old/io.c
287 +++ new/io.c
288 @@ -46,20 +46,17 @@ extern int allowed_lull;
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;
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;
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  
309 @@ -83,7 +80,6 @@ const char *io_read_phase = phase_unknow
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  
317 @@ -110,27 +106,31 @@ static OFF_T active_bytecnt = 0;
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;
339         int len;
340 +       enum msgcode code;
341         char buf[1];
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  
350 -static struct msg_list msg2genr, msg2sndr;
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  {
355 @@ -140,27 +140,31 @@ static void flist_ndx_push(struct flist_
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  }
393 @@ -169,7 +173,7 @@ static void check_timeout(void)
394  {
395         time_t t;
396  
397 -       if (!io_timeout || ignore_timeout)
398 +       if (!io_timeout)
399                 return;
400  
401         if (!last_io_in) {
402 @@ -210,44 +214,38 @@ void set_io_timeout(int secs)
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. */
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)
425  {
426         struct msg_list_item *m;
427 -       int sz = len + 4 + sizeof m[0] - 1;
428 +       int sz = len + sizeof m[0] - 1;
429  
430 +       assert(am_receiver());
431         if (!(m = (struct msg_list_item *)new_array(char, sz)))
432                 out_of_memory("msg_list_add");
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);
442 +
443 +       pthread_mutex_lock(&msg_list.mutex);
444 +       if (msg_list.tail)
445 +               msg_list.tail->next = m;
446         else
447 -               lst->head = m;
448 -       lst->tail = m;
449 +               msg_list.head = m;
450 +       msg_list.tail = m;
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];
463 @@ -266,57 +264,6 @@ static void read_msg_fd(void)
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);
480 -               if (remove_sent_files)
481 -                       decrement_active_files(IVAL(buf,0));
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);
490 -               if (defer_forwarding_messages)
491 -                       msg_list_add(&msg2sndr, MSG_DELETED, buf, len);
492 -               else
493 -                       io_multiplex_write(MSG_DELETED, buf, len);
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);
501 -               if (remove_sent_files) {
502 -                       decrement_active_files(IVAL(buf,0));
503 -                       if (defer_forwarding_messages)
504 -                               msg_list_add(&msg2sndr, MSG_SUCCESS, buf, len);
505 -                       else
506 -                               io_multiplex_write(MSG_SUCCESS, buf, len);
507 -               }
508 -               if (preserve_hard_links)
509 -                       flist_ndx_push(&hlink_list, IVAL(buf,0));
510 -               break;
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 */
518         case MSG_INFO:
519         case MSG_ERROR:
520         case MSG_LOG:
521 @@ -325,10 +272,7 @@ static void read_msg_fd(void)
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;
533 @@ -362,70 +306,76 @@ void decrement_active_files(int ndx)
534         active_bytecnt -= the_file_list->files[ndx]->length;
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. */
541 -static int msg2genr_flush(int flush_it_all)
542 + * This is only called by the generator. */
543 +static void msg_list_flush(void)
544  {
545 -       static int written = 0;
546 -       struct timeval tv;
547 -       fd_set fds;
548 +       assert(am_generator());
549  
550 -       if (msg_fd_out < 0)
551 -               return -1;
552 +       if (defer_forwarding_messages)
553 +               return;
554  
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);
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();
571 -               } else if ((written += n) == m->len) {
572 -                       msg2genr.head = m->next;
573 -                       if (!msg2genr.head)
574 -                               msg2genr.tail = NULL;
575 -                       free(m);
576 -                       written = 0;
577 +       no_flush++;
578 +       defer_forwarding_messages = 1;
579 +       while (msg_list.head) {
580 +               struct msg_list_item *m = (struct msg_list_item *)msg_list.head;
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);
585 +               switch (m->code) {
586 +               case MSG_SOCKERR:
587 +                       close_multiplexing_out();
588 +                       /* FALL THROUGH */
589 +               case MSG_INFO:
590 +               case MSG_ERROR:
591 +               case MSG_LOG:
592 +                       rwrite(m->code, m->buf, m->len);
593 +                       break;
594 +               default:
595 +                       io_multiplex_write(m->code, m->buf, m->len);
596 +                       break;
597                 }
598 +               free(m);
599         }
600 -       return 1;
601 +       defer_forwarding_messages = 0;
602 +       no_flush--;
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 -       }
614 -       msg_list_add(&msg2genr, code, buf, len);
615 -       msg2genr_flush(NORMAL_FLUSH);
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  
654 @@ -505,11 +455,6 @@ static int read_timeout(int fd, char *bu
655                 FD_ZERO(&r_fds);
656                 FD_ZERO(&w_fds);
657                 FD_SET(fd, &r_fds);
658 -               if (msg2genr.head) {
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) {
666 @@ -542,9 +487,6 @@ static int read_timeout(int fd, char *bu
667                         continue;
668                 }
669  
670 -               if (msg2genr.head && FD_ISSET(msg_fd_out, &w_fds))
671 -                       msg2genr_flush(NORMAL_FLUSH);
672 -
673                 if (io_filesfrom_f_out >= 0) {
674                         if (io_filesfrom_buflen) {
675                                 if (FD_ISSET(io_filesfrom_f_out, &w_fds)) {
676 @@ -866,6 +808,8 @@ static void readfd(int fd, char *buffer,
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         }
685 @@ -1127,7 +1071,6 @@ static void writefd_unbuffered(int fd,ch
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                         }
693 @@ -1138,7 +1081,7 @@ static void writefd_unbuffered(int fd,ch
694                 defer_forwarding_messages = 1;
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);
700                         sleep_for_bwlimit(cnt);
701                 }
702 @@ -1148,23 +1091,6 @@ static void writefd_unbuffered(int fd,ch
703         no_flush--;
704  }
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.
726 @@ -1190,14 +1116,15 @@ static void mplex_write(enum msgcode cod
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  }
735  
736  void io_flush(int flush_it_all)
737  {
738 -       msg2genr_flush(flush_it_all);
739 -       msg2sndr_flush();
740 +       if (am_generator())
741 +               msg_list_flush();
742  
743         if (!iobuf_out_cnt || no_flush)
744                 return;
745 @@ -1211,11 +1138,6 @@ void io_flush(int flush_it_all)
746  
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  
757 @@ -1428,9 +1350,3 @@ void start_write_batch(int fd)
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 -}
767 --- old/log.c
768 +++ new/log.c
769 @@ -38,7 +38,6 @@ extern int am_sender;
770  extern int local_server;
771  extern int quiet;
772  extern int module_id;
773 -extern int msg_fd_out;
774  extern int allow_8bit_chars;
775  extern int protocol_version;
776  extern int preserve_times;
777 @@ -76,7 +75,6 @@ struct {
778         { RERR_IPC        , "error in IPC code" },
779         { RERR_CRASHED    , "sibling process crashed" },
780         { RERR_TERMINATED , "sibling process terminated abnormally" },
781 -       { RERR_SIGNAL1    , "received SIGUSR1" },
782         { RERR_SIGNAL     , "received SIGINT, SIGTERM, or SIGHUP" },
783         { RERR_WAITCHILD  , "waitpid() failed" },
784         { RERR_MALLOC     , "error allocating core memory buffers" },
785 @@ -232,8 +230,8 @@ void rwrite(enum logcode code, char *buf
786         if (quiet && code == FINFO)
787                 return;
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         }
796 --- old/main.c
797 +++ new/main.c
798 @@ -30,7 +30,6 @@ extern int list_only;
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;
806 @@ -85,9 +84,20 @@ struct pid_status {
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
825   * remember_children(), we succeed instead of returning an error. */
826  pid_t wait_process(pid_t pid, int *status_ptr, int flags)
827 @@ -164,7 +174,7 @@ static void handle_stats(int f)
828                 show_flist_stats();
829         }
830  
831 -       if (am_generator)
832 +       if (am_generator())
833                 return;
834  
835         if (am_daemon) {
836 @@ -628,12 +638,30 @@ static void do_server_sender(int f_in, i
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. */
870 @@ -642,70 +670,16 @@ static int do_recv(int f_in,int f_out,st
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);
946 @@ -716,10 +690,13 @@ static int do_recv(int f_in,int f_out,st
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  
964 @@ -1089,22 +1066,6 @@ static int start_client(int argc, char *
965         return ret;
966  }
967  
968 -
969 -static RETSIGTYPE sigusr1_handler(UNUSED(int val))
970 -{
971 -       exit_cleanup(RERR_SIGNAL1);
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 -
984  RETSIGTYPE remember_children(UNUSED(int val))
985  {
986  #ifdef WNOHANG
987 @@ -1196,8 +1157,6 @@ int main(int argc,char *argv[])
988  # endif
989         sigact.sa_flags = SA_NOCLDSTOP;
990  #endif
991 -       SIGACTMASK(SIGUSR1, sigusr1_handler);
992 -       SIGACTMASK(SIGUSR2, sigusr2_handler);
993         SIGACTMASK(SIGCHLD, remember_children);
994  #ifdef MAINTAINER_MODE
995         SIGACTMASK(SIGSEGV, rsync_panic_handler);
996 --- old/match.c
997 +++ new/match.c
998 @@ -20,7 +20,7 @@
999  #include "rsync.h"
1000  
1001  extern int verbose;
1002 -extern int do_progress;
1003 +extern int recv_progress;
1004  extern int checksum_seed;
1005  extern int append_mode;
1006  
1007 @@ -110,7 +110,7 @@ static void matched(int f, struct sum_st
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  
1016 @@ -314,7 +314,7 @@ void match_sums(int f, struct sum_struct
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);
1025 @@ -322,7 +322,7 @@ void match_sums(int f, struct sum_struct
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;
1034 --- old/options.c
1035 +++ new/options.c
1036 @@ -74,7 +74,6 @@ int def_compress_level = Z_DEFAULT_COMPR
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;
1042  int relative_paths = -1;
1043  int implied_dirs = 1;
1044 @@ -95,6 +94,7 @@ int am_daemon = 0;
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;
1052 @@ -1301,6 +1301,7 @@ int parse_arguments(int *argc, const cha
1053  
1054         if (do_progress && !verbose && !log_before_transfer && !am_server)
1055                 verbose = 1;
1056 +       recv_progress = do_progress;
1057  
1058         if (dry_run)
1059                 do_xfers = 0;
1060 --- old/pipe.c
1061 +++ new/pipe.c
1062 @@ -56,7 +56,7 @@ pid_t piped_child(char **command, int *f
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);
1071 @@ -120,7 +120,7 @@ pid_t local_child(int argc, char **argv,
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);
1080 --- old/receiver.c
1081 +++ new/receiver.c
1082 @@ -24,7 +24,7 @@ extern int verbose;
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;
1091 @@ -153,7 +153,7 @@ static int receive_data(int f_in, char *
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);
1100 @@ -161,7 +161,7 @@ static int receive_data(int f_in, char *
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;
1109 @@ -174,7 +174,7 @@ static int receive_data(int f_in, char *
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) {
1118 @@ -242,7 +242,7 @@ static int receive_data(int f_in, char *
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) {
1127 @@ -293,12 +293,12 @@ static void handle_delayed_updates(struc
1128                                         "rename failed for %s (from %s)",
1129                                         full_fname(fname), partialptr);
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                                 }
1138 +                               if (preserve_hard_links && file->link_u.links)
1139 +                                       push_hlink_num(i);
1140                                 handle_partial_dir(partialptr, PDIR_DELETE);
1141                         }
1142                 }
1143 @@ -349,11 +349,6 @@ int recv_files(int f_in, struct file_lis
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)
1153                 delayed_bits = bitbag_create(flist->count);
1154  
1155 @@ -374,7 +369,7 @@ int recv_files(int f_in, struct file_lis
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) {
1164 @@ -596,7 +591,7 @@ int recv_files(int f_in, struct file_lis
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)
1170                         rprintf(FINFO, "%s\n", fname);
1171  
1172                 /* recv file data */
1173 @@ -639,11 +634,13 @@ int recv_files(int f_in, struct file_lis
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) {
1180 +                               decrement_active_files(i);
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) {
1189 @@ -666,8 +663,8 @@ int recv_files(int f_in, struct file_lis
1190                                         errstr, fname, keptstr, redostr);
1191                         }
1192                         if (!phase) {
1193 -                               SIVAL(numbuf, 0, i);
1194 -                               send_msg(MSG_REDO, numbuf, 4);
1195 +                               decrement_active_files(i);
1196 +                               push_redo_num(i);
1197                         }
1198                 }
1199         }
1200 --- old/rsync.c
1201 +++ new/rsync.c
1202 @@ -40,7 +40,6 @@ extern int omit_dir_times;
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;
1208  extern int allow_8bit_chars;
1209  extern int preserve_uid;
1210 @@ -303,5 +302,5 @@ const char *who_am_i(void)
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  }
1217 --- old/rsync.h
1218 +++ new/rsync.h
1219 @@ -166,10 +166,8 @@ enum msgcode {
1220         MSG_DATA=0,     /* raw data on the multiplexed stream */
1221         MSG_ERROR=FERROR, MSG_INFO=FINFO, /* remote logging */
1222         MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR, /* sibling logging */
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"
1230 @@ -320,6 +318,7 @@ enum msgcode {
1231  #endif
1232  
1233  #include <assert.h>
1234 +#include <pthread.h>
1235  
1236  #include "lib/pool_alloc.h"
1237  
1238 --- old/util.c
1239 +++ new/util.c
1240 @@ -420,49 +420,6 @@ int robust_rename(char *from, char *to, 
1241         return -1;
1242  }
1243  
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 -}
1286 -
1287  /** Turn a user name into a uid */
1288  int name_to_uid(char *name, uid_t *uid)
1289  {