Correctly send last error to sender
authorbenrubson <6764151+benrubson@users.noreply.github.com>
Tue, 26 May 2020 14:24:30 +0000 (16:24 +0200)
committerbenrubson <6764151+benrubson@users.noreply.github.com>
Tue, 26 May 2020 14:24:30 +0000 (16:24 +0200)
cleanup.c
io.c
rsync.h

index fbf7c60b12d302a2ee4d35e89943cc2e2c8b72b4..b477e6603b2a24a8197bdea06d476539a1685351 100644 (file)
--- a/cleanup.c
+++ b/cleanup.c
@@ -26,6 +26,7 @@ extern int dry_run;
 extern int am_server;
 extern int am_daemon;
 extern int am_receiver;
+extern int am_sender;
 extern int io_error;
 extern int keep_partial;
 extern int got_xfer_error;
@@ -238,15 +239,21 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
                switch_step++;
 
                if (exit_code && exit_code != RERR_SOCKETIO && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
-                && exit_code != RERR_TIMEOUT && !shutting_down && (protocol_version >= 31 || am_receiver)) {
-                       if (line > 0) {
-                               if (DEBUG_GTE(EXIT, 3)) {
-                                       rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
-                                               who_am_i(), exit_code);
+                && exit_code != RERR_TIMEOUT && !shutting_down) {
+                       if (protocol_version >= 31 || am_receiver) {
+                               if (line > 0) {
+                                       if (DEBUG_GTE(EXIT, 3)) {
+                                               rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
+                                                       who_am_i(), exit_code);
+                                       }
+                                       send_msg_int(MSG_ERROR_EXIT, exit_code);
                                }
-                               send_msg_int(MSG_ERROR_EXIT, exit_code);
+                               if (!am_sender)
+                                       io_flush(MSG_FLUSH); /* Be sure to send all messages */
+                               noop_io_until_death();
                        }
-                       noop_io_until_death();
+                       else if (!am_sender)
+                               io_flush(MSG_FLUSH); /* Be sure to send all messages */
                }
 
 #include "case_N.h"
diff --git a/io.c b/io.c
index 01d6152f40d224c12f40fc79dd4e46a5e4ed6ca2..947daa635d3ef8ede51758dc19f25cae195b68d8 100644 (file)
--- a/io.c
+++ b/io.c
@@ -1985,10 +1985,11 @@ static void sleep_for_bwlimit(int bytes_written)
 void io_flush(int flush_it_all)
 {
        if (iobuf.out.len > iobuf.out_empty_len) {
-               if (flush_it_all) /* FULL_FLUSH: flush everything in the output buffers */
+               if (flush_it_all == FULL_FLUSH)        /* flush everything in the output buffers */
                        perform_io(iobuf.out.size - iobuf.out_empty_len, PIO_NEED_OUTROOM);
-               else /* NORMAL_FLUSH: flush at least 1 byte */
+               else if (flush_it_all == NORMAL_FLUSH) /* flush at least 1 byte */
                        perform_io(iobuf.out.size - iobuf.out.len + 1, PIO_NEED_OUTROOM);
+                                                      /* MSG_FLUSH: flush iobuf.msg only */
        }
        if (iobuf.msg.len)
                perform_io(iobuf.msg.size, PIO_NEED_MSGROOM);
diff --git a/rsync.h b/rsync.h
index 210cef4084dc071b17ed0c6c3ab62fbb272bcd85..06f6d338359eed1aa6c793abb07dd1ddf65d9f12 100644 (file)
--- a/rsync.h
+++ b/rsync.h
 #define ATTRS_SET_NANO         (1<<2)
 #define ATTRS_SKIP_ATIME       (1<<3)
 
+#define MSG_FLUSH      2
 #define FULL_FLUSH     1
 #define NORMAL_FLUSH   0