pgsql: Check return value of pclose() correctly

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Check return value of pclose() correctly
Date: 2022-11-15 14:42:44
Message-ID: E1oux99-000Jw3-OT@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Check return value of pclose() correctly

Some callers didn't check the return value of pclose() or
ClosePipeStream() correctly. Either they didn't check it at all or
they treated it like the return of fclose().

The correct way is to first check whether the return value is -1, and
then report errno, and then check the return value like a result from
system(), for which we already have wait_result_to_str() to make it
simpler. To make this more compact, expand wait_result_to_str() to
also handle -1 explicitly.

Reviewed-by: Ankit Kumar Pandey <itsankitkp(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/8cd9fb02-bc26-65f1-a809-b1cb360eef73(at)enterprisedb(dot)com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2fe3bdbd691a5d11626308e7d660440be6c210c8

Modified Files
--------------
src/backend/commands/collationcmds.c | 11 ++++++++++-
src/bin/pg_ctl/pg_ctl.c | 3 +--
src/bin/pg_upgrade/controldata.c | 12 +++++++++---
src/bin/pg_upgrade/exec.c | 6 +++++-
src/bin/pg_upgrade/option.c | 6 +++++-
src/bin/pgbench/pgbench.c | 2 +-
src/bin/psql/command.c | 18 ++++++++++++++----
src/common/wait_error.c | 14 ++++++++++++--
8 files changed, 57 insertions(+), 15 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2022-11-15 15:50:45 pgsql: Deduplicate freeze plans in freeze WAL records.
Previous Message Daniel Gustafsson 2022-11-15 13:59:29 pgsql: doc: Use more concise wording for pl/pgSQL TG_ variables