From 304d7b5817d6e1d3cf59b9edae2213433d901cdc Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 8 Nov 2009 11:43:16 -0800 Subject: [PATCH] More improvements for abnormal exits. --- cleanup.c | 25 +++++++++++++------------ errcode.h | 2 -- io.c | 29 ++++++++++++++++++++--------- log.c | 1 - rsync.h | 2 +- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/cleanup.c b/cleanup.c index 2b1d6974..5d0b92f8 100644 --- 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" diff --git a/errcode.h b/errcode.h index bae7700c..41c55432 100644 --- 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 b5fd3776..d79ec1eb 100644 --- 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 c08dd580..60948e2f 100644 --- 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 61f1c47c..abdb6e02 100644 --- 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 -- 2.34.1