Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8960b2d

Browse files
committed
Fix unportable setvbuf() usage in initdb.
In yesterday's commit2dc4f01, I triedto force buffering of stdout/stderr in initdb to be what it is bydefault when the program is run interactively on Unix (since that's howmost manual testing is done). This tripped over the fact that Windowsdoesn't support _IOLBF mode. We dealt with that a long time ago insyslogger.c by falling back to unbuffered mode on Windows. Export thatsolution in port.h and use it in initdb.Back-patch to 8.4, like the previous commit.
1 parent19d7e8f commit8960b2d

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

‎src/backend/postmaster/syslogger.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,6 @@
4646
#include"utils/ps_status.h"
4747
#include"utils/timestamp.h"
4848

49-
/*
50-
* We really want line-buffered mode for logfile output, but Windows does
51-
* not have it, and interprets _IOLBF as _IOFBF (bozos). So use _IONBF
52-
* instead on Windows.
53-
*/
54-
#ifdefWIN32
55-
#defineLBF_MODE_IONBF
56-
#else
57-
#defineLBF_MODE_IOLBF
58-
#endif
59-
6049
/*
6150
* We read() into a temp buffer twice as big as a chunk, so that any fragment
6251
* left after processing can be moved down to the front and we'll still have
@@ -757,7 +746,7 @@ syslogger_parseArgs(int argc, char *argv[])
757746
if (fd!=-1)
758747
{
759748
syslogFile=fdopen(fd,"a");
760-
setvbuf(syslogFile,NULL,LBF_MODE,0);
749+
setvbuf(syslogFile,NULL,PG_IOLBF,0);
761750
}
762751
#else/* WIN32 */
763752
fd=atoi(*argv++);
@@ -767,7 +756,7 @@ syslogger_parseArgs(int argc, char *argv[])
767756
if (fd>0)
768757
{
769758
syslogFile=fdopen(fd,"a");
770-
setvbuf(syslogFile,NULL,LBF_MODE,0);
759+
setvbuf(syslogFile,NULL,PG_IOLBF,0);
771760
}
772761
}
773762
#endif/* WIN32 */
@@ -1146,7 +1135,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
11461135

11471136
if (fh)
11481137
{
1149-
setvbuf(fh,NULL,LBF_MODE,0);
1138+
setvbuf(fh,NULL,PG_IOLBF,0);
11501139

11511140
#ifdefWIN32
11521141
/* use CRLF line endings on Windows */

‎src/bin/initdb/initdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3453,7 +3453,7 @@ main(int argc, char *argv[])
34533453
* unexpected output ordering when, eg, output is redirected to a file.
34543454
* POSIX says we must do this before any other usage of these files.
34553455
*/
3456-
setvbuf(stdout,NULL,_IOLBF,0);
3456+
setvbuf(stdout,NULL,PG_IOLBF,0);
34573457
setvbuf(stderr,NULL,_IONBF,0);
34583458

34593459
progname=get_progname(argv[0]);

‎src/include/port.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ extern intgettimeofday(struct timeval * tp, struct timezone * tzp);
352352
#defineclosesocket close
353353
#endif/* WIN32 */
354354

355+
/*
356+
* On Windows, setvbuf() does not support _IOLBF mode, and interprets that
357+
* as _IOFBF. To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
358+
* crashes outright if "parameter validation" is enabled. Therefore, in
359+
* places where we'd like to select line-buffered mode, we fall back to
360+
* unbuffered mode instead on Windows. Always use PG_IOLBF not _IOLBF
361+
* directly in order to implement this behavior.
362+
*/
363+
#ifndefWIN32
364+
#definePG_IOLBF_IOLBF
365+
#else
366+
#definePG_IOLBF_IONBF
367+
#endif
368+
355369
/*
356370
* Default "extern" declarations or macro substitutes for library routines.
357371
* When necessary, these routines are provided by files in src/port/.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp