Commit 8ae7278c authored by Tom Lane's avatar Tom Lane

Fix several small Windows compatibility issues, per Andreas.

parent 78877260
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.1 2004/08/05 23:32:10 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.2 2004/08/06 16:00:51 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -41,6 +41,18 @@ ...@@ -41,6 +41,18 @@
#include "utils/ps_status.h" #include "utils/ps_status.h"
/*
* We really want line-buffered mode for logfile output, but Windows does
* not have it, and interprets _IOLBF as _IOFBF (bozos). So use _IONBF
* instead on Windows.
*/
#ifdef WIN32
#define LBF_MODE _IONBF
#else
#define LBF_MODE _IOLBF
#endif
/* /*
* GUC parameters. Redirect_stderr cannot be changed after postmaster * GUC parameters. Redirect_stderr cannot be changed after postmaster
* start, but the rest can change at SIGHUP. * start, but the rest can change at SIGHUP.
...@@ -132,11 +144,19 @@ SysLoggerMain(int argc, char *argv[]) ...@@ -132,11 +144,19 @@ SysLoggerMain(int argc, char *argv[])
*/ */
if (redirection_done) if (redirection_done)
{ {
int i = open(NULL_DEV, O_WRONLY); int fd = open(NULL_DEV, O_WRONLY);
dup2(i, fileno(stdout)); /*
dup2(i, fileno(stderr)); * The closes might look redundant, but they are not: we want to be
close(i); * darn sure the pipe gets closed even if the open failed. We can
* survive running with stderr pointing nowhere, but we can't afford
* to have extra pipe input descriptors hanging around.
*/
close(fileno(stdout));
close(fileno(stderr));
dup2(fd, fileno(stdout));
dup2(fd, fileno(stderr));
close(fd);
} }
/* /*
...@@ -317,9 +337,13 @@ SysLoggerMain(int argc, char *argv[]) ...@@ -317,9 +337,13 @@ SysLoggerMain(int argc, char *argv[])
{ {
ereport(LOG, ereport(LOG,
(errmsg("logger shutting down"))); (errmsg("logger shutting down")));
if (syslogFile) /*
fclose(syslogFile); * Normal exit from the syslogger is here. Note that we
/* normal exit from the syslogger is here */ * deliberately do not close syslogFile before exiting;
* this is to allow for the possibility of elog messages
* being generated inside proc_exit. Regular exit() will
* take care of flushing and closing stdio channels.
*/
proc_exit(0); proc_exit(0);
} }
} }
...@@ -401,7 +425,7 @@ SysLogger_Start(void) ...@@ -401,7 +425,7 @@ SysLogger_Start(void)
(errmsg("could not create logfile \"%s\": %m", (errmsg("could not create logfile \"%s\": %m",
filename)))); filename))));
setvbuf(syslogFile, NULL, _IOLBF, 0); setvbuf(syslogFile, NULL, LBF_MODE, 0);
pfree(filename); pfree(filename);
...@@ -557,7 +581,7 @@ syslogger_parseArgs(int argc, char *argv[]) ...@@ -557,7 +581,7 @@ syslogger_parseArgs(int argc, char *argv[])
if (fd != -1) if (fd != -1)
{ {
syslogFile = fdopen(fd, "a"); syslogFile = fdopen(fd, "a");
setvbuf(syslogFile, NULL, _IOLBF, 0); setvbuf(syslogFile, NULL, LBF_MODE, 0);
} }
redirection_done = (bool) atoi(*argv++); redirection_done = (bool) atoi(*argv++);
#else /* WIN32 */ #else /* WIN32 */
...@@ -568,7 +592,7 @@ syslogger_parseArgs(int argc, char *argv[]) ...@@ -568,7 +592,7 @@ syslogger_parseArgs(int argc, char *argv[])
if (fd != 0) if (fd != 0)
{ {
syslogFile = fdopen(fd, "a"); syslogFile = fdopen(fd, "a");
setvbuf(syslogFile, NULL, _IOLBF, 0); setvbuf(syslogFile, NULL, LBF_MODE, 0);
} }
} }
redirection_done = (bool) atoi(*argv++); redirection_done = (bool) atoi(*argv++);
...@@ -631,7 +655,8 @@ pipeThread(void *arg) ...@@ -631,7 +655,8 @@ pipeThread(void *arg)
{ {
DWORD error = GetLastError(); DWORD error = GetLastError();
if (error == ERROR_HANDLE_EOF) if (error == ERROR_HANDLE_EOF ||
error == ERROR_BROKEN_PIPE)
break; break;
ereport(LOG, ereport(LOG,
(errcode_for_file_access(), (errcode_for_file_access(),
...@@ -689,7 +714,7 @@ logfile_rotate(void) ...@@ -689,7 +714,7 @@ logfile_rotate(void)
return; return;
} }
setvbuf(fh, NULL, _IOLBF, 0); setvbuf(fh, NULL, LBF_MODE, 0);
/* On Windows, need to interlock against data-transfer thread */ /* On Windows, need to interlock against data-transfer thread */
#ifdef WIN32 #ifdef WIN32
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment