From 49f67c066a2a1e4ed52066245078be055c5ad817 Mon Sep 17 00:00:00 2001 From: heikki Date: Wed, 18 Mar 2009 08:44:49 +0000 Subject: [PATCH] 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. --- src/backend/postmaster/syslogger.c | 11 ++++++----- 1 file 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 -- 2.11.4.GIT