Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0440f49

Browse files
committed
reorderbuffer: preserve errno while reporting error
Clobbering errno during cleanup after an error is an oft-repeated, easy to make mistake. Deal with it here as everywhere else, by saving it aside and restoring after cleanup, before ereport'ing. In passing, add a missing errcode declaration in another ereport() call in the same file, which I noticed while skimming the file looking for similar problems. Backpatch to 9.4, where this code was introduced.
1 parent 2b4ae9c commit 0440f49

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/replication/logical/reorderbuffer.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,10 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
23172317

23182318
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
23192319
{
2320+
int save_errno = errno;
2321+
23202322
CloseTransientFile(fd);
2323+
errno = save_errno;
23212324
ereport(ERROR,
23222325
(errcode_for_file_access(),
23232326
errmsg("could not write to data file for XID %u: %m",
@@ -3070,7 +3073,8 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
30703073
fd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
30713074
if (fd < 0)
30723075
ereport(ERROR,
3073-
(errmsg("could not open file \"%s\": %m", path)));
3076+
(errcode_for_file_access(),
3077+
errmsg("could not open file \"%s\": %m", path)));
30743078

30753079
while (true)
30763080
{

0 commit comments

Comments
 (0)