Skip to content

Commit 32fe5fb

Browse files
committed
Correctly send last error to sender
1 parent bcb0a24 commit 32fe5fb

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

cleanup.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern int dry_run;
2626
extern int am_server;
2727
extern int am_daemon;
2828
extern int am_receiver;
29+
extern int am_sender;
2930
extern int io_error;
3031
extern int keep_partial;
3132
extern int got_xfer_error;
@@ -238,15 +239,21 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
238239
switch_step++;
239240

240241
if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
241-
&& exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
242-
if (line > 0) {
243-
if (DEBUG_GTE(EXIT, 3)) {
244-
rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
245-
who_am_i(), exit_code);
242+
&& exit_code != RERR_TIMEOUT && !shutting_down) {
243+
if (protocol_version >= 31 || am_receiver) {
244+
if (line > 0) {
245+
if (DEBUG_GTE(EXIT, 3)) {
246+
rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
247+
who_am_i(), exit_code);
248+
}
249+
send_msg_int(MSG_ERROR_EXIT, exit_code);
246250
}
247-
send_msg_int(MSG_ERROR_EXIT, exit_code);
251+
if (!am_sender)
252+
io_flush(MSG_FLUSH); /* Be sure to send all messages */
253+
noop_io_until_death();
248254
}
249-
noop_io_until_death();
255+
else if (!am_sender)
256+
io_flush(MSG_FLUSH); /* Be sure to send all messages */
250257
}
251258

252259
#include "case_N.h"

io.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1985,10 +1985,11 @@ static void sleep_for_bwlimit(int bytes_written)
19851985
void io_flush(int flush_it_all)
19861986
{
19871987
if (iobuf.out.len > iobuf.out_empty_len) {
1988-
if (flush_it_all) /* FULL_FLUSH: flush everything in the output buffers */
1988+
if (flush_it_all == FULL_FLUSH) /* flush everything in the output buffers */
19891989
perform_io(iobuf.out.size - iobuf.out_empty_len, PIO_NEED_OUTROOM);
1990-
else /* NORMAL_FLUSH: flush at least 1 byte */
1990+
else if (flush_it_all == NORMAL_FLUSH) /* flush at least 1 byte */
19911991
perform_io(iobuf.out.size - iobuf.out.len + 1, PIO_NEED_OUTROOM);
1992+
/* MSG_FLUSH: flush iobuf.msg only */
19921993
}
19931994
if (iobuf.msg.len)
19941995
perform_io(iobuf.msg.size, PIO_NEED_MSGROOM);

rsync.h

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
#define ATTRS_SET_NANO (1<<2)
179179
#define ATTRS_SKIP_ATIME (1<<3)
180180

181+
#define MSG_FLUSH 2
181182
#define FULL_FLUSH 1
182183
#define NORMAL_FLUSH 0
183184

0 commit comments

Comments
 (0)