Made "log file" and "syslog facility" per-module settings.
[rsync/rsync.git] / log.c
... / ...
CommitLineData
1/*
2 * Logging and utility functions.
3 *
4 * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
5 * Copyright (C) 2000-2001 Martin Pool <mbp@samba.org>
6 * Copyright (C) 2003, 2004, 2005, 2006 Wayne Davison
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#include "rsync.h"
24#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
25#include <iconv.h>
26#endif
27
28extern int verbose;
29extern int dry_run;
30extern int am_daemon;
31extern int am_server;
32extern int am_sender;
33extern int local_server;
34extern int quiet;
35extern int module_id;
36extern int msg_fd_out;
37extern int allow_8bit_chars;
38extern int protocol_version;
39extern int preserve_times;
40extern int stdout_format_has_i;
41extern int stdout_format_has_o_or_i;
42extern int logfile_format_has_i;
43extern int logfile_format_has_o_or_i;
44extern mode_t orig_umask;
45extern char *auth_user;
46extern char *stdout_format;
47extern char *logfile_format;
48extern char *logfile_name;
49#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
50extern iconv_t ic_chck;
51#endif
52
53static int log_initialised;
54static int logfile_was_closed;
55static FILE *logfile_fp;
56struct stats stats;
57
58int log_got_error = 0;
59
60struct {
61 int code;
62 char const *name;
63} const rerr_names[] = {
64 { RERR_SYNTAX , "syntax or usage error" },
65 { RERR_PROTOCOL , "protocol incompatibility" },
66 { RERR_FILESELECT , "errors selecting input/output files, dirs" },
67 { RERR_UNSUPPORTED, "requested action not supported" },
68 { RERR_STARTCLIENT, "error starting client-server protocol" },
69 { RERR_SOCKETIO , "error in socket IO" },
70 { RERR_FILEIO , "error in file IO" },
71 { RERR_STREAMIO , "error in rsync protocol data stream" },
72 { RERR_MESSAGEIO , "errors with program diagnostics" },
73 { RERR_IPC , "error in IPC code" },
74 { RERR_CRASHED , "sibling process crashed" },
75 { RERR_TERMINATED , "sibling process terminated abnormally" },
76 { RERR_SIGNAL1 , "received SIGUSR1" },
77 { RERR_SIGNAL , "received SIGINT, SIGTERM, or SIGHUP" },
78 { RERR_WAITCHILD , "waitpid() failed" },
79 { RERR_MALLOC , "error allocating core memory buffers" },
80 { RERR_PARTIAL , "some files could not be transferred" },
81 { RERR_VANISHED , "some files vanished before they could be transferred" },
82 { RERR_TIMEOUT , "timeout in data send/receive" },
83 { RERR_CMD_FAILED , "remote shell failed" },
84 { RERR_CMD_KILLED , "remote shell killed" },
85 { RERR_CMD_RUN , "remote command could not be run" },
86 { RERR_CMD_NOTFOUND,"remote command not found" },
87 { RERR_DEL_LIMIT , "the --max-delete limit stopped deletions" },
88 { 0, NULL }
89};
90
91
92/*
93 * Map from rsync error code to name, or return NULL.
94 */
95static char const *rerr_name(int code)
96{
97 int i;
98 for (i = 0; rerr_names[i].name; i++) {
99 if (rerr_names[i].code == code)
100 return rerr_names[i].name;
101 }
102 return NULL;
103}
104
105static void logit(int priority, char *buf)
106{
107 if (logfile_was_closed)
108 logfile_reopen();
109 if (logfile_fp) {
110 fprintf(logfile_fp, "%s [%d] %s",
111 timestring(time(NULL)), (int)getpid(), buf);
112 fflush(logfile_fp);
113 } else {
114 syslog(priority, "%s", buf);
115 }
116}
117
118static void syslog_init()
119{
120 static int been_here = 0;
121 int options = LOG_PID;
122
123 if (been_here)
124 return;
125 been_here = 1;
126
127#ifdef LOG_NDELAY
128 options |= LOG_NDELAY;
129#endif
130
131#ifdef LOG_DAEMON
132 openlog("rsyncd", options, lp_syslog_facility());
133#else
134 openlog("rsyncd", options);
135#endif
136
137#ifndef LOG_NDELAY
138 logit(LOG_INFO, "rsyncd started\n");
139#endif
140}
141
142static void logfile_open(void)
143{
144 mode_t old_umask = umask(022 | orig_umask);
145 logfile_fp = fopen(logfile_name, "a");
146 umask(old_umask);
147 if (!logfile_fp) {
148 int fopen_errno = errno;
149 /* Rsync falls back to using syslog on failure. */
150 syslog_init();
151 rsyserr(FERROR, fopen_errno,
152 "failed to open log-file %s", logfile_name);
153 rprintf(FINFO, "Ignoring \"log file\" setting.\n");
154 }
155}
156
157void log_init(void)
158{
159 if (log_initialised)
160 return;
161 log_initialised = 1;
162
163 /* This looks pointless, but it is needed in order for the
164 * C library on some systems to fetch the timezone info
165 * before the chroot. */
166 timestring(time(NULL));
167
168 /* Optionally use a log file instead of syslog. (Non-daemon
169 * rsyncs will have already set logfile_name, as needed.) */
170 if (am_daemon && !logfile_name)
171 logfile_name = lp_log_file();
172 if (logfile_name && *logfile_name)
173 logfile_open();
174 else
175 syslog_init();
176}
177
178void logfile_close(void)
179{
180 if (logfile_fp) {
181 logfile_was_closed = 1;
182 fclose(logfile_fp);
183 logfile_fp = NULL;
184 }
185}
186
187void logfile_reopen(void)
188{
189 if (logfile_was_closed) {
190 logfile_was_closed = 0;
191 logfile_open();
192 }
193}
194
195static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
196{
197 const char *s, *end = buf + len;
198 for (s = buf; s < end; s++) {
199 if ((s < end - 4
200 && *s == '\\' && s[1] == '#'
201 && isdigit(*(uchar*)(s+2))
202 && isdigit(*(uchar*)(s+3))
203 && isdigit(*(uchar*)(s+4)))
204 || (*s != '\t'
205 && ((use_isprint && !isprint(*(uchar*)s))
206 || *(uchar*)s < ' '))) {
207 if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
208 exit_cleanup(RERR_MESSAGEIO);
209 fprintf(f, "\\#%03o", *(uchar*)s);
210 buf = s + 1;
211 }
212 }
213 if (buf != end && fwrite(buf, end - buf, 1, f) != 1)
214 exit_cleanup(RERR_MESSAGEIO);
215}
216
217/* this is the underlying (unformatted) rsync debugging function. Call
218 * it with FINFO, FERROR or FLOG. Note: recursion can happen with
219 * certain fatal conditions. */
220void rwrite(enum logcode code, char *buf, int len)
221{
222 int trailing_CR_or_NL;
223 FILE *f = NULL;
224
225 if (len < 0)
226 exit_cleanup(RERR_MESSAGEIO);
227
228 if (am_server && msg_fd_out >= 0) {
229 /* Pass the message to our sibling. */
230 send_msg((enum msgcode)code, buf, len);
231 return;
232 }
233
234 if (code == FSOCKERR) /* This gets simplified for a non-sibling. */
235 code = FERROR;
236
237 if (code == FCLIENT)
238 code = FINFO;
239 else if (am_daemon || logfile_name) {
240 static int in_block;
241 char msg[2048];
242 int priority = code == FERROR ? LOG_WARNING : LOG_INFO;
243
244 if (in_block)
245 return;
246 in_block = 1;
247 if (!log_initialised)
248 log_init();
249 strlcpy(msg, buf, MIN((int)sizeof msg, len + 1));
250 logit(priority, msg);
251 in_block = 0;
252
253 if (code == FLOG || (am_daemon && !am_server))
254 return;
255 } else if (code == FLOG)
256 return;
257
258 if (quiet && code != FERROR)
259 return;
260
261 if (am_server) {
262 /* Pass the message to the non-server side. */
263 if (send_msg((enum msgcode)code, buf, len))
264 return;
265 if (am_daemon) {
266 /* TODO: can we send the error to the user somehow? */
267 return;
268 }
269 }
270
271 switch (code) {
272 case FERROR:
273 log_got_error = 1;
274 f = stderr;
275 break;
276 case FINFO:
277 f = am_server ? stderr : stdout;
278 break;
279 default:
280 exit_cleanup(RERR_MESSAGEIO);
281 }
282
283 trailing_CR_or_NL = len && (buf[len-1] == '\n' || buf[len-1] == '\r')
284 ? buf[--len] : 0;
285
286#if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H
287 if (ic_chck != (iconv_t)-1) {
288 char convbuf[1024];
289 char *in_buf = buf, *out_buf = convbuf;
290 size_t in_cnt = len, out_cnt = sizeof convbuf - 1;
291
292 iconv(ic_chck, NULL, 0, NULL, 0);
293 while (iconv(ic_chck, &in_buf,&in_cnt,
294 &out_buf,&out_cnt) == (size_t)-1) {
295 if (out_buf != convbuf) {
296 filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
297 out_buf = convbuf;
298 out_cnt = sizeof convbuf - 1;
299 }
300 if (errno == E2BIG)
301 continue;
302 fprintf(f, "\\#%03o", *(uchar*)in_buf++);
303 in_cnt--;
304 }
305 if (out_buf != convbuf)
306 filtered_fwrite(f, convbuf, out_buf - convbuf, 0);
307 } else
308#endif
309 filtered_fwrite(f, buf, len, !allow_8bit_chars);
310
311 if (trailing_CR_or_NL) {
312 fputc(trailing_CR_or_NL, f);
313 fflush(f);
314 }
315}
316
317/* This is the rsync debugging function. Call it with FINFO, FERROR or
318 * FLOG. */
319void rprintf(enum logcode code, const char *format, ...)
320{
321 va_list ap;
322 char buf[BIGPATHBUFLEN];
323 size_t len;
324
325 va_start(ap, format);
326 len = vsnprintf(buf, sizeof buf, format, ap);
327 va_end(ap);
328
329 /* Deal with buffer overruns. Instead of panicking, just
330 * truncate the resulting string. (Note that configure ensures
331 * that we have a vsnprintf() that doesn't ever return -1.) */
332 if (len > sizeof buf - 1) {
333 static const char ellipsis[] = "[...]";
334
335 /* Reset length, and zero-terminate the end of our buffer */
336 len = sizeof buf - 1;
337 buf[len] = '\0';
338
339 /* Copy the ellipsis to the end of the string, but give
340 * us one extra character:
341 *
342 * v--- null byte at buf[sizeof buf - 1]
343 * abcdefghij0
344 * -> abcd[...]00 <-- now two null bytes at end
345 *
346 * If the input format string has a trailing newline,
347 * we copy it into that extra null; if it doesn't, well,
348 * all we lose is one byte. */
349 memcpy(buf+len-sizeof ellipsis, ellipsis, sizeof ellipsis);
350 if (format[strlen(format)-1] == '\n') {
351 buf[len-1] = '\n';
352 }
353 }
354
355 rwrite(code, buf, len);
356}
357
358/* This is like rprintf, but it also tries to print some
359 * representation of the error code. Normally errcode = errno.
360 *
361 * Unlike rprintf, this always adds a newline and there should not be
362 * one in the format string.
363 *
364 * Note that since strerror might involve dynamically loading a
365 * message catalog we need to call it once before chroot-ing. */
366void rsyserr(enum logcode code, int errcode, const char *format, ...)
367{
368 va_list ap;
369 char buf[BIGPATHBUFLEN];
370 size_t len;
371
372 strcpy(buf, RSYNC_NAME ": ");
373 len = (sizeof RSYNC_NAME ": ") - 1;
374
375 va_start(ap, format);
376 len += vsnprintf(buf + len, sizeof buf - len, format, ap);
377 va_end(ap);
378
379 if (len < sizeof buf) {
380 len += snprintf(buf + len, sizeof buf - len,
381 ": %s (%d)\n", strerror(errcode), errcode);
382 }
383 if (len >= sizeof buf)
384 exit_cleanup(RERR_MESSAGEIO);
385
386 rwrite(code, buf, len);
387}
388
389void rflush(enum logcode code)
390{
391 FILE *f = NULL;
392
393 if (am_daemon || code == FLOG)
394 return;
395
396 if (code == FERROR || am_server)
397 f = stderr;
398 else
399 f = stdout;
400
401 fflush(f);
402}
403
404/* A generic logging routine for send/recv, with parameter substitiution. */
405static void log_formatted(enum logcode code, char *format, char *op,
406 struct file_struct *file, struct stats *initial_stats,
407 int iflags, char *hlink)
408{
409 char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];
410 char *p, *s, *n;
411 size_t len, total;
412 int64 b;
413
414 *fmt = '%';
415
416 /* We expand % codes one by one in place in buf. We don't
417 * copy in the terminating null of the inserted strings, but
418 * rather keep going until we reach the null of the format. */
419 total = strlcpy(buf, format, sizeof buf);
420 if (total > MAXPATHLEN) {
421 rprintf(FERROR, "log-format string is WAY too long!\n");
422 exit_cleanup(RERR_MESSAGEIO);
423 }
424 buf[total++] = '\n';
425 buf[total] = '\0';
426
427 for (p = buf; (p = strchr(p, '%')) != NULL; ) {
428 s = p++;
429 n = fmt + 1;
430 if (*p == '-')
431 *n++ = *p++;
432 while (isdigit(*(uchar*)p) && n - fmt < (int)(sizeof fmt) - 8)
433 *n++ = *p++;
434 if (!*p)
435 break;
436 *n = '\0';
437 n = NULL;
438
439 switch (*p) {
440 case 'h':
441 if (am_daemon)
442 n = client_name(0);
443 break;
444 case 'a':
445 if (am_daemon)
446 n = client_addr(0);
447 break;
448 case 'l':
449 strlcat(fmt, ".0f", sizeof fmt);
450 snprintf(buf2, sizeof buf2, fmt,
451 (double)file->length);
452 n = buf2;
453 break;
454 case 'U':
455 strlcat(fmt, "ld", sizeof fmt);
456 snprintf(buf2, sizeof buf2, fmt,
457 (long)file->uid);
458 n = buf2;
459 break;
460 case 'G':
461 if (file->gid == GID_NONE)
462 n = "DEFAULT";
463 else {
464 strlcat(fmt, "ld", sizeof fmt);
465 snprintf(buf2, sizeof buf2, fmt,
466 (long)file->gid);
467 n = buf2;
468 }
469 break;
470 case 'p':
471 strlcat(fmt, "ld", sizeof fmt);
472 snprintf(buf2, sizeof buf2, fmt,
473 (long)getpid());
474 n = buf2;
475 break;
476 case 'M':
477 n = timestring(file->modtime);
478 {
479 char *cp = n;
480 while ((cp = strchr(cp, ' ')) != NULL)
481 *cp = '-';
482 }
483 break;
484 case 'B':
485 n = buf2 + MAXPATHLEN - PERMSTRING_SIZE;
486 permstring(n - 1, file->mode); /* skip the type char */
487 break;
488 case 'o':
489 n = op;
490 break;
491 case 'f':
492 n = f_name(file, NULL);
493 if (am_sender && file->dir.root) {
494 pathjoin(buf2, sizeof buf2,
495 file->dir.root, n);
496 clean_fname(buf2, 0);
497 if (fmt[1])
498 strlcpy(n, buf2, MAXPATHLEN);
499 else
500 n = buf2;
501 } else
502 clean_fname(n, 0);
503 if (*n == '/')
504 n++;
505 break;
506 case 'n':
507 n = f_name(file, NULL);
508 if (S_ISDIR(file->mode))
509 strlcat(n, "/", MAXPATHLEN);
510 break;
511 case 'L':
512 if (hlink && *hlink) {
513 n = hlink;
514 strcpy(buf2, " => ");
515 } else if (S_ISLNK(file->mode) && file->u.link) {
516 n = file->u.link;
517 strcpy(buf2, " -> ");
518 } else {
519 n = "";
520 if (!fmt[1])
521 break;
522 strcpy(buf2, " ");
523 }
524 strlcat(fmt, "s", sizeof fmt);
525 snprintf(buf2 + 4, sizeof buf2 - 4, fmt, n);
526 n = buf2;
527 break;
528 case 'm':
529 n = lp_name(module_id);
530 break;
531 case 't':
532 n = timestring(time(NULL));
533 break;
534 case 'P':
535 n = lp_path(module_id);
536 break;
537 case 'u':
538 n = auth_user;
539 break;
540 case 'b':
541 if (am_sender) {
542 b = stats.total_written -
543 initial_stats->total_written;
544 } else {
545 b = stats.total_read -
546 initial_stats->total_read;
547 }
548 strlcat(fmt, ".0f", sizeof fmt);
549 snprintf(buf2, sizeof buf2, fmt, (double)b);
550 n = buf2;
551 break;
552 case 'c':
553 if (!am_sender) {
554 b = stats.total_written -
555 initial_stats->total_written;
556 } else {
557 b = stats.total_read -
558 initial_stats->total_read;
559 }
560 strlcat(fmt, ".0f", sizeof fmt);
561 snprintf(buf2, sizeof buf2, fmt, (double)b);
562 n = buf2;
563 break;
564 case 'i':
565 if (iflags & ITEM_DELETED) {
566 n = "*deleting";
567 break;
568 }
569 n = buf2 + MAXPATHLEN - 32;
570 n[0] = iflags & ITEM_LOCAL_CHANGE
571 ? iflags & ITEM_XNAME_FOLLOWS ? 'h' : 'c'
572 : !(iflags & ITEM_TRANSFER) ? '.'
573 : !local_server && *op == 's' ? '<' : '>';
574 n[1] = S_ISDIR(file->mode) ? 'd'
575 : IS_SPECIAL(file->mode) ? 'S'
576 : IS_DEVICE(file->mode) ? 'D'
577 : S_ISLNK(file->mode) ? 'L' : 'f';
578 n[2] = !(iflags & ITEM_REPORT_CHECKSUM) ? '.' : 'c';
579 n[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';
580 n[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
581 : !preserve_times || S_ISLNK(file->mode) ? 'T' : 't';
582 n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';
583 n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o';
584 n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g';
585 n[8] = '.';
586 n[9] = '\0';
587
588 if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) {
589 char ch = iflags & ITEM_IS_NEW ? '+' : '?';
590 int i;
591 for (i = 2; n[i]; i++)
592 n[i] = ch;
593 } else if (n[0] == '.' || n[0] == 'h'
594 || (n[0] == 'c' && n[1] == 'f')) {
595 int i;
596 for (i = 2; n[i]; i++) {
597 if (n[i] != '.')
598 break;
599 }
600 if (!n[i]) {
601 for (i = 2; n[i]; i++)
602 n[i] = ' ';
603 }
604 }
605 break;
606 }
607
608 /* "n" is the string to be inserted in place of this % code. */
609 if (!n)
610 continue;
611 if (n != buf2 && fmt[1]) {
612 strlcat(fmt, "s", sizeof fmt);
613 snprintf(buf2, sizeof buf2, fmt, n);
614 n = buf2;
615 }
616 len = strlen(n);
617
618 /* Subtract the length of the escape from the string's size. */
619 total -= p - s + 1;
620
621 if (len + total >= (size_t)sizeof buf) {
622 rprintf(FERROR,
623 "buffer overflow expanding %%%c -- exiting\n",
624 p[0]);
625 exit_cleanup(RERR_MESSAGEIO);
626 }
627
628 /* Shuffle the rest of the string along to make space for n */
629 if (len != (size_t)(p - s + 1))
630 memmove(s + len, p + 1, total - (s - buf) + 1);
631 total += len;
632
633 /* Insert the contents of string "n", but NOT its null. */
634 if (len)
635 memcpy(s, n, len);
636
637 /* Skip over inserted string; continue looking */
638 p = s + len;
639 }
640
641 rwrite(code, buf, total);
642}
643
644/* Return 1 if the format escape is in the log-format string (e.g. look for
645 * the 'b' in the "%9b" format escape). */
646int log_format_has(const char *format, char esc)
647{
648 const char *p;
649
650 if (!format)
651 return 0;
652
653 for (p = format; (p = strchr(p, '%')) != NULL; ) {
654 if (*++p == '-')
655 p++;
656 while (isdigit(*(uchar*)p))
657 p++;
658 if (!*p)
659 break;
660 if (*p == esc)
661 return 1;
662 }
663 return 0;
664}
665
666/* Log the transfer of a file. If the code is FCLIENT, the output just goes
667 * to stdout. If it is FLOG, it just goes to the log file. Otherwise we
668 * output to both. */
669void log_item(enum logcode code, struct file_struct *file,
670 struct stats *initial_stats, int iflags, char *hlink)
671{
672 char *s_or_r = am_sender ? "send" : "recv";
673
674 if (code != FLOG && stdout_format && !am_server) {
675 log_formatted(FCLIENT, stdout_format, s_or_r,
676 file, initial_stats, iflags, hlink);
677 }
678 if (code != FCLIENT && logfile_format && *logfile_format) {
679 log_formatted(FLOG, logfile_format, s_or_r,
680 file, initial_stats, iflags, hlink);
681 }
682}
683
684void maybe_log_item(struct file_struct *file, int iflags, int itemizing,
685 char *buf)
686{
687 int significant_flags = iflags & SIGNIFICANT_ITEM_FLAGS;
688 int see_item = itemizing && (significant_flags || *buf
689 || stdout_format_has_i > 1 || (verbose > 1 && stdout_format_has_i));
690 int local_change = iflags & ITEM_LOCAL_CHANGE && significant_flags;
691 if (am_server) {
692 if (logfile_name && !dry_run && see_item
693 && (significant_flags || logfile_format_has_i))
694 log_item(FLOG, file, &stats, iflags, buf);
695 } else if (see_item || local_change || *buf
696 || (S_ISDIR(file->mode) && significant_flags)) {
697 enum logcode code = significant_flags || logfile_format_has_i ? FINFO : FCLIENT;
698 log_item(code, file, &stats, iflags, buf);
699 }
700}
701
702void log_delete(char *fname, int mode)
703{
704 static struct file_struct file;
705 int len = strlen(fname);
706 char *fmt;
707
708 file.mode = mode;
709 file.basename = fname;
710
711 if (!verbose && !stdout_format)
712 ;
713 else if (am_server && protocol_version >= 29 && len < MAXPATHLEN) {
714 if (S_ISDIR(mode))
715 len++; /* directories include trailing null */
716 send_msg(MSG_DELETED, fname, len);
717 } else {
718 fmt = stdout_format_has_o_or_i ? stdout_format : "deleting %n";
719 log_formatted(FCLIENT, fmt, "del.", &file, &stats,
720 ITEM_DELETED, NULL);
721 }
722
723 if (!logfile_name || dry_run || !logfile_format)
724 return;
725
726 fmt = logfile_format_has_o_or_i ? logfile_format : "deleting %n";
727 log_formatted(FLOG, fmt, "del.", &file, &stats, ITEM_DELETED, NULL);
728}
729
730/*
731 * Called when the transfer is interrupted for some reason.
732 *
733 * Code is one of the RERR_* codes from errcode.h, or terminating
734 * successfully.
735 */
736void log_exit(int code, const char *file, int line)
737{
738 if (code == 0) {
739 rprintf(FLOG,"sent %.0f bytes received %.0f bytes total size %.0f\n",
740 (double)stats.total_written,
741 (double)stats.total_read,
742 (double)stats.total_size);
743 } else {
744 const char *name;
745
746 name = rerr_name(code);
747 if (!name)
748 name = "unexplained error";
749
750 /* VANISHED is not an error, only a warning */
751 if (code == RERR_VANISHED) {
752 rprintf(FINFO, "rsync warning: %s (code %d) at %s(%d) [%s=%s]\n",
753 name, code, file, line, who_am_i(), RSYNC_VERSION);
754 } else {
755 rprintf(FERROR, "rsync error: %s (code %d) at %s(%d) [%s=%s]\n",
756 name, code, file, line, who_am_i(), RSYNC_VERSION);
757 }
758 }
759}