diff options
author | Tom Lane | 2015-12-03 19:28:58 +0000 |
---|---|---|
committer | Tom Lane | 2015-12-03 19:29:28 +0000 |
commit | 344cdff2c1541e7a1249299a33723aabeafa0b0c (patch) | |
tree | fe16426718eb6f1abd388ba0db94c31aa8e80f38 /src/bin/psql/copy.c | |
parent | f15b820a5c60b10f3ac1b2fdb37d534ecb0a4bf8 (diff) |
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.
Diffstat (limited to 'src/bin/psql/copy.c')
-rw-r--r-- | src/bin/psql/copy.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index c0fc28373a9..a09408bf550 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -37,7 +37,7 @@ * where 'filename' can be one of the following: * '<file path>' | PROGRAM '<command>' | stdin | stdout | pstdout | pstdout * and 'query' can be one of the following: - * SELECT | UPDATE | INSERT | DELETE + * SELECT | UPDATE | INSERT | DELETE * * An undocumented fact is that you can still write BINARY before the * tablename; this is a hangover from the pre-7.3 syntax. The options @@ -312,9 +312,7 @@ do_copy(const char *args) fflush(stdout); fflush(stderr); errno = 0; -#ifndef WIN32 - pqsignal(SIGPIPE, SIG_IGN); -#endif + disable_sigpipe_trap(); copystream = popen(options->file, PG_BINARY_W); } else @@ -399,9 +397,7 @@ do_copy(const char *args) } success = false; } -#ifndef WIN32 - pqsignal(SIGPIPE, SIG_DFL); -#endif + restore_sigpipe_trap(); } else { |