Skip to content

Commit 1790b35

Browse files
committed
Fix pg_recvlogical not to fsync output when it's a tty or pipe.
The previous coding tried to handle possible failures when fsyncing a tty or pipe fd by accepting EINVAL - but apparently some platforms (windows, OSX) don't reliably return that. So instead check whether the output fd refers to a pipe or a tty when opening it. Reported-By: Olivier Gosseaume, Marko Tiikkaja Discussion: 559AF98B.3050901@joh.to Backpatch to 9.4, where pg_recvlogical was added.
1 parent 0471894 commit 1790b35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/bin/pg_basebackup/pg_recvlogical.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static const char *plugin = "test_decoding";
5050
static int outfd = -1;
5151
static volatile sig_atomic_t time_to_abort = false;
5252
static volatile sig_atomic_t output_reopen = false;
53+
static bool output_isfile;
5354
static int64 output_last_fsync = -1;
5455
static bool output_needs_fsync = false;
5556
static XLogRecPtr output_written_lsn = InvalidXLogRecPtr;
@@ -177,8 +178,11 @@ OutputFsync(int64 now)
177178

178179
output_needs_fsync = false;
179180

180-
/* Accept EINVAL, in case output is writing to a pipe or similar. */
181-
if (fsync(outfd) != 0 && errno != EINVAL)
181+
/* can only fsync if it's a regular file */
182+
if (!output_isfile)
183+
return true;
184+
185+
if (fsync(outfd) != 0)
182186
{
183187
fprintf(stderr,
184188
_("%s: could not fsync log file \"%s\": %s\n"),
@@ -317,6 +321,8 @@ StreamLogicalLog(void)
317321
/* open the output file, if not open yet */
318322
if (outfd == -1)
319323
{
324+
struct stat statbuf;
325+
320326
if (strcmp(outfile, "-") == 0)
321327
outfd = fileno(stdout);
322328
else
@@ -329,6 +335,13 @@ StreamLogicalLog(void)
329335
progname, outfile, strerror(errno));
330336
goto error;
331337
}
338+
339+
if (fstat(outfd, &statbuf) != 0)
340+
fprintf(stderr,
341+
_("%s: could not stat file \"%s\": %s\n"),
342+
progname, outfile, strerror(errno));
343+
344+
output_isfile = S_ISREG(statbuf.st_mode) && !isatty(outfd);
332345
}
333346

334347
r = PQgetCopyData(conn, &copybuf, 1);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy