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