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

Commitda05e57

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 parentf47e4ce commitda05e57

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
@@ -45,17 +45,6 @@
4545
#include"utils/ps_status.h"
4646
#include"utils/timestamp.h"
4747

48-
/*
49-
* We really want line-buffered mode for logfile output, but Windows does
50-
* not have it, and interprets _IOLBF as _IOFBF (bozos). So use _IONBF
51-
* instead on Windows.
52-
*/
53-
#ifdefWIN32
54-
#defineLBF_MODE_IONBF
55-
#else
56-
#defineLBF_MODE_IOLBF
57-
#endif
58-
5948
/*
6049
* We read() into a temp buffer twice as big as a chunk, so that any fragment
6150
* left after processing can be moved down to the front and we'll still have
@@ -704,7 +693,7 @@ syslogger_parseArgs(int argc, char *argv[])
704693
if (fd!=-1)
705694
{
706695
syslogFile=fdopen(fd,"a");
707-
setvbuf(syslogFile,NULL,LBF_MODE,0);
696+
setvbuf(syslogFile,NULL,PG_IOLBF,0);
708697
}
709698
#else/* WIN32 */
710699
fd=atoi(*argv++);
@@ -714,7 +703,7 @@ syslogger_parseArgs(int argc, char *argv[])
714703
if (fd>0)
715704
{
716705
syslogFile=fdopen(fd,"a");
717-
setvbuf(syslogFile,NULL,LBF_MODE,0);
706+
setvbuf(syslogFile,NULL,PG_IOLBF,0);
718707
}
719708
}
720709
#endif/* WIN32 */
@@ -1079,7 +1068,7 @@ logfile_open(const char *filename, const char *mode, bool allow_errors)
10791068

10801069
if (fh)
10811070
{
1082-
setvbuf(fh,NULL,LBF_MODE,0);
1071+
setvbuf(fh,NULL,PG_IOLBF,0);
10831072

10841073
#ifdefWIN32
10851074
/* 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
@@ -2557,7 +2557,7 @@ main(int argc, char *argv[])
25572557
* unexpected output ordering when, eg, output is redirected to a file.
25582558
* POSIX says we must do this before any other usage of these files.
25592559
*/
2560-
setvbuf(stdout,NULL,_IOLBF,0);
2560+
setvbuf(stdout,NULL,PG_IOLBF,0);
25612561
setvbuf(stderr,NULL,_IONBF,0);
25622562

25632563
progname=get_progname(argv[0]);

‎src/include/port.h

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

374+
/*
375+
* On Windows, setvbuf() does not support _IOLBF mode, and interprets that
376+
* as _IOFBF. To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
377+
* crashes outright if "parameter validation" is enabled. Therefore, in
378+
* places where we'd like to select line-buffered mode, we fall back to
379+
* unbuffered mode instead on Windows. Always use PG_IOLBF not _IOLBF
380+
* directly in order to implement this behavior.
381+
*/
382+
#ifndefWIN32
383+
#definePG_IOLBF_IOLBF
384+
#else
385+
#definePG_IOLBF_IONBF
386+
#endif
387+
374388
/*
375389
* Default "extern" declarations or macro substitutes for library routines.
376390
* When necessary, these routines are provided by files in src/port/.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp