Got rid of type-casting into isFOO() and toFOO() functions by
[rsync/rsync.git] / log.c
diff --git a/log.c b/log.c
index 64e584b..f7ccc00 100644 (file)
--- 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;
@@ -88,7 +90,6 @@ struct {
        { 0, NULL }
 };
 
-
 /*
  * Map from rsync error code to name, or return NULL.
  */
@@ -129,7 +130,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 +155,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 +184,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
@@ -198,11 +214,11 @@ static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
        for (s = buf; s < end; s++) {
                if ((s < end - 4
                  && *s == '\\' && s[1] == '#'
-                 && isdigit(*(uchar*)(s+2))
-                 && isdigit(*(uchar*)(s+3))
-                 && isdigit(*(uchar*)(s+4)))
+                 && isDigit(s + 2)
+                 && isDigit(s + 3)
+                 && isDigit(s + 4))
                 || (*s != '\t'
-                 && ((use_isprint && !isprint(*(uchar*)s))
+                 && ((use_isprint && !isPrint(s))
                   || *(uchar*)s < ' '))) {
                        if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
                                exit_cleanup(RERR_MESSAGEIO);
@@ -245,7 +261,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;
@@ -369,7 +385,7 @@ void rsyserr(enum logcode code, int errcode, const char *format, ...)
        char buf[BIGPATHBUFLEN];
        size_t len;
 
-       strcpy(buf, RSYNC_NAME ": ");
+       strlcpy(buf, RSYNC_NAME ": ", sizeof buf);
        len = (sizeof RSYNC_NAME ": ") - 1;
 
        va_start(ap, format);
@@ -429,7 +445,7 @@ static void log_formatted(enum logcode code, char *format, char *op,
                n = fmt + 1;
                if (*p == '-')
                        *n++ = *p++;
-               while (isdigit(*(uchar*)p) && n - fmt < (int)(sizeof fmt) - 8)
+               while (isDigit(p) && n - fmt < (int)(sizeof fmt) - 8)
                        *n++ = *p++;
                if (!*p)
                        break;
@@ -498,6 +514,14 @@ static void log_formatted(enum logcode code, char *format, char *op,
                                        strlcpy(n, buf2, MAXPATHLEN);
                                else
                                        n = buf2;
+                       } 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 == '/')
@@ -511,15 +535,15 @@ static void log_formatted(enum logcode code, char *format, char *op,
                case 'L':
                        if (hlink && *hlink) {
                                n = hlink;
-                               strcpy(buf2, " => ");
+                               strlcpy(buf2, " => ", sizeof buf2);
                        } else if (S_ISLNK(file->mode) && file->u.link) {
                                n = file->u.link;
-                               strcpy(buf2, " -> ");
+                               strlcpy(buf2, " -> ", sizeof buf2);
                        } else {
                                n = "";
                                if (!fmt[1])
                                        break;
-                               strcpy(buf2, "    ");
+                               strlcpy(buf2, "    ", sizeof buf2);
                        }
                        strlcat(fmt, "s", sizeof fmt);
                        snprintf(buf2 + 4, sizeof buf2 - 4, fmt, n);
@@ -653,7 +677,7 @@ int log_format_has(const char *format, char esc)
        for (p = format; (p = strchr(p, '%')) != NULL; ) {
                if (*++p == '-')
                        p++;
-               while (isdigit(*(uchar*)p))
+               while (isDigit(p))
                        p++;
                if (!*p)
                        break;