pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Clean up inconsistent use of fflush().
Date: Mon, 29 Aug 2022 17:55:51 +0000
Message-ID: <E1oSizH-000UUD-2n@gemulon.postgresql.org> (raw)

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7fed801135bae14d63b11ee4a10f6083767046d8

Modified Files
--------------
src/backend/access/transam/xlogarchive.c  |  2 ++
src/backend/postmaster/fork_process.c     |  7 +------
src/backend/postmaster/shell_archive.c    |  1 +
src/backend/storage/file/fd.c             |  3 +--
src/backend/utils/error/elog.c            |  6 ++----
src/bin/initdb/initdb.c                   |  5 +++--
src/bin/pg_ctl/pg_ctl.c                   |  5 +++--
src/bin/pg_dump/pg_dumpall.c              |  3 +--
src/bin/pg_rewind/pg_rewind.c             |  1 +
src/bin/pg_upgrade/controldata.c          |  6 ++----
src/bin/pg_upgrade/exec.c                 |  7 +++++++
src/bin/pg_upgrade/option.c               |  1 +
src/bin/pg_verifybackup/pg_verifybackup.c |  1 +
src/bin/pgbench/pgbench.c                 |  2 ++
src/bin/psql/command.c                    |  4 ++++
src/bin/psql/common.c                     |  1 +
src/bin/psql/copy.c                       |  8 +++-----
src/bin/psql/prompt.c                     |  4 +++-
src/bin/psql/psqlscanslash.l              |  1 +
src/common/exec.c                         |  4 +---
src/fe_utils/archive.c                    |  1 +
src/fe_utils/print.c                      |  1 +
src/interfaces/libpq/fe-print.c           |  1 +
src/test/regress/pg_regress.c             | 18 ++++++++----------
24 files changed, 52 insertions(+), 41 deletions(-)



Message-ID: <E1oSizH-000UUD-2n@gemulon.postgresql.org>
Permalink:  ../E1oSizH-000UUD-2n@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oSizH-000UUD-2n@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Clean up inconsistent use of fflush().
  In-Reply-To: <E1oSizH-000UUD-2n@gemulon.postgresql.org>
  References: <E1oSizH-000UUD-2n@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox