Thread: pgsql: Check return value of pclose() correctly

pgsql: Check return value of pclose() correctly

From
Peter Eisentraut
Date:
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@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/8cd9fb02-bc26-65f1-a809-b1cb360eef73@enterprisedb.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(-)