]> granicus.if.org Git - postgresql/commitdiff
reorderbuffer: preserve errno while reporting error
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 19 Aug 2016 17:38:55 +0000 (14:38 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 19 Aug 2016 17:38:55 +0000 (14:38 -0300)
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.

src/backend/replication/logical/reorderbuffer.c

index 30aa5706d881c14b30a3bf218b1e795ad32104d4..3b63e21dbd0a7c0b1053fd412915e9c25000f0c4 100644 (file)
@@ -2136,7 +2136,10 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
 
        if (write(fd, rb->outbuf, ondisk->size) != ondisk->size)
        {
+               int save_errno = errno;
+
                CloseTransientFile(fd);
+               errno = save_errno;
                ereport(ERROR,
                                (errcode_for_file_access(),
                                 errmsg("could not write to data file for XID %u: %m",
@@ -2865,7 +2868,8 @@ ApplyLogicalMappingFile(HTAB *tuplecid_data, Oid relid, const char *fname)
        fd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
        if (fd < 0)
                ereport(ERROR,
-                               (errmsg("could not open file \"%s\": %m", path)));
+                               (errcode_for_file_access(),
+                                errmsg("could not open file \"%s\": %m", path)));
 
        while (true)
        {