postgres.git / summary / log / commit / refs
commit 2bd49b493a52f0a21bc3fc51c355963f99ac1a4e
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue Nov 17 01:32:35 2020 +0000
First released in: 14.0, 9.5.25, 9.6.21, 10.16, 11.11, 12.6, 13.2
Don't Insert() a VFD entry until it's fully built.
Otherwise, if FDDEBUG is enabled, the debugging output fails because
it tries to read the fileName, which isn't set up yet (and should in
fact always be NULL).
AFAICT, this has been wrong since Berkeley. Before 96bf88d52,
it would accidentally fail to crash on platforms where snprintf()
is forgiving about being passed a NULL pointer for %s; but the
file name intended to be included in the debug output wouldn't
ever have shown up.
Report and fix by Greg Nancarrow. Although this is only visibly
broken in custom-made builds, it still seems worth back-patching
to all supported branches, as the FDDEBUG code is pretty useless
as it stands.
Discussion: https://postgr.es/m/CAJcOf-cUDgm9qYtC_B6XrC6MktMPNRby2p61EtSGZKnfotMArw@mail.gmail.com
src/backend/storage/file/fd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index bd72a87ee30..05abcf72d68 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -1486,8 +1486,6 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)
DO_DB(elog(LOG, "PathNameOpenFile: success %d",
vfdP->fd));
- Insert(file);
-
vfdP->fileName = fnamecopy;
/* Saved flags are adjusted to be OK for re-opening file */
vfdP->fileFlags = fileFlags & ~(O_CREAT | O_TRUNC | O_EXCL);
@@ -1496,6 +1494,8 @@ PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)
vfdP->fdstate = 0x0;
vfdP->resowner = NULL;
+ Insert(file);
+
return file;
}
[parent: cd9c1b3e197a]