summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2009-03-18 08:44:49 +0000
committerHeikki Linnakangas2009-03-18 08:44:49 +0000
commit77926e66130f670ef910a5c80fb16e9a66f1a01b (patch)
tree746a61cb6fe639821d936d81655cc4298ad1bc0a
parent921c03301b639625535ac82fa8f4cf9e50279fe3 (diff)
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.
-rw-r--r--src/backend/postmaster/syslogger.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 0f8d93a968..1b7c3bfa31 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -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