More improvements for abnormal exits.
authorWayne Davison <wayned@samba.org>
Sun, 8 Nov 2009 19:43:16 +0000 (11:43 -0800)
committerWayne Davison <wayned@samba.org>
Sun, 8 Nov 2009 19:45:55 +0000 (11:45 -0800)
cleanup.c
errcode.h
io.c
log.c
rsync.h

index 2b1d697..5d0b92f 100644 (file)
--- a/cleanup.c
+++ b/cleanup.c
@@ -136,17 +136,6 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
                                code, file, line);
                }
 
-               /* FALLTHROUGH */
-#include "case_N.h"
-
-               if (exit_code && exit_code != RERR_RCVR_ERROR
-                && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
-                && (protocol_version >= 31 || (!am_sender && !am_generator))) {
-                       send_msg_int(MSG_ERROR_EXIT, exit_code);
-                       if (am_server && !am_sender && !am_generator)
-                               noop_io_until_death();
-               }
-
                /* FALLTHROUGH */
 #include "case_N.h"
 
@@ -205,7 +194,9 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
                                code = exit_code = RERR_PARTIAL;
                }
 
-               if ((code && code != RERR_RCVR_ERROR)
+               /* If line < 0, this exit is after a MSG_ERROR_EXIT event, so
+                * we don't want to output a duplicate error. */
+               if ((code && line > 0)
                 || am_daemon || (logfile_name && (am_server || !INFO_GTE(STATS, 1))))
                        log_exit(code, file, line);
 
@@ -219,6 +210,16 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
                                unmodified_code, file, line, code);
                }
 
+               /* FALLTHROUGH */
+#include "case_N.h"
+
+               if (exit_code && exit_code != RERR_STREAMIO && exit_code != RERR_SIGNAL1
+                && (protocol_version >= 31 || am_server || (!am_sender && !am_generator))) {
+                       if (line > 0)
+                               send_msg_int(MSG_ERROR_EXIT, exit_code);
+                       noop_io_until_death();
+               }
+
                /* FALLTHROUGH */
 #include "case_N.h"
 
index bae7700..41c5543 100644 (file)
--- a/errcode.h
+++ b/errcode.h
@@ -47,8 +47,6 @@
 #define RERR_TIMEOUT    30      /* timeout in data send/receive */
 #define RERR_CONTIMEOUT 35      /* timeout waiting for daemon connection */
 
-#define RERR_RCVR_ERROR 42      /* receiver is exiting with an error */
-
 /* Although it doesn't seem to be specified anywhere,
  * ssh and the shell seem to return these values:
  *
diff --git a/io.c b/io.c
index b5fd377..d79ec1e 100644 (file)
--- a/io.c
+++ b/io.c
@@ -807,7 +807,7 @@ void noop_io_until_death(void)
        char buf[1024];
 
        kluge_around_eof = 1;
-       set_io_timeout(10);
+       set_io_timeout(protocol_version >= 31 ? 10 : 1);
 
        while (1)
                read_buf(iobuf.in_fd, buf, sizeof buf);
@@ -1438,15 +1438,26 @@ static void read_a_msg(void)
                }
                break;
        case MSG_ERROR_EXIT:
-               if (msg_bytes != 4)
+               if (msg_bytes == 0) {
+                       if (!am_sender && !am_generator) {
+                               send_msg(MSG_ERROR_EXIT, "", 0, 0);
+                               io_flush(FULL_FLUSH);
+                       }
+                       val = 0;
+               } else if (msg_bytes == 4) {
+                       data = perform_io(4, PIO_INPUT_AND_CONSUME);
+                       val = IVAL(data, 0);
+                       if (protocol_version >= 31) {
+                               if (am_generator)
+                                       send_msg_int(MSG_ERROR_EXIT, val);
+                               else
+                                       send_msg(MSG_ERROR_EXIT, "", 0, 0);
+                       }
+               } else
                        goto invalid_msg;
-               data = perform_io(4, PIO_INPUT_AND_CONSUME);
-               val = IVAL(data, 0);
-               if (am_generator && protocol_version >= 31)
-                       send_msg_int(MSG_ERROR_EXIT, val);
-               if (am_generator)
-                       val = RERR_RCVR_ERROR; /* avoids duplicate errors */
-               exit_cleanup(val);
+               /* Send a negative linenum so that we don't end up
+                * with a duplicate exit message. */
+               _exit_cleanup(val, __FILE__, 0 - __LINE__);
        default:
                rprintf(FERROR, "unexpected tag %d [%s%s]\n",
                        tag, who_am_i(), inc_recurse ? "/inc" : "");
diff --git a/log.c b/log.c
index c08dd58..60948e2 100644 (file)
--- a/log.c
+++ b/log.c
@@ -100,7 +100,6 @@ struct {
        { RERR_DEL_LIMIT  , "the --max-delete limit stopped deletions" },
        { RERR_TIMEOUT    , "timeout in data send/receive" },
        { RERR_CONTIMEOUT , "timeout waiting for daemon connection" },
-       { RERR_RCVR_ERROR , "exiting due to receiver error" },
        { RERR_CMD_FAILED , "remote shell failed" },
        { RERR_CMD_KILLED , "remote shell killed" },
        { RERR_CMD_RUN    , "remote command could not be run" },
diff --git a/rsync.h b/rsync.h
index 61f1c47..abdb6e0 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -98,7 +98,7 @@
 /* This is used when working on a new protocol version in CVS, and should
  * be a new non-zero value for each CVS change that affects the protocol.
  * It must ALWAYS be 0 when the protocol goes final (and NEVER before)! */
-#define SUBPROTOCOL_VERSION 11
+#define SUBPROTOCOL_VERSION 12
 
 /* We refuse to interoperate with versions that are not in this range.
  * Note that we assume we'll work with later versions: the onus is on