X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/969cdffbeaaa32e4ef2ef90862b46f686856b042..3f0211b63a6cdc4a2cecfd2a0dffeba172c86a47:/log.c diff --git a/log.c b/log.c index f3a3cff1..fc4b5833 100644 --- a/log.c +++ b/log.c @@ -20,6 +20,7 @@ */ #include "rsync.h" +#include "ifuncs.h" extern int verbose; extern int dry_run; @@ -60,7 +61,7 @@ static int logfile_was_closed; static FILE *logfile_fp; struct stats stats; -int log_got_error = 0; +int got_xfer_error = 0; struct { int code; @@ -234,8 +235,8 @@ static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint) } /* this is the underlying (unformatted) rsync debugging function. Call - * it with FINFO, FERROR or FLOG. Note: recursion can happen with - * certain fatal conditions. */ + * it with FINFO, FERROR_*, FWARNING, FLOG, or FCLIENT. Note: recursion + * can happen with certain fatal conditions. */ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) { int trailing_CR_or_NL; @@ -258,7 +259,7 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) return; } - if (code == FSOCKERR) /* This gets simplified for a non-sibling. */ + if (code == FERROR_SOCKET) /* This gets simplified for a non-sibling. */ code = FERROR; if (code == FCLIENT) @@ -266,7 +267,7 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) else if (am_daemon || logfile_name) { static int in_block; char msg[2048]; - int priority = code == FERROR ? LOG_WARNING : LOG_INFO; + int priority = code == FINFO || code == FLOG ? LOG_INFO : LOG_WARNING; if (in_block) return; @@ -282,12 +283,19 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) } else if (code == FLOG) return; - if (quiet && code != FERROR) + if (quiet && code == FINFO) return; if (am_server) { + enum msgcode msg = (enum msgcode)code; + if (protocol_version < 30) { + if (msg == MSG_ERROR) + msg = MSG_ERROR_XFER; + else if (msg == MSG_WARNING) + msg = MSG_INFO; + } /* Pass the message to the non-server side. */ - if (send_msg((enum msgcode)code, buf, len, !is_utf8)) + if (send_msg(msg, buf, len, !is_utf8)) return; if (am_daemon) { /* TODO: can we send the error to the user somehow? */ @@ -296,8 +304,11 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) } switch (code) { + case FERROR_XFER: + got_xfer_error = 1; + /* CONTINUE */ case FERROR: - log_got_error = 1; + case FWARNING: f = stderr; break; case FINFO: @@ -312,26 +323,25 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) #ifdef ICONV_CONST if (ic != (iconv_t)-1) { + xbuf outbuf, inbuf; char convbuf[1024]; - ICONV_CONST char *in_buf = (ICONV_CONST char *)buf; - char *out_buf = convbuf; - size_t in_cnt = len, out_cnt = sizeof convbuf - 1; - - iconv(ic, NULL, 0, NULL, 0); - while (iconv(ic, &in_buf,&in_cnt, - &out_buf,&out_cnt) == (size_t)-1) { - if (out_buf != convbuf) { - filtered_fwrite(f, convbuf, out_buf - convbuf, 0); - out_buf = convbuf; - out_cnt = sizeof convbuf - 1; + int ierrno; + + INIT_CONST_XBUF(outbuf, convbuf); + INIT_XBUF(inbuf, (char*)buf, len, -1); + + while (inbuf.len) { + iconvbufs(ic, &inbuf, &outbuf, 0); + ierrno = errno; + if (outbuf.len) { + filtered_fwrite(f, convbuf, outbuf.len, 0); + outbuf.len = 0; } - if (errno == E2BIG) + if (!ierrno || ierrno == E2BIG) continue; - fprintf(f, "\\#%03o", *(uchar*)in_buf++); - in_cnt--; + fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++)); + inbuf.len--; } - if (out_buf != convbuf) - filtered_fwrite(f, convbuf, out_buf - convbuf, 0); } else #endif filtered_fwrite(f, buf, len, !allow_8bit_chars); @@ -342,8 +352,8 @@ void rwrite(enum logcode code, const char *buf, int len, int is_utf8) } } -/* This is the rsync debugging function. Call it with FINFO, FERROR or - * FLOG. */ +/* This is the rsync debugging function. Call it with FINFO, FERROR_*, + * FWARNING, FLOG, or FCLIENT. */ void rprintf(enum logcode code, const char *format, ...) { va_list ap; @@ -421,10 +431,10 @@ void rflush(enum logcode code) if (am_daemon || code == FLOG) return; - if (code == FERROR || am_server) - f = stderr; - else + if (code == FINFO && !am_server) f = stdout; + else + f = stderr; fflush(f); } @@ -801,7 +811,7 @@ void log_exit(int code, const char *file, int line) /* VANISHED is not an error, only a warning */ if (code == RERR_VANISHED) { - rprintf(FINFO, "rsync warning: %s (code %d) at %s(%d) [%s=%s]\n", + rprintf(FWARNING, "rsync warning: %s (code %d) at %s(%d) [%s=%s]\n", name, code, file, line, who_am_i(), RSYNC_VERSION); } else { rprintf(FERROR, "rsync error: %s (code %d) at %s(%d) [%s=%s]\n",