From: Heikki Linnakangas Date: Wed, 18 Mar 2009 08:44:52 +0000 (+0000) Subject: Fix Windows-specific race condition in syslogger. This could've been X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=bfee71fa3ac057fbde5963dbdc353a09cc2ba9c1;p=users%2Fbernd%2Fpostgres.git 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. --- 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