Go to the source code of this file.
Data Structures | |
struct | err_list |
Functions | |
char const * | rerr_name (int code) |
void | err_list_add (int code, char *buf, int len) |
void | err_list_push (void) |
void | logit (int priority, char *buf) |
void | log_init (void) |
void | log_open () |
void | log_close () |
void | set_error_fd (int fd) |
void | rwrite (enum logcode code, char *buf, int len) |
void | rprintf (enum logcode code, const char *format,...) |
void | rsyserr (enum logcode code, int errcode, const char *format,...) |
void | rflush (enum logcode code) |
void | log_formatted (enum logcode code, char *format, char *op, struct file_struct *file, struct stats *initial_stats) |
void | log_send (struct file_struct *file, struct stats *initial_stats) |
void | log_recv (struct file_struct *file, struct stats *initial_stats) |
void | log_exit (int code, const char *file, int line) |
void | log_transfer (struct file_struct *file, const char *fname) |
Variables | |
char * | logfname |
FILE * | logfile |
int | log_error_fd = -1 |
stats | stats |
int | log_got_error = 0 |
struct { | |
int code | |
char const * name | |
} | rerr_names [] |
err_list * | err_list_head |
err_list * | err_list_tail |
|
Definition at line 68 of file log.c. References code, and rerr_names. Referenced by log_exit().
00069 { 00070 int i; 00071 for (i = 0; rerr_names[i].name; i++) { 00072 if (rerr_names[i].code == code) 00073 return rerr_names[i].name; 00074 } 00075 return NULL; 00076 } |
|
Definition at line 89 of file log.c. References err_list::buf, code, err_list::len, err_list::next, and err_list::written. Referenced by rwrite().
00090 { 00091 struct err_list *el; 00092 el = (struct err_list *)malloc(sizeof(*el)); 00093 if (!el) exit_cleanup(RERR_MALLOC); 00094 el->next = NULL; 00095 el->buf = malloc(len+4); 00096 if (!el->buf) exit_cleanup(RERR_MALLOC); 00097 memcpy(el->buf+4, buf, len); 00098 SIVAL(el->buf, 0, ((code+MPLEX_BASE)<<24) | len); 00099 el->len = len+4; 00100 el->written = 0; 00101 if (err_list_tail) { 00102 err_list_tail->next = el; 00103 } else { 00104 err_list_head = el; 00105 } 00106 err_list_tail = el; 00107 } |
|
Definition at line 111 of file log.c. References err_list::buf, err_list::len, log_error_fd, err_list::next, and err_list::written. Referenced by check_timeout(), io_flush(), rwrite(), writefd(), and writefd_unbuffered().
00112 { 00113 if (log_error_fd == -1) return; 00114 00115 while (err_list_head) { 00116 struct err_list *el = err_list_head; 00117 int n = write(log_error_fd, el->buf+el->written, el->len - el->written); 00118 /* don't check for an error if the best way of handling the error is 00119 to ignore it */ 00120 if (n == -1) break; 00121 if (n > 0) { 00122 el->written += n; 00123 } 00124 if (el->written == el->len) { 00125 free(el->buf); 00126 err_list_head = el->next; 00127 if (!err_list_head) err_list_tail = NULL; 00128 free(el); 00129 } 00130 } 00131 } |
|
Definition at line 134 of file log.c. References log_open(), logfile, and timestring(). Referenced by log_init(), and rwrite().
00135 { 00136 if (logfname) { 00137 if (!logfile) 00138 log_open(); 00139 fprintf(logfile,"%s [%d] %s", 00140 timestring(time(NULL)), (int)getpid(), buf); 00141 fflush(logfile); 00142 } else { 00143 syslog(priority, "%s", buf); 00144 } 00145 } |
|
Definition at line 147 of file log.c. References log_open(), logfname, and logit(). Referenced by daemon_main(), rsync_module(), and rwrite().
00148 { 00149 static int initialised; 00150 int options = LOG_PID; 00151 time_t t; 00152 00153 if (initialised) return; 00154 initialised = 1; 00155 00156 /* this looks pointless, but it is needed in order for the 00157 C library on some systems to fetch the timezone info 00158 before the chroot */ 00159 t = time(NULL); 00160 localtime(&t); 00161 00162 /* optionally use a log file instead of syslog */ 00163 logfname = lp_log_file(); 00164 if (logfname) { 00165 if (*logfname) { 00166 log_open(); 00167 return; 00168 } 00169 logfname = NULL; 00170 } 00171 00172 #ifdef LOG_NDELAY 00173 options |= LOG_NDELAY; 00174 #endif 00175 00176 #ifdef LOG_DAEMON 00177 openlog("rsyncd", options, lp_syslog_facility()); 00178 #else 00179 openlog("rsyncd", options); 00180 #endif 00181 00182 #ifndef LOG_NDELAY 00183 logit(LOG_INFO,"rsyncd started\n"); 00184 #endif 00185 } |
|
Definition at line 187 of file log.c. References logfile, logfname, and orig_umask. Referenced by log_init(), logit(), and start_accept_loop().
00188 { 00189 if (logfname && !logfile) { 00190 extern int orig_umask; 00191 int old_umask = umask(022 | orig_umask); 00192 logfile = fopen(logfname, "a"); 00193 umask(old_umask); 00194 } 00195 } |
|
Definition at line 197 of file log.c. References logfile. Referenced by start_accept_loop().
|
|
Definition at line 207 of file log.c. References log_error_fd, and set_nonblocking(). Referenced by do_recv().
00208 { 00209 log_error_fd = fd; 00210 set_nonblocking(log_error_fd); 00211 } |
|
Definition at line 215 of file log.c. References am_daemon, code, err_list_add(), err_list_push(), FERROR, FINFO, FLOG, io_multiplex_write(), log_error_fd, log_got_error, log_init(), logcode, logit(), and quiet. Referenced by read_error_fd(), rprintf(), and rsyserr().
00216 { 00217 FILE *f=NULL; 00218 extern int am_daemon; 00219 extern int am_server; 00220 extern int quiet; 00221 /* recursion can happen with certain fatal conditions */ 00222 00223 if (quiet && code == FINFO) return; 00224 00225 if (len < 0) exit_cleanup(RERR_MESSAGEIO); 00226 00227 buf[len] = 0; 00228 00229 if (code == FLOG) { 00230 if (am_daemon) logit(LOG_INFO, buf); 00231 return; 00232 } 00233 00234 /* first try to pass it off to our sibling */ 00235 if (am_server && log_error_fd != -1) { 00236 err_list_add(code, buf, len); 00237 err_list_push(); 00238 return; 00239 } 00240 00241 /* If that fails, try to pass it to the other end. 00242 * 00243 * io_multiplex_write can fail if we do not have a multiplexed 00244 * connection at the moment, in which case we fall through and 00245 * log locally instead. */ 00246 if (am_server && io_multiplex_write(code, buf, len)) { 00247 return; 00248 } 00249 00250 if (am_daemon) { 00251 static int depth; 00252 int priority = LOG_INFO; 00253 if (code == FERROR) priority = LOG_WARNING; 00254 00255 if (depth) return; 00256 00257 depth++; 00258 00259 log_init(); 00260 logit(priority, buf); 00261 00262 depth--; 00263 return; 00264 } 00265 00266 if (code == FERROR) { 00267 log_got_error = 1; 00268 f = stderr; 00269 } 00270 00271 if (code == FINFO) { 00272 if (am_server) 00273 f = stderr; 00274 else 00275 f = stdout; 00276 } 00277 00278 if (!f) exit_cleanup(RERR_MESSAGEIO); 00279 00280 if (fwrite(buf, len, 1, f) != 1) exit_cleanup(RERR_MESSAGEIO); 00281 00282 if (buf[len-1] == '\r' || buf[len-1] == '\n') fflush(f); 00283 } |
|
Definition at line 288 of file log.c. References code, logcode, rwrite(), and vsnprintf().
00289 { 00290 va_list ap; 00291 char buf[1024]; 00292 int len; 00293 00294 va_start(ap, format); 00295 /* Note: might return -1 */ 00296 len = vsnprintf(buf, sizeof(buf), format, ap); 00297 va_end(ap); 00298 00299 /* Deal with buffer overruns. Instead of panicking, just 00300 * truncate the resulting string. Note that some vsnprintf()s 00301 * return -1 on truncation, e.g., glibc 2.0.6 and earlier. */ 00302 if ((size_t) len > sizeof(buf)-1 || len < 0) { 00303 const char ellipsis[] = "[...]"; 00304 00305 /* Reset length, and zero-terminate the end of our buffer */ 00306 len = sizeof(buf)-1; 00307 buf[len] = '\0'; 00308 00309 /* Copy the ellipsis to the end of the string, but give 00310 * us one extra character: 00311 * 00312 * v--- null byte at buf[sizeof(buf)-1] 00313 * abcdefghij0 00314 * -> abcd[...]00 <-- now two null bytes at end 00315 * 00316 * If the input format string has a trailing newline, 00317 * we copy it into that extra null; if it doesn't, well, 00318 * all we lose is one byte. */ 00319 strncpy(buf+len-sizeof(ellipsis), ellipsis, sizeof(ellipsis)); 00320 if (format[strlen(format)-1] == '\n') { 00321 buf[len-1] = '\n'; 00322 } 00323 } 00324 00325 rwrite(code, buf, len); 00326 } |
|
Definition at line 337 of file log.c. References code, logcode, rwrite(), and vsnprintf().
00338 { 00339 va_list ap; 00340 char buf[1024]; 00341 int len; 00342 size_t sys_len; 00343 char *sysmsg; 00344 00345 va_start(ap, format); 00346 /* Note: might return <0 */ 00347 len = vsnprintf(buf, sizeof(buf), format, ap); 00348 va_end(ap); 00349 00350 /* TODO: Put in RSYNC_NAME at the start. */ 00351 00352 if ((size_t) len > sizeof(buf)-1) 00353 exit_cleanup(RERR_MESSAGEIO); 00354 00355 sysmsg = strerror(errcode); 00356 sys_len = strlen(sysmsg); 00357 if ((size_t) len + 3 + sys_len > sizeof(buf) - 1) 00358 exit_cleanup(RERR_MESSAGEIO); 00359 00360 strcpy(buf + len, ": "); 00361 len += 2; 00362 strcpy(buf + len, sysmsg); 00363 len += sys_len; 00364 strcpy(buf + len, "\n"); 00365 len++; 00366 00367 rwrite(code, buf, len); 00368 } |
|
Definition at line 372 of file log.c. References am_daemon, code, FERROR, FINFO, FLOG, and logcode. Referenced by start_filelist_progress().
00373 { 00374 FILE *f = NULL; 00375 extern int am_daemon; 00376 00377 if (am_daemon) { 00378 return; 00379 } 00380 00381 if (code == FLOG) { 00382 return; 00383 } 00384 00385 if (code == FERROR) { 00386 f = stderr; 00387 } 00388 00389 if (code == FINFO) { 00390 extern int am_server; 00391 if (am_server) 00392 f = stderr; 00393 else 00394 f = stdout; 00395 } 00396 00397 if (!f) exit_cleanup(RERR_MESSAGEIO); 00398 fflush(f); 00399 } |
|
Definition at line 405 of file log.c. References am_daemon, am_sender, auth_user, file_struct::basedir, clean_fname(), client_addr(), client_name(), code, f_name(), FERROR, file_struct::length, logcode, memmove(), rprintf(), snprintf(), strlcpy(), timestring(), stats::total_read, and stats::total_written. Referenced by log_recv(), and log_send().
00408 { 00409 extern int module_id; 00410 extern char *auth_user; 00411 char buf[1024]; 00412 char buf2[1024]; 00413 char *p, *s, *n; 00414 size_t l; 00415 extern struct stats stats; 00416 extern int am_sender; 00417 extern int am_daemon; 00418 int64 b; 00419 00420 /* We expand % codes one by one in place in buf. We don't 00421 * copy in the terminating nul of the inserted strings, but 00422 * rather keep going until we reach the nul of the format. 00423 * Just to make sure we don't clobber that nul and therefore 00424 * accidentally keep going, we zero the buffer now. */ 00425 memset(buf, 0, sizeof buf); 00426 strlcpy(buf, format, sizeof(buf)); 00427 00428 for (s=&buf[0]; 00429 s && (p=strchr(s,'%')); ) { 00430 n = NULL; 00431 s = p + 1; 00432 00433 switch (p[1]) { 00434 case 'h': if (am_daemon) n = client_name(0); break; 00435 case 'a': if (am_daemon) n = client_addr(0); break; 00436 case 'l': 00437 snprintf(buf2,sizeof(buf2),"%.0f", 00438 (double)file->length); 00439 n = buf2; 00440 break; 00441 case 'p': 00442 snprintf(buf2,sizeof(buf2),"%d", 00443 (int)getpid()); 00444 n = buf2; 00445 break; 00446 case 'o': n = op; break; 00447 case 'f': 00448 snprintf(buf2, sizeof(buf2), "%s/%s", 00449 file->basedir?file->basedir:"", 00450 f_name(file)); 00451 clean_fname(buf2); 00452 n = buf2; 00453 if (*n == '/') n++; 00454 break; 00455 case 'm': n = lp_name(module_id); break; 00456 case 't': n = timestring(time(NULL)); break; 00457 case 'P': n = lp_path(module_id); break; 00458 case 'u': n = auth_user; break; 00459 case 'b': 00460 if (am_sender) { 00461 b = stats.total_written - 00462 initial_stats->total_written; 00463 } else { 00464 b = stats.total_read - 00465 initial_stats->total_read; 00466 } 00467 snprintf(buf2,sizeof(buf2),"%.0f", (double)b); 00468 n = buf2; 00469 break; 00470 case 'c': 00471 if (!am_sender) { 00472 b = stats.total_written - 00473 initial_stats->total_written; 00474 } else { 00475 b = stats.total_read - 00476 initial_stats->total_read; 00477 } 00478 snprintf(buf2,sizeof(buf2),"%.0f", (double)b); 00479 n = buf2; 00480 break; 00481 } 00482 00483 /* n is the string to be inserted in place of this % 00484 * code; l is its length not including the trailing 00485 * NUL */ 00486 if (!n) 00487 continue; 00488 00489 l = strlen(n); 00490 00491 if (l + ((int)(s - &buf[0])) >= sizeof(buf)) { 00492 rprintf(FERROR,"buffer overflow expanding %%%c - exiting\n", 00493 p[0]); 00494 exit_cleanup(RERR_MESSAGEIO); 00495 } 00496 00497 /* Shuffle the rest of the string along to make space for n */ 00498 if (l != 2) { 00499 memmove(s+(l-1), s+1, strlen(s+1)+1); 00500 } 00501 00502 /* Copy in n but NOT its nul, because the format sting 00503 * probably continues after this. */ 00504 memcpy(p, n, l); 00505 00506 /* Skip over inserted string; continue looking */ 00507 s = p+l; 00508 } 00509 00510 rprintf(code,"%s\n", buf); 00511 } |
|
Definition at line 514 of file log.c. References FINFO, FLOG, log_format, and log_formatted(). Referenced by send_files().
00515 { 00516 extern int module_id; 00517 extern int am_server; 00518 extern char *log_format; 00519 00520 if (lp_transfer_logging(module_id)) { 00521 log_formatted(FLOG, lp_log_format(module_id), "send", file, initial_stats); 00522 } else if (log_format && !am_server) { 00523 log_formatted(FINFO, log_format, "send", file, initial_stats); 00524 } 00525 } |
|
Definition at line 528 of file log.c. References FINFO, FLOG, log_format, and log_formatted(). Referenced by recv_files().
00529 { 00530 extern int module_id; 00531 extern int am_server; 00532 extern char *log_format; 00533 00534 if (lp_transfer_logging(module_id)) { 00535 log_formatted(FLOG, lp_log_format(module_id), "recv", file, initial_stats); 00536 } else if (log_format && !am_server) { 00537 log_formatted(FINFO, log_format, "recv", file, initial_stats); 00538 } 00539 } |
|
Definition at line 550 of file log.c. References code, FERROR, FLOG, name, rerr_name(), rprintf(), stats::total_read, stats::total_size, and stats::total_written. Referenced by _exit_cleanup(), and report().
00551 { 00552 if (code == 0) { 00553 extern struct stats stats; 00554 rprintf(FLOG,"wrote %.0f bytes read %.0f bytes total size %.0f\n", 00555 (double)stats.total_written, 00556 (double)stats.total_read, 00557 (double)stats.total_size); 00558 } else { 00559 const char *name; 00560 00561 name = rerr_name(code); 00562 if (!name) 00563 name = "unexplained error"; 00564 00565 rprintf(FERROR,"rsync error: %s (code %d) at %s(%d)\n", 00566 name, code, file, line); 00567 } 00568 } |
|
Definition at line 575 of file log.c. References FINFO, and rprintf(). Referenced by recv_files(), and send_files().
|
|
|
|
|
|
Definition at line 32 of file log.c. Referenced by err_list_push(), rwrite(), and set_error_fd(). |
|
|
|
Definition at line 35 of file log.c. Referenced by _exit_cleanup(), rwrite(), and sigusr2_handler(). |
|
Definition at line 38 of file log.c. Referenced by _exit_cleanup(), err_list_add(), io_multiplex_write(), log_exit(), log_formatted(), mplex_write(), rerr_name(), rflush(), rprintf(), rsyserr(), and rwrite(). |
|
Definition at line 39 of file log.c. Referenced by log_exit(). |
|
Referenced by rerr_name(). |
|
|
|
|