8000 reorderbuffer: preserve errno while reporting error · patchsoft/postgres@ac3aac3 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac3aac3

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 c4f1540 commit ac3aac3

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
@@ -2207,7 +2207,10 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
22072207

22082208
if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
22092209
{
2210+
int save_errno = errno;
2211+
22102212
CloseTransientFile(fd);
2213+
errno = save_errno;
22112214
ereport(ERROR,
22122215
(errcode_for_file_access(),
22132216
errmsg("could not write to data file for XID %u: %m",
@@ -2936,7 +2939,8 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
29362939
fd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
29372940
if (fd < 0)
29382941
ereport(ERROR,
2939-
(errmsg("could not open file \"%s\": %m", path)));
2942+
(errcode_for_file_access(),
2943+
errmsg("could not open file \"%s\": %m", path)));
29402944

29412945
while (true)
29422946
{

0 commit comments

Comments
 (0)
0