mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Address set of issues with errno handling
System calls mixed up in error code paths are causing two issues which several code paths have not correctly handled: 1) For write() calls, sometimes the system may return less bytes than what has been written without errno being set. Some paths were careful enough to consider that case, and assumed that errno should be set to ENOSPC, other calls missed that. 2) errno generated by a system call is overwritten by other system calls which may succeed once an error code path is taken, causing what is reported to the user to be incorrect. This patch uses the brute-force approach of correcting all those code paths. Some refactoring could happen in the future, but this is let as future work, which is not targeted for back-branches anyway. Author: Michael Paquier Reviewed-by: Ashutosh Sharma Discussion: https://postgr.es/m/20180622061535.GD5215@paquier.xyz
This commit is contained in:
parent
6350dcc1f4
commit
6eec6724ff
@ -1169,9 +1169,14 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
|
|||||||
/* write out tail end of mapping file (again) */
|
/* write out tail end of mapping file (again) */
|
||||||
pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
|
pgstat_report_wait_start(WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE);
|
||||||
if (write(fd, data, len) != len)
|
if (write(fd, data, len) != len)
|
||||||
|
{
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m", path)));
|
errmsg("could not write to file \"%s\": %m", path)));
|
||||||
|
}
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1214,12 +1214,17 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
|
|||||||
*/
|
*/
|
||||||
if (fstat(fd, &stat))
|
if (fstat(fd, &stat))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
if (give_warnings)
|
if (give_warnings)
|
||||||
|
{
|
||||||
|
errno = save_errno;
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not stat two-phase state file \"%s\": %m",
|
errmsg("could not stat two-phase state file \"%s\": %m",
|
||||||
path)));
|
path)));
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1247,13 +1252,18 @@ ReadTwoPhaseFile(TransactionId xid, bool give_warnings)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_READ);
|
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_READ);
|
||||||
if (read(fd, buf, stat.st_size) != stat.st_size)
|
if (read(fd, buf, stat.st_size) != stat.st_size)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
if (give_warnings)
|
if (give_warnings)
|
||||||
|
{
|
||||||
|
errno = save_errno;
|
||||||
ereport(WARNING,
|
ereport(WARNING,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read two-phase state file \"%s\": %m",
|
errmsg("could not read two-phase state file \"%s\": %m",
|
||||||
path)));
|
path)));
|
||||||
|
}
|
||||||
pfree(buf);
|
pfree(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1597,16 +1607,26 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE);
|
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE);
|
||||||
if (write(fd, content, len) != len)
|
if (write(fd, content, len) != len)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write two-phase state file: %m")));
|
errmsg("could not write two-phase state file: %m")));
|
||||||
}
|
}
|
||||||
if (write(fd, &statefile_crc, sizeof(pg_crc32c)) != sizeof(pg_crc32c))
|
if (write(fd, &statefile_crc, sizeof(pg_crc32c)) != sizeof(pg_crc32c))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write two-phase state file: %m")));
|
errmsg("could not write two-phase state file: %m")));
|
||||||
@ -1620,7 +1640,10 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_SYNC);
|
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_SYNC);
|
||||||
if (pg_fsync(fd) != 0)
|
if (pg_fsync(fd) != 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not fsync two-phase state file: %m")));
|
errmsg("could not fsync two-phase state file: %m")));
|
||||||
|
@ -3243,7 +3243,10 @@ XLogFileInit(XLogSegNo logsegno, bool *use_existent, bool use_lock)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_SYNC);
|
pgstat_report_wait_start(WAIT_EVENT_WAL_INIT_SYNC);
|
||||||
if (pg_fsync(fd) != 0)
|
if (pg_fsync(fd) != 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
||||||
@ -11590,8 +11593,10 @@ retry:
|
|||||||
if (lseek(readFile, (off_t) readOff, SEEK_SET) < 0)
|
if (lseek(readFile, (off_t) readOff, SEEK_SET) < 0)
|
||||||
{
|
{
|
||||||
char fname[MAXFNAMELEN];
|
char fname[MAXFNAMELEN];
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
XLogFileName(fname, curFileTLI, readSegNo);
|
XLogFileName(fname, curFileTLI, readSegNo);
|
||||||
|
errno = save_errno;
|
||||||
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
|
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not seek in log segment %s to offset %u: %m",
|
errmsg("could not seek in log segment %s to offset %u: %m",
|
||||||
@ -11603,9 +11608,11 @@ retry:
|
|||||||
if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (read(readFile, readBuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
{
|
{
|
||||||
char fname[MAXFNAMELEN];
|
char fname[MAXFNAMELEN];
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
XLogFileName(fname, curFileTLI, readSegNo);
|
XLogFileName(fname, curFileTLI, readSegNo);
|
||||||
|
errno = save_errno;
|
||||||
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
|
ereport(emode_for_corrupt_record(emode, targetPagePtr + reqLen),
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read from log segment %s, offset %u: %m",
|
errmsg("could not read from log segment %s, offset %u: %m",
|
||||||
|
@ -716,9 +716,11 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
|||||||
if (lseek(sendFile, (off_t) startoff, SEEK_SET) < 0)
|
if (lseek(sendFile, (off_t) startoff, SEEK_SET) < 0)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
XLogFilePath(path, tli, sendSegNo);
|
XLogFilePath(path, tli, sendSegNo);
|
||||||
|
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not seek in log segment %s to offset %u: %m",
|
errmsg("could not seek in log segment %s to offset %u: %m",
|
||||||
@ -739,9 +741,11 @@ XLogRead(char *buf, TimeLineID tli, XLogRecPtr startptr, Size count)
|
|||||||
if (readbytes <= 0)
|
if (readbytes <= 0)
|
||||||
{
|
{
|
||||||
char path[MAXPGPATH];
|
char path[MAXPGPATH];
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
XLogFilePath(path, tli, sendSegNo);
|
XLogFilePath(path, tli, sendSegNo);
|
||||||
|
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read from log segment %s, offset %u, length %lu: %m",
|
errmsg("could not read from log segment %s, offset %u, length %lu: %m",
|
||||||
|
@ -463,6 +463,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
|||||||
fp = AllocateFile(pathbuf, "rb");
|
fp = AllocateFile(pathbuf, "rb");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Most likely reason for this is that the file was already
|
* Most likely reason for this is that the file was already
|
||||||
* removed by a checkpoint, so check for that to get a better
|
* removed by a checkpoint, so check for that to get a better
|
||||||
@ -470,6 +472,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
|||||||
*/
|
*/
|
||||||
CheckXLogRemoved(segno, tli);
|
CheckXLogRemoved(segno, tli);
|
||||||
|
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not open file \"%s\": %m", pathbuf)));
|
errmsg("could not open file \"%s\": %m", pathbuf)));
|
||||||
|
@ -579,7 +579,12 @@ CheckPointReplicationOrigin(void)
|
|||||||
/* write magic */
|
/* write magic */
|
||||||
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
|
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(tmpfd);
|
CloseTransientFile(tmpfd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m",
|
errmsg("could not write to file \"%s\": %m",
|
||||||
@ -618,7 +623,12 @@ CheckPointReplicationOrigin(void)
|
|||||||
if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
|
if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
|
||||||
sizeof(disk_state))
|
sizeof(disk_state))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(tmpfd);
|
CloseTransientFile(tmpfd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m",
|
errmsg("could not write to file \"%s\": %m",
|
||||||
@ -634,7 +644,12 @@ CheckPointReplicationOrigin(void)
|
|||||||
FIN_CRC32C(crc);
|
FIN_CRC32C(crc);
|
||||||
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
|
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(tmpfd);
|
CloseTransientFile(tmpfd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m",
|
errmsg("could not write to file \"%s\": %m",
|
||||||
|
@ -2309,7 +2309,9 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
|||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
errno = save_errno;
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to data file for XID %u: %m",
|
errmsg("could not write to data file for XID %u: %m",
|
||||||
|
@ -1606,7 +1606,12 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
|
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_WRITE);
|
||||||
if ((write(fd, ondisk, needed_length)) != needed_length)
|
if ((write(fd, ondisk, needed_length)) != needed_length)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m", tmppath)));
|
errmsg("could not write to file \"%s\": %m", tmppath)));
|
||||||
@ -1624,7 +1629,10 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_SYNC);
|
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_SYNC);
|
||||||
if (pg_fsync(fd) != 0)
|
if (pg_fsync(fd) != 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
||||||
@ -1709,7 +1717,10 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
if (readBytes != SnapBuildOnDiskConstantSize)
|
if (readBytes != SnapBuildOnDiskConstantSize)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read file \"%s\", read %d of %d: %m",
|
errmsg("could not read file \"%s\", read %d of %d: %m",
|
||||||
@ -1737,7 +1748,10 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
if (readBytes != sizeof(SnapBuild))
|
if (readBytes != sizeof(SnapBuild))
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read file \"%s\", read %d of %d: %m",
|
errmsg("could not read file \"%s\", read %d of %d: %m",
|
||||||
@ -1754,7 +1768,10 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
if (readBytes != sz)
|
if (readBytes != sz)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read file \"%s\", read %d of %d: %m",
|
errmsg("could not read file \"%s\", read %d of %d: %m",
|
||||||
@ -1770,7 +1787,10 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
if (readBytes != sz)
|
if (readBytes != sz)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not read file \"%s\", read %d of %d: %m",
|
errmsg("could not read file \"%s\", read %d of %d: %m",
|
||||||
|
@ -1268,7 +1268,9 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
|||||||
|
|
||||||
pgstat_report_wait_end();
|
pgstat_report_wait_end();
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
errno = save_errno;
|
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
ereport(elevel,
|
ereport(elevel,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not write to file \"%s\": %m",
|
errmsg("could not write to file \"%s\": %m",
|
||||||
@ -1372,7 +1374,10 @@ RestoreSlotFromDisk(const char *name)
|
|||||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC);
|
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC);
|
||||||
if (pg_fsync(fd) != 0)
|
if (pg_fsync(fd) != 0)
|
||||||
{
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
|
||||||
CloseTransientFile(fd);
|
CloseTransientFile(fd);
|
||||||
|
errno = save_errno;
|
||||||
ereport(PANIC,
|
ereport(PANIC,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not fsync file \"%s\": %m",
|
errmsg("could not fsync file \"%s\": %m",
|
||||||
|
@ -127,7 +127,11 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
|
|||||||
|
|
||||||
pg_free(zerobuf);
|
pg_free(zerobuf);
|
||||||
close(fd);
|
close(fd);
|
||||||
errno = save_errno;
|
|
||||||
|
/*
|
||||||
|
* If write didn't set errno, assume problem is no disk space.
|
||||||
|
*/
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -441,7 +445,14 @@ tar_write_compressed_data(void *buf, size_t count, bool flush)
|
|||||||
size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out;
|
size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out;
|
||||||
|
|
||||||
if (write(tar_data->fd, tar_data->zlibOut, len) != len)
|
if (write(tar_data->fd, tar_data->zlibOut, len) != len)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If write didn't set errno, assume problem is no disk space.
|
||||||
|
*/
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
tar_data->zp->next_out = tar_data->zlibOut;
|
tar_data->zp->next_out = tar_data->zlibOut;
|
||||||
tar_data->zp->avail_out = ZLIB_OUT_SIZE;
|
tar_data->zp->avail_out = ZLIB_OUT_SIZE;
|
||||||
@ -621,7 +632,8 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
|
|||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
pg_free(tar_data->currentfile);
|
pg_free(tar_data->currentfile);
|
||||||
tar_data->currentfile = NULL;
|
tar_data->currentfile = NULL;
|
||||||
errno = save_errno;
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
errno = save_errno ? save_errno : ENOSPC;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -816,7 +828,12 @@ tar_close(Walfile f, WalCloseMethod method)
|
|||||||
if (!tar_data->compression)
|
if (!tar_data->compression)
|
||||||
{
|
{
|
||||||
if (write(tar_data->fd, tf->header, 512) != 512)
|
if (write(tar_data->fd, tf->header, 512) != 512)
|
||||||
|
{
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
else
|
else
|
||||||
@ -882,7 +899,12 @@ tar_finish(void)
|
|||||||
if (!tar_data->compression)
|
if (!tar_data->compression)
|
||||||
{
|
{
|
||||||
if (write(tar_data->fd, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf))
|
if (write(tar_data->fd, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf))
|
||||||
|
{
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
else
|
else
|
||||||
@ -909,7 +931,15 @@ tar_finish(void)
|
|||||||
size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out;
|
size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out;
|
||||||
|
|
||||||
if (write(tar_data->fd, tar_data->zlibOut, len) != len)
|
if (write(tar_data->fd, tar_data->zlibOut, len) != len)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If write didn't set errno, assume problem is no disk
|
||||||
|
* space.
|
||||||
|
*/
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (r == Z_STREAM_END)
|
if (r == Z_STREAM_END)
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user