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-0008MW-CS@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
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/344cdff2c1541e7a1249299a33723aabeafa0b0c

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    |   10 +--
src/bin/psql/print.c   |   78 ++++++++++++++++----
src/bin/psql/print.h   |    4 ++
src/bin/psql/startup.c |    3 +-
7 files changed, 178 insertions(+), 106 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: doc: Fix markup and improve placeholder names
Next
From: Tom Lane
Date:
Subject: pgsql: Clean up some psql issues around handling of the query output fi