aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-08-05 05:32:37 +0900
committerMichael Paquier <michael@paquier.xyz>2018-08-05 05:32:37 +0900
commitafd5fde856675f54a7b5d857f7a173f9a3237b57 (patch)
treeda31bb9c247fb82b42edf8d61cbbb7c2b5ace49f /src/backend/replication/logical
parentaca22574106e05d297bd04874ffa0ccbdb768e29 (diff)
downloadpostgresql-afd5fde856675f54a7b5d857f7a173f9a3237b57.tar.gz
postgresql-afd5fde856675f54a7b5d857f7a173f9a3237b57.zip
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
Diffstat (limited to 'src/backend/replication/logical')
-rw-r--r--src/backend/replication/logical/origin.c3
-rw-r--r--src/backend/replication/logical/reorderbuffer.c1
-rw-r--r--src/backend/replication/logical/snapbuild.c1
3 files changed, 5 insertions, 0 deletions
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 4ecd6a9eae0..94832a105bf 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -547,6 +547,7 @@ CheckPointReplicationOrigin(void)
tmppath)));
/* write magic */
+ errno = 0;
if ((write(tmpfd, &magic, sizeof(magic))) != sizeof(magic))
{
int save_errno = errno;
@@ -590,6 +591,7 @@ CheckPointReplicationOrigin(void)
/* make sure we only write out a commit that's persistent */
XLogFlush(local_lsn);
+ errno = 0;
if ((write(tmpfd, &disk_state, sizeof(disk_state))) !=
sizeof(disk_state))
{
@@ -612,6 +614,7 @@ CheckPointReplicationOrigin(void)
/* write out the CRC */
FIN_CRC32C(crc);
+ errno = 0;
if ((write(tmpfd, &crc, sizeof(crc))) != sizeof(crc))
{
int save_errno = errno;
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 3606e9ec7ff..b73ac5b9243 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -2369,6 +2369,7 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
ondisk->size = sz;
+ errno = 0;
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
{
int save_errno = errno;
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 2c96fbd5067..7a06fe086f6 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -1571,6 +1571,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
ereport(ERROR,
(errmsg("could not open file \"%s\": %m", path)));
+ errno = 0;
if ((write(fd, ondisk, needed_length)) != needed_length)
{
int save_errno = errno;