Fix fd.c to preserve errno where needed.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 May 2013 19:04:31 +0000 (15:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 May 2013 19:04:31 +0000 (15:04 -0400)
commit6563fb2b45146852601e63828308fe04fb03b9e9
tree9f661ec90ee01597c8a64c777fd3d9336b4d25ac
parente7bfc7e42cebf80507f9c9965dc4a572e9fb76a4
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