Clean up inconsistent use of fflush().
commit7fed801135bae14d63b11ee4a10f6083767046d8
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 29 Aug 2022 17:55:38 +0000 (29 13:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 29 Aug 2022 17:55:41 +0000 (29 13:55 -0400)
tree73fa489ffb169fe62ae066ef5cfe6a39a8fa6163
parent20796536c10fe7869e7af2c69615f14a80555c5d
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
24 files changed:
src/backend/access/transam/xlogarchive.c
src/backend/postmaster/fork_process.c
src/backend/postmaster/shell_archive.c
src/backend/storage/file/fd.c
src/backend/utils/error/elog.c
src/bin/initdb/initdb.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_rewind/pg_rewind.c
src/bin/pg_upgrade/controldata.c
src/bin/pg_upgrade/exec.c
src/bin/pg_upgrade/option.c
src/bin/pg_verifybackup/pg_verifybackup.c
src/bin/pgbench/pgbench.c
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/copy.c
src/bin/psql/prompt.c
src/bin/psql/psqlscanslash.l
src/common/exec.c
src/fe_utils/archive.c
src/fe_utils/print.c
src/interfaces/libpq/fe-print.c
src/test/regress/pg_regress.c