From: David Dykstra Date: Tue, 24 Oct 2000 18:50:08 +0000 (+0000) Subject: When running as --daemon in the background and using a "log file" rsyncd.conf X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/45a8354004ecbc1c0b03d6e880b512854ed9439a When running as --daemon in the background and using a "log file" rsyncd.conf 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. --- diff --git a/clientserver.c b/clientserver.c index 95461106..0164d070 100644 --- a/clientserver.c +++ b/clientserver.c @@ -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 61a8bd05..1c54a85d 100644 --- a/log.c +++ b/log.c @@ -23,12 +23,19 @@ */ #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--; diff --git a/socket.c b/socket.c index 9a619515..a0debcd1 100644 --- 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);