1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-29 13:56:47 +03:00

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
This commit is contained in:
Alvaro Herrera 2021-03-31 20:11:51 -03:00
parent aba24b51cc
commit 6ec578e601
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
2 changed files with 5 additions and 4 deletions

View File

@ -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;
}

View File

@ -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);