diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2021-03-31 20:11:51 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2021-03-31 20:11:51 -0300 |
commit | 6ec578e60101c3c02533f99715945a0400fb3286 (patch) | |
tree | 5368a84ddedf0c0da61fc9ec73ea148658821f0b /src | |
parent | aba24b51cc1b045a9810458b4bb15fee2c182948 (diff) | |
download | postgresql-6ec578e60101c3c02533f99715945a0400fb3286.tar.gz postgresql-6ec578e60101c3c02533f99715945a0400fb3286.zip |
Remove setvbuf() call from PQtrace()
It's misplaced there -- it's not libpq's output stream to tweak in that
way. In particular, POSIX says that it has to be called before any
other operation on the file, so if a stream previously used by the
calling application, bad things may happen.
Put setvbuf() in libpq_pipeline for good measure.
Also, reduce fopen(..., "w+") to just fopen(..., "w") in
libpq_pipeline.c. It's not clear that this fixes anything, but we don't
use w+ anywhere.
Per complaints from Tom Lane.
Discussion: https://postgr.es/m/3337422.1617229905@sss.pgh.pa.us
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/libpq/fe-trace.c | 2 | ||||
-rw-r--r-- | src/test/modules/libpq_pipeline/libpq_pipeline.c | 7 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c index ca59c183182..9a4595f5c87 100644 --- a/src/interfaces/libpq/fe-trace.c +++ b/src/interfaces/libpq/fe-trace.c @@ -40,8 +40,6 @@ PQtrace(PGconn *conn, FILE *debug_port) if (debug_port == NULL) return; - /* Make the trace stream line-buffered */ - setvbuf(debug_port, NULL, _IOLBF, 0); conn->Pfdebug = debug_port; conn->traceFlags = 0; } diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index 081a84f8248..7aa78662653 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -1319,10 +1319,13 @@ main(int argc, char **argv) /* Set the trace file, if requested */ if (tracefile != NULL) { - trace = fopen(tracefile, "w+"); - + trace = fopen(tracefile, "w"); if (trace == NULL) pg_fatal("could not open file \"%s\": %m", tracefile); + + /* Make it line-buffered */ + setvbuf(trace, NULL, _IOLBF, 0); + PQtrace(conn, trace); PQtraceSetFlags(conn, PQTRACE_SUPPRESS_TIMESTAMPS | PQTRACE_REGRESS_MODE); |