X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/d0133e6ebac72b659d773b059032d56faa3a0314..5e1f082d0c0af5fdb8096023772eb4f5013f78a0:/log.c diff --git a/log.c b/log.c index 64e584b0..1c577efb 100644 --- a/log.c +++ b/log.c @@ -49,6 +49,8 @@ extern char *logfile_name; #if defined HAVE_ICONV_OPEN && defined HAVE_ICONV_H extern iconv_t ic_chck; #endif +extern char curr_dir[]; +extern unsigned int module_dirlen; static int log_initialised; static int logfile_was_closed; @@ -129,7 +131,7 @@ static void syslog_init() #endif #ifdef LOG_DAEMON - openlog("rsyncd", options, lp_syslog_facility()); + openlog("rsyncd", options, lp_syslog_facility(module_id)); #else openlog("rsyncd", options); #endif @@ -154,11 +156,26 @@ static void logfile_open(void) } } -void log_init(void) +void log_init(int restart) { - if (log_initialised) - return; - log_initialised = 1; + if (log_initialised) { + if (!restart) + return; + if (strcmp(logfile_name, lp_log_file(module_id)) != 0) { + if (logfile_fp) { + fclose(logfile_fp); + logfile_fp = NULL; + } else + closelog(); + logfile_name = NULL; + } else if (*logfile_name) + return; /* unchanged, non-empty "log file" names */ + else if (lp_syslog_facility(-1) != lp_syslog_facility(module_id)) + closelog(); + else + return; /* unchanged syslog settings */ + } else + log_initialised = 1; /* This looks pointless, but it is needed in order for the * C library on some systems to fetch the timezone info @@ -168,7 +185,7 @@ void log_init(void) /* Optionally use a log file instead of syslog. (Non-daemon * rsyncs will have already set logfile_name, as needed.) */ if (am_daemon && !logfile_name) - logfile_name = lp_log_file(); + logfile_name = lp_log_file(module_id); if (logfile_name && *logfile_name) logfile_open(); else @@ -245,7 +262,7 @@ void rwrite(enum logcode code, char *buf, int len) return; in_block = 1; if (!log_initialised) - log_init(); + log_init(0); strlcpy(msg, buf, MIN((int)sizeof msg, len + 1)); logit(priority, msg); in_block = 0; @@ -498,8 +515,18 @@ static void log_formatted(enum logcode code, char *format, char *op, strlcpy(n, buf2, MAXPATHLEN); else n = buf2; - } else - clean_fname(n, 0); + } else { + if (*n != '/') { + pathjoin(buf2, sizeof buf2, + curr_dir + module_dirlen, n); + clean_fname(buf2, 0); + if (fmt[1]) + strlcpy(n, buf2, MAXPATHLEN); + else + n = buf2; + } else + clean_fname(n, 0); + } if (*n == '/') n++; break;