8000 In initdb, ensure stdout/stderr buffering behavior is what we expect. · larkly/postgres-docker@a2655a3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit a2655a3

Browse files
committed
In initdb, ensure stdout/stderr buffering behavior is what we expect.
Since this program may print to either stdout or stderr, the relative ordering of its messages depends on the buffering behavior of those files. Force stdout to be line-buffered and stderr to be unbuffered, ensuring that the behavior will match standard Unix interactive behavior, even when stdout and stderr are rerouted to a file. Per complaint from Tomas Vondra. The particular case he pointed out is new in HEAD, but issues of the same sort could arise in any branch with other error messages, so back-patch to all branches. I'm unsure whether we might not want to do this in other client programs as well. For the moment, just fix initdb.
1 parent 0d8d0d0 commit a2655a3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/bin/initdb/initdb.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,15 @@ main(int argc, char *argv[])
26692669
"pg_stat_tmp"
26702670
};
26712671

2672+
/*
2673+
* Ensure that buffering behavior of stdout and stderr matches what it is
2674+
* in interactive usage (at least on most platforms). This prevents
2675+
* unexpected output ordering when, eg, output is redirected to a file.
2676+
* POSIX says we must do this before any other usage of these files.
2677+
*/
2678+
setvbuf(stdout, NULL, _IOLBF, 0);
2679+
setvbuf(stderr, NULL, _IONBF, 0);
2680+
26722681
progname = get_progname(argv[0]);
26732682
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
26742683

0 commit comments

Comments
 (0)
0