From bfee71fa3ac057fbde5963dbdc353a09cc2ba9c1 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 18 Mar 2009 08:44:52 +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 9a108b4e62..2d20b82e48 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -909,13 +909,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.39.5