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