From: Marko Kreen Date: Thu, 6 Sep 2007 20:19:47 +0000 (+0000) Subject: long-lived logfile fd X-Git-Tag: pgbouncer_1_1~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c35901fbe85d69bbb1dccfd05bcd3369791cb901;p=pgbouncer long-lived logfile fd --- diff --git a/src/main.c b/src/main.c index 3816e3b..263366e 100644 --- a/src/main.c +++ b/src/main.c @@ -228,6 +228,9 @@ void load_config(bool reload) /* reset pool_size */ config_postprocess(); + + /* reopen logfile */ + close_logfile(); } /* diff --git a/src/util.c b/src/util.c index 9f9aa84..b085f96 100644 --- a/src/util.c +++ b/src/util.c @@ -45,6 +45,27 @@ static void render_time(char *buf, int max) strftime(buf, max, "%Y-%m-%d %H:%M:%S", &tm); } +static int log_fd = 0; + +void close_logfile(void) +{ + if (log_fd > 0) { + safe_close(log_fd); + log_fd = 0; + } +} + +static int open_logfile(void) +{ + if (!log_fd) { + int fd = open(cf_logfile, O_CREAT | O_APPEND | O_WRONLY, 0644); + if (fd < 0) + return -1; + log_fd = fd; + } + return log_fd; +} + static void _log_write(const char *pfx, const char *msg) { char buf[1024]; @@ -54,7 +75,7 @@ static void _log_write(const char *pfx, const char *msg) len = snprintf(buf, sizeof(buf), "%s %u %s %s\n", tbuf, (unsigned)getpid(), pfx, msg); if (cf_logfile) { - int fd = open(cf_logfile, O_CREAT | O_APPEND | O_WRONLY, 0644); + int fd = open_logfile(); if (fd > 0) { safe_write(fd, buf, len); safe_close(fd); diff --git a/src/util.h b/src/util.h index 0333b31..6a3d03a 100644 --- a/src/util.h +++ b/src/util.h @@ -44,6 +44,7 @@ void log_level(const char *level, const char *s, ...); if (cf_verbose > 1) log_level("NOISE", ## args); \ } while (0) +void close_logfile(void); /* * logging about specific socket