Skip to content

Instantly share code, notes, and snippets.

@NelsonMinar
Created May 20, 2013 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NelsonMinar/5612580 to your computer and use it in GitHub Desktop.
Save NelsonMinar/5612580 to your computer and use it in GitHub Desktop.
Patch for PostgresSQL bug on Macs. Modified slightly from upstream fix so that it applies cleanly. Originally from https://github.com/postgres/postgres/commit/6563fb2b45146852601e63828308fe04fb03b9e9
From 6563fb2b45146852601e63828308fe04fb03b9e9 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 16 May 2013 15:04:31 -0400
Subject: [PATCH] Fix fd.c to preserve errno where needed.
PathNameOpenFile failed to ensure that the correct value of errno was
returned to its caller after a failure (because it incorrectly supposed
that free() can never change errno). In some cases this would result
in a user-visible failure because an expected ENOENT errno was replaced
with something else. Bogus EINVAL failures have been observed on OS X,
for example.
There were also a couple of places that could mangle an important value
of errno if FDDEBUG was defined. While the usefulness of that debug
support is highly debatable, we might as well make it safe to use,
so add errno save/restore logic to the DO_DB macro.
Per bug #8167 from Nelson Minar, diagnosed by RhodiumToad.
Back-patch to all supported branches.
---
src/backend/storage/file/fd.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index c31a523..78c7d41 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -128,9 +128,15 @@
/* Debugging.... */
#ifdef FDDEBUG
-#define DO_DB(A) A
+#define DO_DB(A) \
+ do { \
+ int _do_db_save_errno = errno; \
+ A; \
+ errno = _do_db_save_errno; \
+ } while (0)
#else
-#define DO_DB(A) /* A */
+#define DO_DB(A) \
+ ((void) 0)
#endif
#define VFD_CLOSED (-1)
@@ -703,7 +709,7 @@
if (vfdP->fd < 0)
{
DO_DB(elog(LOG, "RE_OPEN FAILED: %d", errno));
- return vfdP->fd;
+ return -1;
}
else
{
@@ -754,7 +760,7 @@
Index i;
File file;
- DO_DB(elog(LOG, "AllocateVfd. Size %lu", SizeVfdCache));
+ DO_DB(elog(LOG, "AllocateVfd. Size %lu", (unsigned long) SizeVfdCache));
Assert(SizeVfdCache > 0); /* InitFileAccess not called? */
@@ -911,8 +917,11 @@
if (vfdP->fd < 0)
{
+ int save_errno = errno;
+
FreeVfd(file);
free(fnamecopy);
+ errno = save_errno;
return -1;
}
++nfile;
--
1.8.1.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment