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