static volatile sig_atomic_t time_to_abort = false;
static volatile sig_atomic_t output_reopen = false;
static int64 output_last_fsync = -1;
-static bool output_unsynced = false;
+static bool output_needs_fsync = false;
static XLogRecPtr output_written_lsn = InvalidXLogRecPtr;
static XLogRecPtr output_fsync_lsn = InvalidXLogRecPtr;
if (fsync_interval <= 0)
return true;
- if (!output_unsynced)
+ if (!output_needs_fsync)
return true;
- output_unsynced = false;
+ output_needs_fsync = false;
/* Accept EINVAL, in case output is writing to a pipe or similar. */
if (fsync(outfd) != 0 && errno != EINVAL)
last_status = now;
}
+ /* got SIGHUP, close output file */
+ if (outfd != -1 && output_reopen && strcmp(outfile, "-") != 0)
+ {
+ now = feGetCurrentTimestamp();
+ if (!OutputFsync(now))
+ goto error;
+ close(outfd);
+ outfd = -1;
+ }
+ output_reopen = false;
+
r = PQgetCopyData(conn, ©buf, 1);
if (r == 0)
{
((int64) 1000);
/* Compute when we need to wakeup to fsync the output file. */
- if (fsync_interval > 0 && output_unsynced)
+ if (fsync_interval > 0 && output_needs_fsync)
fsync_target = output_last_fsync + (fsync_interval - 1) *
((int64) 1000);
output_written_lsn = Max(temp, output_written_lsn);
}
- /* redirect output to stdout */
- if (outfd == -1 && strcmp(outfile, "-") == 0)
- {
- outfd = fileno(stdout);
- }
-
- /* got SIGHUP, close output file */
- if (outfd != -1 && output_reopen)
- {
- now = feGetCurrentTimestamp();
- if (!OutputFsync(now))
- goto error;
- close(outfd);
- outfd = -1;
- output_reopen = false;
- }
-
+ /* open the output file, if not open yet */
if (outfd == -1)
{
-
- outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY,
- S_IRUSR | S_IWUSR);
+ if (strcmp(outfile, "-") == 0)
+ outfd = fileno(stdout);
+ else
+ outfd = open(outfile, O_CREAT | O_APPEND | O_WRONLY | PG_BINARY,
+ S_IRUSR | S_IWUSR);
if (outfd == -1)
{
fprintf(stderr,
bytes_written = 0;
/* signal that a fsync is needed */
- output_unsynced = true;
+ output_needs_fsync = true;
while (bytes_left)
{