Skip to content

Commit 6ec578e

Browse files
committed
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
1 parent aba24b5 commit 6ec578e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/interfaces/libpq/fe-trace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ PQtrace(PGconn *conn, FILE *debug_port)
4040
if (debug_port == NULL)
4141
return;
4242

43-
/* Make the trace stream line-buffered */
44-
setvbuf(debug_port, NULL, _IOLBF, 0);
4543
conn->Pfdebug = debug_port;
4644
conn->traceFlags = 0;
4745
}

src/test/modules/libpq_pipeline/libpq_pipeline.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,13 @@ main(int argc, char **argv)
13191319
/* Set the trace file, if requested */
13201320
if (tracefile != NULL)
13211321
{
1322-
trace = fopen(tracefile, "w+");
1323-
1322+
trace = fopen(tracefile, "w");
13241323
if (trace == NULL)
13251324
pg_fatal("could not open file \"%s\": %m", tracefile);
1325+
1326+
/* Make it line-buffered */
1327+
setvbuf(trace, NULL, _IOLBF, 0);
1328+
13261329
PQtrace(conn, trace);
13271330
PQtraceSetFlags(conn,
13281331
PQTRACE_SUPPRESS_TIMESTAMPS | PQTRACE_REGRESS_MODE);

0 commit comments

Comments
 (0)