pgsql: Clean up some psql issues around handling of the query output fi - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Clean up some psql issues around handling of the query output fi
Date
Msg-id E1a4ZaD-0008MX-Cf@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Clean up some psql issues around handling of the query output file.

Formerly, if "psql -o foo" failed to open the output file "foo", it would
print an error message but then carry on as though -o had not been
specified at all.  This seems contrary to expectation: a program that
cannot open its output file normally fails altogether.  Make psql do
exit(1) after reporting the error.

If "\o foo" failed to open "foo", it would print an error message but then
reset the output file to stdout, as if the argument had been omitted.
This is likewise pretty surprising behavior.  Make it keep the previous
output state, instead.

psql keeps SIGPIPE interrupts disabled when it is writing to a pipe, either
a pipe specified by -o/\o or a transient pipe opened for purposes such as
using a pager on query output.  The logic for this was too simple and could
sometimes re-enable SIGPIPE when a -o pipe was still active, thus possibly
leading to an unexpected psql crash later.

Fixing the last point required getting rid of the kluge in PrintQueryTuples
and ExecQueryUsingCursor whereby they'd transiently change the global
queryFout state, but that seems like good cleanup anyway.

Back-patch to 9.5 but not further; these are minor-enough issues that
changing the behavior in stable branches doesn't seem appropriate.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/07338cb7425ee661ea2b80c1a3826bee1bc1a1de

Modified Files
--------------
src/bin/psql/command.c |    4 ++
src/bin/psql/common.c  |  184 ++++++++++++++++++++++++++----------------------
src/bin/psql/common.h  |    1 +
src/bin/psql/copy.c    |    8 +--
src/bin/psql/print.c   |   78 ++++++++++++++++----
src/bin/psql/print.h   |    4 ++
src/bin/psql/startup.c |    3 +-
7 files changed, 177 insertions(+), 105 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Clean up some psql issues around handling of the query output fi
Next
From: Alvaro Herrera
Date:
Subject: pgsql: Further tweak commit_timestamp behavior