]> granicus.if.org Git - pgbouncer/commitdiff
code still tried to close fd, fix and clean up
authorMarko Kreen <markokr@gmail.com>
Fri, 7 Sep 2007 12:23:47 +0000 (12:23 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 7 Sep 2007 12:23:47 +0000 (12:23 +0000)
src/util.c

index b085f966be8cf2e1920089dfec9bc104de1fb2e1..45177be530d6a8231a6b1aff2e3f0883542ec154 100644 (file)
@@ -55,15 +55,15 @@ void close_logfile(void)
        }
 }
 
-static int open_logfile(void)
+static void write_logfile(const char *buf, int len)
 {
        if (!log_fd) {
                int fd = open(cf_logfile, O_CREAT | O_APPEND | O_WRONLY, 0644);
                if (fd < 0)
-                       return -1;
+                       return;
                log_fd = fd;
        }
-       return log_fd;
+       safe_write(log_fd, buf, len);
 }
 
 static void _log_write(const char *pfx, const char *msg)
@@ -71,16 +71,14 @@ static void _log_write(const char *pfx, const char *msg)
        char buf[1024];
        char tbuf[64];
        int len;
+
        render_time(tbuf, sizeof(tbuf));
        len = snprintf(buf, sizeof(buf), "%s %u %s %s\n",
                        tbuf, (unsigned)getpid(), pfx, msg);
-       if (cf_logfile) {
-               int fd = open_logfile();
-               if (fd > 0) {
-                       safe_write(fd, buf, len);
-                       safe_close(fd);
-               }
-       }
+
+       if (cf_logfile)
+               write_logfile(buf, len);
+
        if (!cf_quiet)
                fprintf(stderr, "%s", buf);
 }