diff options
author | Michael Paquier | 2018-08-04 20:32:54 +0000 |
---|---|---|
committer | Michael Paquier | 2018-08-04 20:32:54 +0000 |
commit | 69599cc49e7cc48f180e49322aea00c1ec634388 (patch) | |
tree | 748239159b16d5e740249cdae47cfd0a2d6392d9 | |
parent | 0229e087df2ac050f53140fd7497d0e70943d16f (diff) |
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
-rw-r--r-- | src/backend/access/transam/twophase.c | 1 | ||||
-rw-r--r-- | src/bin/pg_basebackup/receivelog.c | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 3c732d8f801..06a16d1fb7d 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1565,6 +1565,7 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len) path))); /* Write content and CRC */ + errno = 0; if (write(fd, content, len) != len) { int save_errno = errno; diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c index 3e12d63530e..b2891431eae 100644 --- a/src/bin/pg_basebackup/receivelog.c +++ b/src/bin/pg_basebackup/receivelog.c @@ -138,6 +138,7 @@ open_walfile(XLogRecPtr startpoint, uint32 timeline, char *basedir, zerobuf = pg_malloc0(XLOG_BLCKSZ); for (bytes = 0; bytes < XLogSegSize; bytes += XLOG_BLCKSZ) { + errno = 0; if (write(f, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) { /* if write didn't set errno, assume problem is no disk space */ @@ -1129,6 +1130,7 @@ HandleCopyStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, } } + errno = 0; if (write(walfile, copybuf + hdr_len + bytes_written, bytes_to_write) != bytes_to_write) |