Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c0de38

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 atty or pipe fd by accepting EINVAL - but apparently someplatforms (windows, OSX) don't reliably return that. So instead checkwhether the output fd refers to a pipe or a tty when opening it.Reported-By: Olivier Gosseaume, Marko TiikkajaDiscussion: 559AF98B.3050901@joh.toBackpatch to 9.4, where pg_recvlogical was added.
1 parent02eac01 commit5c0de38

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
staticintoutfd=-1;
5151
staticvolatilesig_atomic_ttime_to_abort= false;
5252
staticvolatilesig_atomic_toutput_reopen= false;
53+
staticbooloutput_isfile;
5354
staticint64output_last_fsync=-1;
5455
staticbooloutput_needs_fsync= false;
5556
staticXLogRecPtroutput_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+
structstatstatbuf;
325+
320326
if (strcmp(outfile,"-")==0)
321327
outfd=fileno(stdout);
322328
else
@@ -329,6 +335,13 @@ StreamLogicalLog(void)
329335
progname,outfile,strerror(errno));
330336
gotoerror;
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)

[8]ページ先頭

©2009-2025 Movatter.jp