Skip to content

Commit e69a3ac

Browse files
committed
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
1 parent 250528c commit e69a3ac

File tree

6 files changed

+7
-0
lines changed

6 files changed

+7
-0
lines changed

src/backend/access/heap/rewriteheap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ heap_xlog_logical_rewrite(XLogRecPtr lsn, XLogRecord *r)
11721172
len = xlrec->num_mappings * sizeof(LogicalRewriteMappingData);
11731173

11741174
/* write out tail end of mapping file (again) */
1175+
errno = 0;
11751176
if (write(fd, data, len) != len)
11761177
{
11771178
/* if write didn't set errno, assume problem is no disk space */

src/backend/access/transam/twophase.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
15661566
path)));
15671567

15681568
/* Write content and CRC */
1569+
errno = 0;
15691570
if (write(fd, content, len) != len)
15701571
{
15711572
int save_errno = errno;

src/backend/replication/logical/reorderbuffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
22962296

22972297
ondisk->size = sz;
22982298

2299+
errno = 0;
22992300
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
23002301
{
23012302
int save_errno = errno;

src/backend/replication/logical/snapbuild.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15711571
ereport(ERROR,
15721572
(errmsg("could not open file \"%s\": %m", path)));
15731573

1574+
errno = 0;
15741575
if ((write(fd, ondisk, needed_length)) != needed_length)
15751576
{
15761577
int save_errno = errno;

src/backend/replication/slot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
10261026
SnapBuildOnDiskChecksummedSize);
10271027
FIN_CRC32(cp.checksum);
10281028

1029+
errno = 0;
10291030
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
10301031
{
10311032
int save_errno = errno;

src/bin/pg_basebackup/receivelog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir,
137137
zerobuf = pg_malloc0(XLOG_BLCKSZ);
138138
for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ)
139139
{
140+
errno = 0;
140141
if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
141142
{
142143
/* if write didn't set errno, assume problem is no disk space */
@@ -1094,6 +1095,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
10941095
}
10951096
}
10961097

1098+
errno = 0;
10971099
if (write(walfile,
10981100
copybuf + hdr_len + bytes_written,
10991101
bytes_to_write) != bytes_to_write)

0 commit comments

Comments
 (0)