summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2022-08-29 17:55:38 +0000
committerTom Lane2022-08-29 17:55:41 +0000
commit7fed801135bae14d63b11ee4a10f6083767046d8 (patch)
tree73fa489ffb169fe62ae066ef5cfe6a39a8fa6163 /src/test
parent20796536c10fe7869e7af2c69615f14a80555c5d (diff)
Clean up inconsistent use of fflush().
More than twenty years ago (79fcde48b), we hacked the postmaster to avoid a core-dump on systems that didn't support fflush(NULL). We've mostly, though not completely, hewed to that rule ever since. But such systems are surely gone in the wild, so in the spirit of cleaning out no-longer-needed portability hacks let's get rid of multiple per-file fflush() calls in favor of using fflush(NULL). Also, we were fairly inconsistent about whether to fflush() before popen() and system() calls. While we've received no bug reports about that, it seems likely that at least some of these call sites are at risk of odd behavior, such as error messages appearing in an unexpected order. Rather than expend a lot of brain cells figuring out which places are at hazard, let's just establish a uniform coding rule that we should fflush(NULL) before these calls. A no-op fflush() is surely of trivial cost compared to launching a sub-process via a shell; while if it's not a no-op then we likely need it. Discussion: https://postgr.es/m/2923412.1661722825@sss.pgh.pa.us
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/pg_regress.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index a803355f8ee..7290948eeee 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -263,15 +263,12 @@ stop_postmaster(void)
char buf[MAXPGPATH * 2];
int r;
- /* On Windows, system() seems not to force fflush, so... */
- fflush(stdout);
- fflush(stderr);
-
snprintf(buf, sizeof(buf),
"\"%s%spg_ctl\" stop -D \"%s/data\" -s",
bindir ? bindir : "",
bindir ? "/" : "",
temp_instance);
+ fflush(NULL);
r = system(buf);
if (r != 0)
{
@@ -1029,6 +1026,7 @@ psql_end_command(StringInfo buf, const char *database)
database);
/* And now we can execute the shell command */
+ fflush(NULL);
if (system(buf->data) != 0)
{
/* psql probably already reported the error */
@@ -1063,13 +1061,9 @@ spawn_process(const char *cmdline)
pid_t pid;
/*
- * Must flush I/O buffers before fork. Ideally we'd use fflush(NULL) here
- * ... does anyone still care about systems where that doesn't work?
+ * Must flush I/O buffers before fork.
*/
- fflush(stdout);
- fflush(stderr);
- if (logfile)
- fflush(logfile);
+ fflush(NULL);
#ifdef EXEC_BACKEND
pg_disable_aslr();
@@ -1247,6 +1241,7 @@ run_diff(const char *cmd, const char *filename)
{
int r;
+ fflush(NULL);
r = system(cmd);
if (!WIFEXITED(r) || WEXITSTATUS(r) > 1)
{
@@ -2264,6 +2259,7 @@ regression_main(int argc, char *argv[],
debug ? " --debug" : "",
nolocale ? " --no-locale" : "",
outputdir);
+ fflush(NULL);
if (system(buf))
{
fprintf(stderr, _("\n%s: initdb failed\nExamine %s/log/initdb.log for the reason.\nCommand was: %s\n"), progname, outputdir, buf);
@@ -2335,6 +2331,7 @@ regression_main(int argc, char *argv[],
for (i = 0; i < 16; i++)
{
+ fflush(NULL);
if (system(buf2) == 0)
{
char s[16];
@@ -2398,6 +2395,7 @@ regression_main(int argc, char *argv[],
for (i = 0; i < wait_seconds; i++)
{
/* Done if psql succeeds */
+ fflush(NULL);
if (system(buf2) == 0)
break;