Check return value of pclose() correctly
authorPeter Eisentraut <[email protected]>
Tue, 15 Nov 2022 14:35:37 +0000 (15:35 +0100)
committerPeter Eisentraut <[email protected]>
Tue, 15 Nov 2022 14:36:51 +0000 (15:36 +0100)
commit2fe3bdbd691a5d11626308e7d660440be6c210c8
tree2e06bab0637373787d629086a752d0d2408d63ba
parentb7f3981756d314d32cca27b5c3d31bdd58b6ff06
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 <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/8cd9fb02-bc26-65f1-a809-b1cb360eef73@enterprisedb.com
src/backend/commands/collationcmds.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_upgrade/controldata.c
src/bin/pg_upgrade/exec.c
src/bin/pg_upgrade/option.c
src/bin/pgbench/pgbench.c
src/bin/psql/command.c
src/common/wait_error.c