Skip to content
Snippets Groups Projects
Commit e69a3ac4 authored by Michael Paquier's avatar Michael Paquier
Browse files

Reset properly errno before calling write()

6cb33724 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
parent 250528ce
No related branches found
Tags
No related merge requests found
...@@ -1172,6 +1172,7 @@ heap_xlog_logical_rewrite(XLogRecPtr lsn, XLogRecord *r) ...@@ -1172,6 +1172,7 @@ heap_xlog_logical_rewrite(XLogRecPtr lsn, XLogRecord *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 */
... ...
......
...@@ -1566,6 +1566,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) ...@@ -1566,6 +1566,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;
... ...
......
...@@ -2296,6 +2296,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn, ...@@ -2296,6 +2296,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) ...@@ -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;
... ...
......
...@@ -1026,6 +1026,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) ...@@ -1026,6 +1026,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
SnapBuildOnDiskChecksummedSize); SnapBuildOnDiskChecksummedSize);
FIN_CRC32(cp.checksum); FIN_CRC32(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;
... ...
......
...@@ -137,6 +137,7 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, ...@@ -137,6 +137,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 */
...@@ -1094,6 +1095,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, ...@@ -1094,6 +1095,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline,
} }
} }
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)
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment