Commit | Line | Data |
---|---|---|
a039749b | 1 | /* -*- c-file-style: "linux"; -*- |
4a7319be | 2 | |
0c5a792a | 3 | Copyright (C) 1998-2001 by Andrew Tridgell <tridge@samba.org> |
18c71e96 | 4 | Copyright (C) 2000-2001 by Martin Pool <mbp@samba.org> |
4a7319be | 5 | |
0b76cd63 AT |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
4a7319be | 10 | |
0b76cd63 AT |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
4a7319be | 15 | |
0b76cd63 AT |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 | */ | |
20 | ||
21 | /* | |
3e3dcd62 | 22 | Logging and utility functions. |
0c5a792a | 23 | tridge, May 1998 |
0b76cd63 | 24 | |
3e3dcd62 MP |
25 | Mapping to human-readable messages added by Martin Pool |
26 | <mbp@samba.org>, Oct 2000. | |
0b76cd63 AT |
27 | */ |
28 | #include "rsync.h" | |
29 | ||
ef74f5d6 | 30 | extern int dry_run; |
548abf96 WD |
31 | extern int am_daemon; |
32 | extern int am_server; | |
33 | extern int am_sender; | |
34 | extern int quiet; | |
35 | extern int module_id; | |
a644fc3c | 36 | extern int msg_fd_out; |
ef74f5d6 | 37 | extern int preserve_times; |
548abf96 WD |
38 | extern char *auth_user; |
39 | extern char *log_format; | |
40 | ||
30e8c8e1 | 41 | static int log_initialised; |
45a83540 | 42 | static char *logfname; |
4f6325c3 | 43 | static FILE *logfile; |
b35d0d8e | 44 | struct stats stats; |
e0414f42 | 45 | |
8fcdc444 | 46 | int log_got_error = 0; |
af642a61 MP |
47 | |
48 | struct { | |
49 | int code; | |
50 | char const *name; | |
51 | } const rerr_names[] = { | |
4a7319be WD |
52 | { RERR_SYNTAX , "syntax or usage error" }, |
53 | { RERR_PROTOCOL , "protocol incompatibility" }, | |
54 | { RERR_FILESELECT , "errors selecting input/output files, dirs" }, | |
55 | { RERR_UNSUPPORTED, "requested action not supported" }, | |
56 | { RERR_STARTCLIENT, "error starting client-server protocol" }, | |
57 | { RERR_SOCKETIO , "error in socket IO" }, | |
58 | { RERR_FILEIO , "error in file IO" }, | |
59 | { RERR_STREAMIO , "error in rsync protocol data stream" }, | |
60 | { RERR_MESSAGEIO , "errors with program diagnostics" }, | |
61 | { RERR_IPC , "error in IPC code" }, | |
62 | { RERR_SIGNAL , "received SIGUSR1 or SIGINT" }, | |
63 | { RERR_WAITCHILD , "some error returned by waitpid()" }, | |
64 | { RERR_MALLOC , "error allocating core memory buffers" }, | |
65 | { RERR_PARTIAL , "some files could not be transferred" }, | |
584ba4eb | 66 | { RERR_VANISHED , "some files vanished before they could be transferred" }, |
4a7319be | 67 | { RERR_TIMEOUT , "timeout in data send/receive" }, |
19b27a48 AT |
68 | { RERR_CMD_FAILED , "remote shell failed" }, |
69 | { RERR_CMD_KILLED , "remote shell killed" }, | |
70 | { RERR_CMD_RUN, "remote command could not be run" }, | |
4a7319be WD |
71 | { RERR_CMD_NOTFOUND, "remote command not found" }, |
72 | { 0, NULL } | |
af642a61 MP |
73 | }; |
74 | ||
75 | ||
76 | ||
77 | /* | |
78 | * Map from rsync error code to name, or return NULL. | |
79 | */ | |
80 | static char const *rerr_name(int code) | |
81 | { | |
4a7319be WD |
82 | int i; |
83 | for (i = 0; rerr_names[i].name; i++) { | |
84 | if (rerr_names[i].code == code) | |
85 | return rerr_names[i].name; | |
86 | } | |
87 | return NULL; | |
af642a61 MP |
88 | } |
89 | ||
2267efea | 90 | void log_open(void) |
63ecee4d WD |
91 | { |
92 | if (logfname && !logfile) { | |
93 | extern int orig_umask; | |
94 | int old_umask = umask(022 | orig_umask); | |
95 | logfile = fopen(logfname, "a"); | |
96 | umask(old_umask); | |
97 | if (!logfile) { | |
98 | am_daemon = 0; /* avoid trying to log again */ | |
99 | rsyserr(FERROR, errno, "fopen() of log-file failed"); | |
100 | exit_cleanup(RERR_FILESELECT); | |
101 | } | |
102 | } | |
103 | } | |
af642a61 | 104 | |
2267efea WD |
105 | void log_close(void) |
106 | { | |
107 | if (logfile) { | |
108 | fclose(logfile); | |
109 | logfile = NULL; | |
110 | } | |
111 | } | |
112 | ||
4f6325c3 AT |
113 | static void logit(int priority, char *buf) |
114 | { | |
45a83540 | 115 | if (logfname) { |
15b84e14 DD |
116 | if (!logfile) |
117 | log_open(); | |
4a7319be | 118 | fprintf(logfile,"%s [%d] %s", |
f7632fc6 | 119 | timestring(time(NULL)), (int)getpid(), buf); |
4f6325c3 AT |
120 | fflush(logfile); |
121 | } else { | |
122 | syslog(priority, "%s", buf); | |
123 | } | |
124 | } | |
e42c9458 | 125 | |
45a83540 | 126 | void log_init(void) |
1a016bfd | 127 | { |
1a016bfd | 128 | int options = LOG_PID; |
bcf5b133 | 129 | time_t t; |
1a016bfd | 130 | |
0bb4d176 WD |
131 | if (log_initialised) |
132 | return; | |
30e8c8e1 | 133 | log_initialised = 1; |
1a016bfd | 134 | |
958f3735 | 135 | /* this looks pointless, but it is needed in order for the |
4a7319be WD |
136 | * C library on some systems to fetch the timezone info |
137 | * before the chroot */ | |
958f3735 AT |
138 | t = time(NULL); |
139 | localtime(&t); | |
140 | ||
141 | /* optionally use a log file instead of syslog */ | |
45a83540 DD |
142 | logfname = lp_log_file(); |
143 | if (logfname) { | |
15b84e14 DD |
144 | if (*logfname) { |
145 | log_open(); | |
45a83540 | 146 | return; |
15b84e14 | 147 | } |
45a83540 | 148 | logfname = NULL; |
4f6325c3 AT |
149 | } |
150 | ||
1a016bfd AT |
151 | #ifdef LOG_NDELAY |
152 | options |= LOG_NDELAY; | |
153 | #endif | |
154 | ||
155 | #ifdef LOG_DAEMON | |
156 | openlog("rsyncd", options, lp_syslog_facility()); | |
157 | #else | |
158 | openlog("rsyncd", options); | |
159 | #endif | |
160 | ||
161 | #ifndef LOG_NDELAY | |
4f6325c3 | 162 | logit(LOG_INFO,"rsyncd started\n"); |
1a016bfd AT |
163 | #endif |
164 | } | |
1a016bfd | 165 | |
554e0a8d | 166 | /* this is the underlying (unformatted) rsync debugging function. Call |
4a7319be | 167 | * it with FINFO, FERROR or FLOG */ |
ff41a59f | 168 | void rwrite(enum logcode code, char *buf, int len) |
0b76cd63 | 169 | { |
8fcdc444 | 170 | FILE *f = NULL; |
8d9dc9f9 | 171 | /* recursion can happen with certain fatal conditions */ |
8d9dc9f9 | 172 | |
a644fc3c WD |
173 | if (quiet && code == FINFO) |
174 | return; | |
b86f0cef | 175 | |
a644fc3c WD |
176 | if (len < 0) |
177 | exit_cleanup(RERR_MESSAGEIO); | |
0b76cd63 | 178 | |
ff8b29b8 AT |
179 | buf[len] = 0; |
180 | ||
0bb4d176 WD |
181 | if (am_server && msg_fd_out >= 0) { |
182 | /* Pass the message to our sibling. */ | |
183 | send_msg((enum msgcode)code, buf, len); | |
11a5a3c7 AT |
184 | return; |
185 | } | |
186 | ||
0bb4d176 WD |
187 | if (am_daemon) { |
188 | static int in_block; | |
189 | char msg[2048]; | |
190 | int priority = code == FERROR ? LOG_WARNING : LOG_INFO; | |
191 | ||
192 | if (in_block) | |
a644fc3c | 193 | return; |
0bb4d176 WD |
194 | in_block = 1; |
195 | if (!log_initialised) | |
196 | log_init(); | |
197 | strlcpy(msg, buf, MIN((int)sizeof msg, len + 1)); | |
198 | logit(priority, msg); | |
199 | in_block = 0; | |
200 | ||
201 | if (code == FLOG || !am_server) | |
a644fc3c | 202 | return; |
0bb4d176 | 203 | } else if (code == FLOG) |
ff8b29b8 | 204 | return; |
0bb4d176 WD |
205 | |
206 | if (am_server) { | |
207 | /* Pass the message to the non-server side. */ | |
208 | if (io_multiplex_write((enum msgcode)code, buf, len)) | |
209 | return; | |
210 | if (am_daemon) { | |
211 | /* TODO: can we send the error to the user somehow? */ | |
212 | return; | |
213 | } | |
0b76cd63 AT |
214 | } |
215 | ||
ff41a59f | 216 | if (code == FERROR) { |
ff81e809 | 217 | log_got_error = 1; |
ff8b29b8 | 218 | f = stderr; |
4a7319be | 219 | } |
ff8b29b8 | 220 | |
0bb4d176 WD |
221 | if (code == FINFO) |
222 | f = am_server ? stderr : stdout; | |
ff8b29b8 | 223 | |
0bb4d176 WD |
224 | if (!f) |
225 | exit_cleanup(RERR_MESSAGEIO); | |
0b76cd63 | 226 | |
0bb4d176 WD |
227 | if (fwrite(buf, len, 1, f) != 1) |
228 | exit_cleanup(RERR_MESSAGEIO); | |
8d9dc9f9 | 229 | |
0bb4d176 WD |
230 | if (buf[len-1] == '\r' || buf[len-1] == '\n') |
231 | fflush(f); | |
0b76cd63 | 232 | } |
554e0a8d AT |
233 | |
234 | ||
a039749b MP |
235 | /* This is the rsync debugging function. Call it with FINFO, FERROR or |
236 | * FLOG. */ | |
237 | void rprintf(enum logcode code, const char *format, ...) | |
554e0a8d | 238 | { |
4a7319be | 239 | va_list ap; |
8fcdc444 WD |
240 | char buf[MAXPATHLEN+512]; |
241 | size_t len; | |
554e0a8d AT |
242 | |
243 | va_start(ap, format); | |
ef74f5d6 | 244 | len = vsnprintf(buf, sizeof buf, format, ap); |
554e0a8d AT |
245 | va_end(ap); |
246 | ||
b2f02464 | 247 | /* Deal with buffer overruns. Instead of panicking, just |
8fcdc444 WD |
248 | * truncate the resulting string. (Note that configure ensures |
249 | * that we have a vsnprintf() that doesn't ever return -1.) */ | |
250 | if (len > sizeof buf - 1) { | |
b2f02464 MP |
251 | const char ellipsis[] = "[...]"; |
252 | ||
253 | /* Reset length, and zero-terminate the end of our buffer */ | |
ef74f5d6 | 254 | len = sizeof buf - 1; |
b2f02464 MP |
255 | buf[len] = '\0'; |
256 | ||
257 | /* Copy the ellipsis to the end of the string, but give | |
258 | * us one extra character: | |
259 | * | |
ef74f5d6 | 260 | * v--- null byte at buf[sizeof buf - 1] |
b2f02464 MP |
261 | * abcdefghij0 |
262 | * -> abcd[...]00 <-- now two null bytes at end | |
263 | * | |
264 | * If the input format string has a trailing newline, | |
265 | * we copy it into that extra null; if it doesn't, well, | |
266 | * all we lose is one byte. */ | |
ef74f5d6 | 267 | strncpy(buf+len-sizeof ellipsis, ellipsis, sizeof ellipsis); |
b2f02464 MP |
268 | if (format[strlen(format)-1] == '\n') { |
269 | buf[len-1] = '\n'; | |
270 | } | |
271 | } | |
554e0a8d | 272 | |
ff41a59f | 273 | rwrite(code, buf, len); |
554e0a8d | 274 | } |
0b76cd63 | 275 | |
a039749b MP |
276 | |
277 | /* This is like rprintf, but it also tries to print some | |
278 | * representation of the error code. Normally errcode = errno. | |
279 | * | |
280 | * Unlike rprintf, this always adds a newline and there should not be | |
281 | * one in the format string. | |
282 | * | |
283 | * Note that since strerror might involve dynamically loading a | |
284 | * message catalog we need to call it once before chroot-ing. */ | |
285 | void rsyserr(enum logcode code, int errcode, const char *format, ...) | |
286 | { | |
4a7319be | 287 | va_list ap; |
8fcdc444 WD |
288 | char buf[MAXPATHLEN+512]; |
289 | size_t len; | |
290 | ||
291 | strcpy(buf, RSYNC_NAME ": "); | |
292 | len = (sizeof RSYNC_NAME ": ") - 1; | |
a039749b MP |
293 | |
294 | va_start(ap, format); | |
8fcdc444 | 295 | len += vsnprintf(buf + len, sizeof buf - len, format, ap); |
a039749b MP |
296 | va_end(ap); |
297 | ||
8fcdc444 WD |
298 | if (len < sizeof buf) { |
299 | len += snprintf(buf + len, sizeof buf - len, | |
300 | ": %s (%d)\n", strerror(errcode), errcode); | |
301 | } | |
302 | if (len >= sizeof buf) | |
4a7319be | 303 | exit_cleanup(RERR_MESSAGEIO); |
a039749b | 304 | |
a039749b MP |
305 | rwrite(code, buf, len); |
306 | } | |
307 | ||
308 | ||
309 | ||
ff41a59f | 310 | void rflush(enum logcode code) |
0b76cd63 AT |
311 | { |
312 | FILE *f = NULL; | |
0b76cd63 AT |
313 | |
314 | if (am_daemon) { | |
315 | return; | |
316 | } | |
317 | ||
ff41a59f | 318 | if (code == FLOG) { |
e08bfe12 | 319 | return; |
4a7319be | 320 | } |
e08bfe12 | 321 | |
ff41a59f | 322 | if (code == FERROR) { |
0b76cd63 | 323 | f = stderr; |
4a7319be | 324 | } |
0b76cd63 | 325 | |
ff41a59f | 326 | if (code == FINFO) { |
4a7319be | 327 | if (am_server) |
0b76cd63 AT |
328 | f = stderr; |
329 | else | |
330 | f = stdout; | |
4a7319be | 331 | } |
0b76cd63 | 332 | |
65417579 | 333 | if (!f) exit_cleanup(RERR_MESSAGEIO); |
0b76cd63 AT |
334 | fflush(f); |
335 | } | |
336 | ||
11a5a3c7 | 337 | |
e08bfe12 AT |
338 | |
339 | /* a generic logging routine for send/recv, with parameter | |
4a7319be | 340 | * substitiution */ |
0f3203c3 | 341 | static void log_formatted(enum logcode code, |
b6062654 | 342 | char *format, char *op, struct file_struct *file, |
ef74f5d6 | 343 | struct stats *initial_stats, int iflags) |
e08bfe12 | 344 | { |
ef74f5d6 | 345 | char buf[MAXPATHLEN+1024]; |
e66d70e3 | 346 | char buf2[MAXPATHLEN]; |
ef74f5d6 WD |
347 | char *p, *n; |
348 | size_t len, total; | |
1b7c47cb | 349 | int64 b; |
e08bfe12 | 350 | |
aa126974 MP |
351 | /* We expand % codes one by one in place in buf. We don't |
352 | * copy in the terminating nul of the inserted strings, but | |
ef74f5d6 WD |
353 | * rather keep going until we reach the nul of the format. */ |
354 | total = strlcpy(buf, format, sizeof buf); | |
e08bfe12 | 355 | |
ef74f5d6 | 356 | for (p = buf; (p = strchr(p, '%')) != NULL && p[1]; ) { |
e08bfe12 | 357 | n = NULL; |
e08bfe12 AT |
358 | |
359 | switch (p[1]) { | |
af77cc6b AT |
360 | case 'h': if (am_daemon) n = client_name(0); break; |
361 | case 'a': if (am_daemon) n = client_addr(0); break; | |
4a7319be | 362 | case 'l': |
ef74f5d6 | 363 | snprintf(buf2, sizeof buf2, "%.0f", |
4a7319be | 364 | (double)file->length); |
e08bfe12 AT |
365 | n = buf2; |
366 | break; | |
4a7319be | 367 | case 'p': |
ef74f5d6 | 368 | snprintf(buf2, sizeof buf2, "%d", |
4a7319be | 369 | (int)getpid()); |
e08bfe12 AT |
370 | n = buf2; |
371 | break; | |
372 | case 'o': n = op; break; | |
4a7319be | 373 | case 'f': |
81d2b0ef | 374 | pathjoin(buf2, sizeof buf2, |
c32edbe0 | 375 | am_sender && file->dir.root ? file->dir.root : "", |
4875d6b6 | 376 | safe_fname(f_name(file))); |
58b1999e | 377 | clean_fname(buf2, 0); |
4a7319be | 378 | n = buf2; |
b6062654 | 379 | if (*n == '/') n++; |
ab7104da | 380 | break; |
ef74f5d6 WD |
381 | case 'n': |
382 | n = (char*)safe_fname(f_name(file)); | |
e66d70e3 WD |
383 | if (S_ISDIR(file->mode)) { |
384 | /* The buffer from safe_fname() has more | |
385 | * room than MAXPATHLEN, so this is safe. */ | |
386 | strcat(n, "/"); | |
387 | } | |
ef74f5d6 WD |
388 | break; |
389 | case 'L': | |
390 | if (S_ISLNK(file->mode)) { | |
391 | snprintf(buf2, sizeof buf2, " -> %s", | |
392 | safe_fname(file->u.link)); | |
393 | n = buf2; | |
394 | } else | |
395 | n = ""; | |
396 | break; | |
97cb8dc2 | 397 | case 'm': n = lp_name(module_id); break; |
b6062654 | 398 | case 't': n = timestring(time(NULL)); break; |
97cb8dc2 AT |
399 | case 'P': n = lp_path(module_id); break; |
400 | case 'u': n = auth_user; break; | |
4a7319be | 401 | case 'b': |
1b7c47cb | 402 | if (am_sender) { |
4a7319be | 403 | b = stats.total_written - |
1b7c47cb AT |
404 | initial_stats->total_written; |
405 | } else { | |
4a7319be | 406 | b = stats.total_read - |
1b7c47cb AT |
407 | initial_stats->total_read; |
408 | } | |
ef74f5d6 | 409 | snprintf(buf2, sizeof buf2, "%.0f", (double)b); |
1b7c47cb AT |
410 | n = buf2; |
411 | break; | |
4a7319be | 412 | case 'c': |
1b7c47cb | 413 | if (!am_sender) { |
4a7319be | 414 | b = stats.total_written - |
1b7c47cb AT |
415 | initial_stats->total_written; |
416 | } else { | |
4a7319be | 417 | b = stats.total_read - |
1b7c47cb AT |
418 | initial_stats->total_read; |
419 | } | |
ef74f5d6 | 420 | snprintf(buf2, sizeof buf2, "%.0f", (double)b); |
1b7c47cb AT |
421 | n = buf2; |
422 | break; | |
ef74f5d6 WD |
423 | case 'i': |
424 | n = buf2; | |
d4e01963 WD |
425 | n[0] = !(iflags & ITEM_UPDATING) ? ' ' |
426 | : dry_run ? '*' | |
427 | : *op == 's' ? '>' : '<'; | |
ef74f5d6 WD |
428 | n[1] = S_ISDIR(file->mode) ? 'd' : IS_DEVICE(file->mode) ? 'D' |
429 | : S_ISLNK(file->mode) ? 'L' : 'f'; | |
d4e01963 WD |
430 | n[2] = !(iflags & ITEM_REPORT_CHECKSUM) ? '.' : 'c'; |
431 | n[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's'; | |
432 | n[4] = !(iflags & ITEM_REPORT_TIME) ? '.' | |
ef74f5d6 WD |
433 | : !preserve_times || IS_DEVICE(file->mode) |
434 | || S_ISLNK(file->mode) ? 'T' : 't'; | |
d4e01963 WD |
435 | n[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p'; |
436 | n[6] = !(iflags & ITEM_REPORT_OWNER) ? '.' : 'o'; | |
437 | n[7] = !(iflags & ITEM_REPORT_GROUP) ? '.' : 'g'; | |
ef74f5d6 WD |
438 | n[8] = '\0'; |
439 | ||
440 | if (iflags & (ITEM_IS_NEW|ITEM_MISSING_DATA)) { | |
441 | char ch = iflags & ITEM_IS_NEW ? '+' : '?'; | |
442 | int i; | |
443 | for (i = 2; n[i]; i++) | |
444 | n[i] = ch; | |
445 | } | |
446 | break; | |
e08bfe12 AT |
447 | } |
448 | ||
aa126974 | 449 | /* n is the string to be inserted in place of this % |
ef74f5d6 | 450 | * code; len is its length not including the trailing |
aa126974 | 451 | * NUL */ |
ef74f5d6 WD |
452 | if (!n) { |
453 | p += 2; | |
aa126974 | 454 | continue; |
ef74f5d6 | 455 | } |
e08bfe12 | 456 | |
ef74f5d6 | 457 | len = strlen(n); |
e08bfe12 | 458 | |
ef74f5d6 | 459 | if (len + total - 2 >= sizeof buf) { |
1e7098b5 WD |
460 | rprintf(FERROR, |
461 | "buffer overflow expanding %%%c -- exiting\n", | |
e08bfe12 | 462 | p[0]); |
65417579 | 463 | exit_cleanup(RERR_MESSAGEIO); |
e08bfe12 AT |
464 | } |
465 | ||
aa126974 | 466 | /* Shuffle the rest of the string along to make space for n */ |
ef74f5d6 WD |
467 | if (len != 2) |
468 | memmove(p + len, p + 2, total - (p + 2 - buf) + 1); | |
469 | total += len - 2; | |
aa126974 | 470 | |
ef74f5d6 WD |
471 | /* Insert the contents of string "n", but NOT its nul. */ |
472 | if (len) | |
473 | memcpy(p, n, len); | |
e08bfe12 | 474 | |
aa126974 | 475 | /* Skip over inserted string; continue looking */ |
ef74f5d6 | 476 | p += len; |
e08bfe12 AT |
477 | } |
478 | ||
ef74f5d6 | 479 | rprintf(code, "%s\n", buf); |
e08bfe12 AT |
480 | } |
481 | ||
11a5a3c7 | 482 | /* log the outgoing transfer of a file */ |
ef74f5d6 | 483 | void log_send(struct file_struct *file, struct stats *initial_stats, int iflags) |
11a5a3c7 | 484 | { |
11a5a3c7 | 485 | if (lp_transfer_logging(module_id)) { |
ef74f5d6 WD |
486 | log_formatted(FLOG, lp_log_format(module_id), "send", |
487 | file, initial_stats, iflags); | |
b6062654 | 488 | } else if (log_format && !am_server) { |
ef74f5d6 WD |
489 | log_formatted(FINFO, log_format, "send", |
490 | file, initial_stats, iflags); | |
11a5a3c7 AT |
491 | } |
492 | } | |
493 | ||
494 | /* log the incoming transfer of a file */ | |
ef74f5d6 | 495 | void log_recv(struct file_struct *file, struct stats *initial_stats, int iflags) |
11a5a3c7 | 496 | { |
11a5a3c7 | 497 | if (lp_transfer_logging(module_id)) { |
ef74f5d6 WD |
498 | log_formatted(FLOG, lp_log_format(module_id), "recv", |
499 | file, initial_stats, iflags); | |
b6062654 | 500 | } else if (log_format && !am_server) { |
ef74f5d6 WD |
501 | log_formatted(FINFO, log_format, "recv", |
502 | file, initial_stats, iflags); | |
11a5a3c7 AT |
503 | } |
504 | } | |
505 | ||
af642a61 MP |
506 | |
507 | ||
508 | ||
509 | /* | |
510 | * Called when the transfer is interrupted for some reason. | |
511 | * | |
512 | * Code is one of the RERR_* codes from errcode.h, or terminating | |
513 | * successfully. | |
514 | */ | |
a9766ef1 | 515 | void log_exit(int code, const char *file, int line) |
9b73d1c0 AT |
516 | { |
517 | if (code == 0) { | |
67ea0d48 | 518 | rprintf(FLOG,"wrote %.0f bytes read %.0f bytes total size %.0f\n", |
9b73d1c0 AT |
519 | (double)stats.total_written, |
520 | (double)stats.total_read, | |
521 | (double)stats.total_size); | |
522 | } else { | |
4a7319be WD |
523 | const char *name; |
524 | ||
525 | name = rerr_name(code); | |
526 | if (!name) | |
527 | name = "unexplained error"; | |
af642a61 | 528 | |
1bca1de6 WD |
529 | /* VANISHED is not an error, only a warning */ |
530 | if (code == RERR_VANISHED) { | |
531 | rprintf(FINFO, "rsync warning: %s (code %d) at %s(%d)\n", | |
532 | name, code, file, line); | |
533 | } else { | |
534 | rprintf(FERROR, "rsync error: %s (code %d) at %s(%d)\n", | |
535 | name, code, file, line); | |
536 | } | |
9b73d1c0 AT |
537 | } |
538 | } |