Commit 45a83540 authored by David Dykstra's avatar David Dykstra

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.
parent c32d0240
......@@ -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);
......
......@@ -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--;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment