Adding more calls to safe_fname().
[rsync/rsync.git] / log.c
diff --git a/log.c b/log.c
index 0b55457..256e70e 100644 (file)
--- a/log.c
+++ b/log.c
@@ -61,7 +61,7 @@ struct {
        { RERR_WAITCHILD  , "some error returned by waitpid()" },
        { RERR_MALLOC     , "error allocating core memory buffers" },
        { RERR_PARTIAL    , "some files could not be transferred" },
-       { RERR_VANISHED   , "some files vanished before they could be transfered" },
+       { RERR_VANISHED   , "some files vanished before they could be transferred" },
        { RERR_TIMEOUT    , "timeout in data send/receive" },
        { RERR_CMD_FAILED , "remote shell failed" },
        { RERR_CMD_KILLED , "remote shell killed" },
@@ -85,6 +85,20 @@ static char const *rerr_name(int code)
        return NULL;
 }
 
+static void log_open(void)
+{
+       if (logfname && !logfile) {
+               extern int orig_umask;
+               int old_umask = umask(022 | orig_umask);
+               logfile = fopen(logfname, "a");
+               umask(old_umask);
+               if (!logfile) {
+                       am_daemon = 0; /* avoid trying to log again */
+                       rsyserr(FERROR, errno, "fopen() of log-file failed");
+                       exit_cleanup(RERR_FILESELECT);
+               }
+       }
+}
 
 static void logit(int priority, char *buf)
 {
@@ -139,16 +153,6 @@ void log_init(void)
 #endif
 }
 
-void log_open(void)
-{
-       if (logfname && !logfile) {
-               extern int orig_umask;
-               int old_umask = umask(022 | orig_umask);
-               logfile = fopen(logfname, "a");
-               umask(old_umask);
-       }
-}
-
 void log_close(void)
 {
        if (logfile) {
@@ -371,8 +375,8 @@ static void log_formatted(enum logcode code,
                case 'o': n = op; break;
                case 'f':
                        pathjoin(buf2, sizeof buf2,
-                                file->basedir ? file->basedir : "",
-                                f_name(file));
+                           am_sender && file->dir.root ? file->dir.root : "",
+                           safe_fname(f_name(file)));
                        clean_fname(buf2, 0);
                        n = buf2;
                        if (*n == '/') n++;
@@ -414,7 +418,7 @@ static void log_formatted(enum logcode code,
                l = strlen(n);
 
                if (l + ((int)(s - &buf[0])) >= sizeof(buf)) {
-                       rprintf(FERROR,"buffer overflow expanding %%%c - exiting\n",
+                       rprintf(FERROR,"buffer overflow expanding %%%c -- exiting\n",
                                p[0]);
                        exit_cleanup(RERR_MESSAGEIO);
                }