Reset properly errno before calling write()
6cb3372 enforces errno to ENOSPC when less bytes than what is expected have been written when it is unset, though it forgot to properly reset errno before doing a system call to write(), causing errno to potentially come from a previous system call. Reported-by: Tom Lane Author: Michael Paquier Reviewed-by: Tom Lane Discussion: https://postgr.es/m/31797.1533326676@sss.pgh.pa.us
This commit is contained in:
parent
aca2257410
commit
afd5fde856
@ -1164,6 +1164,7 @@ heap_xlog_logical_rewrite(XLogReaderState *r)
|
|||||||
len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
|
len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
|
||||||
|
|
||||||
/* write out tail end of mapping file (again) */
|
/* write out tail end of mapping file (again) */
|
||||||
|
errno = 0;
|
||||||
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 write didn't set errno, assume problem is no disk space */
|
||||||
|
@ -1577,6 +1577,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
|
|||||||
path)));
|
path)));
|
||||||
|
|
||||||
/* Write content and CRC */
|
/* Write content and CRC */
|
||||||
|
errno = 0;
|
||||||
if (write(fd, content, len) != len)
|
if (write(fd, content, len) != len)
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
@ -547,6 +547,7 @@ CheckPointReplicationOrigin(void)
|
|||||||
tmppath)));
|
tmppath)));
|
||||||
|
|
||||||
/* write magic */
|
/* write magic */
|
||||||
|
errno = 0;
|
||||||
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
|
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
@ -590,6 +591,7 @@ CheckPointReplicationOrigin(void)
|
|||||||
/* make sure we only write out a commit that's persistent */
|
/* make sure we only write out a commit that's persistent */
|
||||||
XLogFlush(local_lsn);
|
XLogFlush(local_lsn);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
|
if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
|
||||||
sizeof(disk_state))
|
sizeof(disk_state))
|
||||||
{
|
{
|
||||||
@ -612,6 +614,7 @@ CheckPointReplicationOrigin(void)
|
|||||||
|
|
||||||
/* write out the CRC */
|
/* write out the CRC */
|
||||||
FIN_CRC32C(crc);
|
FIN_CRC32C(crc);
|
||||||
|
errno = 0;
|
||||||
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
|
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
@ -2369,6 +2369,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
|
|||||||
|
|
||||||
ondisk->size = sz;
|
ondisk->size = sz;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
|
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
@ -1571,6 +1571,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
|
|||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errmsg("could not open file \"%s\": %m", path)));
|
(errmsg("could not open file \"%s\": %m", path)));
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if ((write(fd, ondisk, needed_length)) != needed_length)
|
if ((write(fd, ondisk, needed_length)) != needed_length)
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
@ -1028,6 +1028,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
|||||||
SnapBuildOnDiskChecksummedSize);
|
SnapBuildOnDiskChecksummedSize);
|
||||||
FIN_CRC32C(cp.checksum);
|
FIN_CRC32C(cp.checksum);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
|
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
@ -157,6 +157,7 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir,
|
|||||||
zerobuf = pg_malloc0(XLOG_BLCKSZ);
|
zerobuf = pg_malloc0(XLOG_BLCKSZ);
|
||||||
for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ)
|
for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ)
|
||||||
{
|
{
|
||||||
|
errno = 0;
|
||||||
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
|
||||||
{
|
{
|
||||||
/* if write didn't set errno, assume problem is no disk space */
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
@ -1217,6 +1218,7 @@ ProcessXLogDataMsg(PGconn *conn, char *copybuf, int len,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
if (write(walfile,
|
if (write(walfile,
|
||||||
copybuf + hdr_len + bytes_written,
|
copybuf + hdr_len + bytes_written,
|
||||||
bytes_to_write) != bytes_to_write)
|
bytes_to_write) != bytes_to_write)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user