aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-05-15 15:57:54 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-05-15 15:57:54 -0400
commitf62d417825d6a8e26768a130a5f4c9e454d9dbe4 (patch)
tree2bcb47f506363428363a7015b78714e21cc0970d
parent2f8e68bd7ea3523977567369056c4b3e67e44fdc (diff)
downloadpostgresql-f62d417825d6a8e26768a130a5f4c9e454d9dbe4.tar.gz
postgresql-f62d417825d6a8e26768a130a5f4c9e454d9dbe4.zip
Fix unportable setvbuf() usage in initdb.
In yesterday's commit 2dc4f011fd61501cce507be78c39a2677690d44b, I tried to force buffering of stdout/stderr in initdb to be what it is by default when the program is run interactively on Unix (since that's how most manual testing is done). This tripped over the fact that Windows doesn't support _IOLBF mode. We dealt with that a long time ago in syslogger.c by falling back to unbuffered mode on Windows. Export that solution in port.h and use it in initdb. Back-patch to 8.4, like the previous commit.
-rw-r--r--src/backend/postmaster/syslogger.c17
-rw-r--r--src/bin/initdb/initdb.c2
-rw-r--r--src/include/port.h14
3 files changed, 18 insertions, 15 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index f89a5339e0f..916519be502 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -48,17 +48,6 @@
#include "utils/timestamp.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
-
-/*
* We read() into a temp buffer twice as big as a chunk, so that any fragment
* left after processing can be moved down to the front and we'll still have
* room to read a full chunk.
@@ -765,7 +754,7 @@ syslogger_parseArgs(int argc, char *argv[])
if (fd != -1)
{
syslogFile = fdopen(fd, "a");
- setvbuf(syslogFile, NULL, LBF_MODE, 0);
+ setvbuf(syslogFile, NULL, PG_IOLBF, 0);
}
#else /* WIN32 */
fd = atoi(*argv++);
@@ -775,7 +764,7 @@ syslogger_parseArgs(int argc, char *argv[])
if (fd > 0)
{
syslogFile = fdopen(fd, "a");
- setvbuf(syslogFile, NULL, LBF_MODE, 0);
+ setvbuf(syslogFile, NULL, PG_IOLBF, 0);
}
}
#endif /* WIN32 */
@@ -1154,7 +1143,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
if (fh)
{
- setvbuf(fh, NULL, LBF_MODE, 0);
+ setvbuf(fh, NULL, PG_IOLBF, 0);
#ifdef WIN32
/* use CRLF line endings on Windows */
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index acaae029806..5228f134222 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -3529,7 +3529,7 @@ main(int argc, char *argv[])
* unexpected output ordering when, eg, output is redirected to a file.
* POSIX says we must do this before any other usage of these files.
*/
- setvbuf(stdout, NULL, _IOLBF, 0);
+ setvbuf(stdout, NULL, PG_IOLBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
progname = get_progname(argv[0]);
diff --git a/src/include/port.h b/src/include/port.h
index 3d7f2675545..c9226f3dac1 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -339,6 +339,20 @@ extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
#endif /* WIN32 */
/*
+ * On Windows, setvbuf() does not support _IOLBF mode, and interprets that
+ * as _IOFBF. To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
+ * crashes outright if "parameter validation" is enabled. Therefore, in
+ * places where we'd like to select line-buffered mode, we fall back to
+ * unbuffered mode instead on Windows. Always use PG_IOLBF not _IOLBF
+ * directly in order to implement this behavior.
+ */
+#ifndef WIN32
+#define PG_IOLBF _IOLBF
+#else
+#define PG_IOLBF _IONBF
+#endif
+
+/*
* Default "extern" declarations or macro substitutes for library routines.
* When necessary, these routines are provided by files in src/port/.
*/