aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/syslogger.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-03-18 08:44:49 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-03-18 08:44:49 +0000
commit8e1a8fe2886c4e373f8ddd6262c2832ffcea9194 (patch)
treea970fa54a5226868efde24061fb25921f9c733c4 /src/backend/postmaster/syslogger.c
parent029348cff90e7d6d7e2ccd135de3720eabf7dac2 (diff)
downloadpostgresql-8e1a8fe2886c4e373f8ddd6262c2832ffcea9194.tar.gz
postgresql-8e1a8fe2886c4e373f8ddd6262c2832ffcea9194.zip
Fix Windows-specific race condition in syslogger. This could've been
the cause of the "could not write to log file: Bad file descriptor" errors reported at http://archives.postgresql.org//pgsql-general/2008-06/msg00193.php Backpatch to 8.3, the race condition was introduced by the CSV logging patch. Analysis and patch by Gurjeet Singh.
Diffstat (limited to 'src/backend/postmaster/syslogger.c')
-rw-r--r--src/backend/postmaster/syslogger.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 189ca58bba3..8475bdbd88a 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -18,7 +18,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.49 2009/02/24 12:09:09 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.50 2009/03/18 08:44:49 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -907,13 +907,14 @@ write_syslogger_file(const char *buffer, int count, int destination)
if (destination == LOG_DESTINATION_CSVLOG && csvlogFile == NULL)
open_csvlogfile();
- logfile = destination == LOG_DESTINATION_CSVLOG ? csvlogFile : syslogFile;
-
-#ifndef WIN32
- rc = fwrite(buffer, 1, count, logfile);
-#else
+#ifdef WIN32
EnterCriticalSection(&sysfileSection);
+#endif
+
+ logfile = destination == LOG_DESTINATION_CSVLOG ? csvlogFile : syslogFile;
rc = fwrite(buffer, 1, count, logfile);
+
+#ifdef WIN32
LeaveCriticalSection(&sysfileSection);
#endif