]> granicus.if.org Git - pgbouncer/commitdiff
long-lived logfile fd
authorMarko Kreen <markokr@gmail.com>
Thu, 6 Sep 2007 20:19:47 +0000 (20:19 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 6 Sep 2007 20:19:47 +0000 (20:19 +0000)
src/main.c
src/util.c
src/util.h

index 3816e3b8f7c5afa4798fe5116448232b0e68237a..263366e2e7dce6a206747dce2567015f094c982f 100644 (file)
@@ -228,6 +228,9 @@ void load_config(bool reload)
 
        /* reset pool_size */
        config_postprocess();
+
+       /* reopen logfile */
+       close_logfile();
 }
 
 /*
index 9f9aa84c072eacd44409baced9f14522ed50986c..b085f966be8cf2e1920089dfec9bc104de1fb2e1 100644 (file)
@@ -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);
index 0333b317781a8431b5f61a9a472298728e0884fe..6a3d03a46b4d993a87f397e7a78dc47bdfe16e32 100644 (file)
@@ -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