Commit aa3999d6 authored by Wayne Davison's avatar Wayne Davison

Fix the val reading for MSG_ERROR_EXIT. Use 0-length MSG_DATA when

MSG_NOOP is not available (is both safer and supports older rsyncs).
parent 6e9ad2bb
...@@ -896,7 +896,7 @@ void noop_io_until_death(void) ...@@ -896,7 +896,7 @@ void noop_io_until_death(void)
read_buf(iobuf.in_fd, buf, sizeof buf); read_buf(iobuf.in_fd, buf, sizeof buf);
} }
/* Buffer a message for the multiplexed output stream. Is never used for MSG_DATA. */ /* Buffer a message for the multiplexed output stream. Is not used for (normal) MSG_DATA. */
int send_msg(enum msgcode code, const char *buf, size_t len, int convert) int send_msg(enum msgcode code, const char *buf, size_t len, int convert)
{ {
char *hdr; char *hdr;
...@@ -958,8 +958,8 @@ int send_msg(enum msgcode code, const char *buf, size_t len, int convert) ...@@ -958,8 +958,8 @@ int send_msg(enum msgcode code, const char *buf, size_t len, int convert)
{ {
size_t siz; size_t siz;
if ((pos += 4) >= iobuf.msg.size) if ((pos += 4) == iobuf.msg.size)
pos -= iobuf.msg.size; pos = 0;
/* Handle a split copy if we wrap around the end of the circular buffer. */ /* Handle a split copy if we wrap around the end of the circular buffer. */
if (pos >= iobuf.msg.pos && (siz = iobuf.msg.size - pos) < len) { if (pos >= iobuf.msg.pos && (siz = iobuf.msg.size - pos) < len) {
...@@ -1313,18 +1313,16 @@ void maybe_flush_socket(int important) ...@@ -1313,18 +1313,16 @@ void maybe_flush_socket(int important)
io_flush(NORMAL_FLUSH); io_flush(NORMAL_FLUSH);
} }
/* This never adds new non-msg-buffer data, since we don't know the state
* of the raw-data buffer. */
void maybe_send_keepalive(void) void maybe_send_keepalive(void)
{ {
if (time(NULL) - last_io_out >= allowed_lull) { if (time(NULL) - last_io_out >= allowed_lull) {
if (!iobuf.msg.len && iobuf.out.len == iobuf.out_empty_len) { if (!iobuf.msg.len && iobuf.out.len == iobuf.out_empty_len) {
if (protocol_version < 29)
return; /* there's nothing we can do */
if (protocol_version >= 30) if (protocol_version >= 30)
send_msg(MSG_NOOP, "", 0, 0); send_msg(MSG_NOOP, "", 0, 0);
else { else
write_int(iobuf.out_fd, cur_flist->used); send_msg(MSG_DATA, "", 0, 0);
write_shortint(iobuf.out_fd, ITEM_IS_NEW);
}
} }
if (iobuf.msg.len) if (iobuf.msg.len)
perform_io(iobuf.msg.size - iobuf.msg.len + 1, PIO_NEED_MSGROOM); perform_io(iobuf.msg.size - iobuf.msg.len + 1, PIO_NEED_MSGROOM);
...@@ -1373,7 +1371,8 @@ static void read_a_msg(void) ...@@ -1373,7 +1371,8 @@ static void read_a_msg(void)
* possible that this points off the end of the buffer, in * possible that this points off the end of the buffer, in
* which case the gradual reading of the input stream will * which case the gradual reading of the input stream will
* cause this value to decrease and eventually become real. */ * cause this value to decrease and eventually become real. */
iobuf.raw_input_ends_before = iobuf.in.pos + msg_bytes; if (msg_bytes)
iobuf.raw_input_ends_before = iobuf.in.pos + msg_bytes;
iobuf.in_multiplexed = 1; iobuf.in_multiplexed = 1;
break; break;
case MSG_STATS: case MSG_STATS:
...@@ -1410,9 +1409,11 @@ static void read_a_msg(void) ...@@ -1410,9 +1409,11 @@ static void read_a_msg(void)
} }
break; break;
case MSG_NOOP: case MSG_NOOP:
if (msg_bytes != 0)
goto invalid_msg;
iobuf.in_multiplexed = 1;
if (am_sender) if (am_sender)
maybe_send_keepalive(); maybe_send_keepalive();
iobuf.in_multiplexed = 1;
break; break;
case MSG_DELETED: case MSG_DELETED:
if (msg_bytes >= sizeof data) if (msg_bytes >= sizeof data)
...@@ -1543,23 +1544,19 @@ static void read_a_msg(void) ...@@ -1543,23 +1544,19 @@ static void read_a_msg(void)
send_msg(MSG_ERROR_EXIT, "", 0, 0); send_msg(MSG_ERROR_EXIT, "", 0, 0);
io_flush(FULL_FLUSH); io_flush(FULL_FLUSH);
} }
val = 0; } else if (protocol_version >= 31) {
} else { if (am_generator) {
val = raw_read_int(); if (DEBUG_GTE(EXIT, 3)) {
if (protocol_version >= 31) { rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n",
if (am_generator) { who_am_i(), val);
if (DEBUG_GTE(EXIT, 3)) { }
rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT with exit_code %d\n", send_msg_int(MSG_ERROR_EXIT, val);
who_am_i(), val); } else {
} if (DEBUG_GTE(EXIT, 3)) {
send_msg_int(MSG_ERROR_EXIT, val); rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT (len 0)\n",
} else { who_am_i());
if (DEBUG_GTE(EXIT, 3)) {
rprintf(FINFO, "[%s] sending MSG_ERROR_EXIT (len 0)\n",
who_am_i());
}
send_msg(MSG_ERROR_EXIT, "", 0, 0);
} }
send_msg(MSG_ERROR_EXIT, "", 0, 0);
} }
} }
/* Send a negative linenum so that we don't end up /* Send a negative linenum so that we don't end up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment