8000 reorderbuffer: preserve errno while reporting error · s-monk/postgres@07d4723 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 07d4723

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 1d990cd commit 07d4723

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,10 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
21362136

21372137
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
21382138
{
2139+
int save_errno = errno;
2140+
21392141
CloseTransientFile(fd);
2142+
errno = save_errno;
21402143
ereport(ERROR,
21412144
(errcode_for_file_access(),
21422145
errmsg("could not write to data file for XID %u: %m",
@@ -2865,7 +2868,8 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
28652868
fd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
28662869
if (fd < 0)
28672870
ereport(ERROR,
2868-
(errmsg("could not open file \"%s\": %m", path)));
2871+
(errcode_for_file_access(),
2872+
errmsg("could not open file \"%s\": %m", path)));
28692873

28702874
while (true)
28712875
{

0 commit comments

Comments
 (0)
0