summaryrefslogtreecommitdiff
path: root/src/backend/replication/basebackup.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-06-25 11:20:50 +0900
committerMichael Paquier <michael@paquier.xyz>2018-06-25 11:20:50 +0900
commit7fdf56b0a796f9e6f625c8fa236ece72b91b2270 (patch)
tree4b12e5db74f7a0e96ad08ccadb09e4f0bf6cea7e /src/backend/replication/basebackup.c
parent037768cf75707cb00ef5c1c1d70b0c6a6800206b (diff)
Address set of issues with errno handling
System calls mixed up in error code paths are causing two issues which several code paths have not correctly handled: 1) For write() calls, sometimes the system may return less bytes than what has been written without errno being set. Some paths were careful enough to consider that case, and assumed that errno should be set to ENOSPC, other calls missed that. 2) errno generated by a system call is overwritten by other system calls which may succeed once an error code path is taken, causing what is reported to the user to be incorrect. This patch uses the brute-force approach of correcting all those code paths. Some refactoring could happen in the future, but this is let as future work, which is not targeted for back-branches anyway. Author: Michael Paquier Reviewed-by: Ashutosh Sharma Discussion: https://postgr.es/m/20180622061535.GD5215@paquier.xyz
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r--src/backend/replication/basebackup.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index 53be5d55e49..73a56cbf16e 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -392,6 +392,8 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
fp = AllocateFile(pathbuf, "rb");
if (fp == NULL)
{
+ int save_errno = errno;
+
/*
* Most likely reason for this is that the file was already
* removed by a checkpoint, so check for that to get a better
@@ -399,6 +401,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
*/
CheckXLogRemoved(segno, tli);
+ errno = save_errno;
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", pathbuf)));