When running as --daemon in the background and using a "log file" rsyncd.conf
authorDavid Dykstra <dwd@samba.org>
Tue, 24 Oct 2000 18:50:08 +0000 (18:50 +0000)
committerDavid Dykstra <dwd@samba.org>
Tue, 24 Oct 2000 18:50:08 +0000 (18:50 +0000)
directive, close the log file every time it is open when going to sleep on
the socket.  This allows the log file to get cleaned out by another process.

clientserver.c
log.c
socket.c

index 95461106df7ca953825fca9b8e51370a9f39af0e..0164d070bdcc7071b25a569b922248955bf90afb 100644 (file)
@@ -206,7 +206,7 @@ static int rsync_module(int fd, int i)
        p = lp_exclude(i);
        add_exclude_line(p);
 
-       log_open();
+       log_init();
 
        if (use_chroot) {
                if (chroot(lp_path(i))) {
@@ -449,7 +449,7 @@ int daemon_main(void)
                exit_cleanup(RERR_SYNTAX);
        }
 
-       log_open();
+       log_init();
 
        rprintf(FINFO,"rsyncd version %s starting\n",VERSION);
 
diff --git a/log.c b/log.c
index 61a8bd05e3c03410fe0022a148bb454e3afbeb4a..1c54a85d1942ed3852e63d3705d8b0f9cd013147 100644 (file)
--- a/log.c
+++ b/log.c
   */
 #include "rsync.h"
 
+static char *logfname;
 static FILE *logfile;
 static int log_error_fd = -1;
 
 static void logit(int priority, char *buf)
 {
-       if (logfile) {
+       if (logfname) {
+               if (!logfile) {
+                       extern int orig_umask;
+                       int old_umask = umask(022 | orig_umask);
+                       logfile = fopen(logfname, "a");
+                       umask(old_umask);
+               }
                fprintf(logfile,"%s [%d] %s", 
                        timestring(time(NULL)), (int)getpid(), buf);
                fflush(logfile);
@@ -37,12 +44,11 @@ static void logit(int priority, char *buf)
        }
 }
 
-void log_open(void)
+void log_init(void)
 {
        static int initialised;
        int options = LOG_PID;
        time_t t;
-       char *logf;
 
        if (initialised) return;
        initialised = 1;
@@ -54,13 +60,11 @@ void log_open(void)
        localtime(&t);
 
        /* optionally use a log file instead of syslog */
-       logf = lp_log_file();
-       if (logf && *logf) {
-               extern int orig_umask;
-               int old_umask = umask(022 | orig_umask);
-               logfile = fopen(logf, "a");
-               umask(old_umask);
-               return;
+       logfname = lp_log_file();
+       if (logfname) {
+               if (*logfname)
+                       return;
+               logfname = NULL;
        }
 
 #ifdef LOG_NDELAY
@@ -78,6 +82,16 @@ void log_open(void)
 #endif
 }
 
+/* for long runs when using a log file, close it before potential long waits
+   so it can be trimmed by another process instead of growing forever */
+void log_release()
+{
+       if (logfile) {
+               fclose(logfile);
+               logfile = NULL;
+       }
+}
+
 /* setup the error file descriptor - used when we are a server
    that is receiving files */
 void set_error_fd(int fd)
@@ -125,7 +139,7 @@ void rwrite(enum logcode code, char *buf, int len)
 
                depth++;
 
-               log_open();
+               log_init();
                logit(priority, buf);
 
                depth--;
index 9a61951545f59cc7145f6496bb1e585a9ca39015..a0debcd1f624709c60297aa934dc6365ff90b04e 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -247,6 +247,8 @@ void start_accept_loop(int port, int (*fn)(int ))
                struct sockaddr addr;
                int in_addrlen = sizeof(addr);
 
+               log_release();
+
                FD_ZERO(&fds);
                FD_SET(s, &fds);