]> granicus.if.org Git - pgbouncer/commitdiff
Dont let logging change errno.
authorMarko Kreen <markokr@gmail.com>
Mon, 19 Apr 2010 07:08:31 +0000 (07:08 +0000)
committerMarko Kreen <markokr@gmail.com>
Mon, 19 Apr 2010 07:08:31 +0000 (07:08 +0000)
With badly configured logging and higher logging levels, the code can
see wrong errno from syscalls.  So always retore original errno when logging.

src/util.c

index 1f4dd1e81107aad7c4f75ed57850f724592c0c9f..eb9de5d301a31414cc0dfe78b4022f0e56a5b3af 100644 (file)
@@ -147,6 +147,7 @@ static void _log_write(const char *pfx, const char *msg)
        char buf[1024];
        char tbuf[64];
        int len;
+       int old_errno = errno;
 
        render_time(tbuf, sizeof(tbuf));
        len = snprintf(buf, sizeof(buf), "%s %u %s %s\n",
@@ -160,6 +161,9 @@ static void _log_write(const char *pfx, const char *msg)
 
        if (!cf_quiet)
                fprintf(stderr, "%s", buf);
+
+       if (old_errno != errno)
+               errno = old_errno;
 }
 
 static void _log(const char *pfx, const char *fmt, va_list ap)