Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite7e005e

Browse files
committed
Fix fd.c to preserve errno where needed.
PathNameOpenFile failed to ensure that the correct value of errno wasreturned to its caller after a failure (because it incorrectly supposedthat free() can never change errno). In some cases this would resultin a user-visible failure because an expected ENOENT errno was replacedwith 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 valueof errno if FDDEBUG was defined. While the usefulness of that debugsupport 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.
1 parent630a8af commite7e005e

File tree

1 file changed

+13
-4
lines changed
  • src/backend/storage/file

1 file changed

+13
-4
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,15 @@ intmax_safe_fds = 32;/* default if not changed */
109109
/* Debugging.... */
110110

111111
#ifdefFDDEBUG
112-
#defineDO_DB(A) A
112+
#defineDO_DB(A) \
113+
do { \
114+
int_do_db_save_errno = errno; \
115+
A; \
116+
errno = _do_db_save_errno; \
117+
} while (0)
113118
#else
114-
#defineDO_DB(A)/* A */
119+
#defineDO_DB(A) \
120+
((void) 0)
115121
#endif
116122

117123
#defineVFD_CLOSED (-1)
@@ -674,7 +680,7 @@ LruInsert(File file)
674680
if (vfdP->fd<0)
675681
{
676682
DO_DB(elog(LOG,"RE_OPEN FAILED: %d",errno));
677-
returnvfdP->fd;
683+
return-1;
678684
}
679685
else
680686
{
@@ -725,7 +731,7 @@ AllocateVfd(void)
725731
Indexi;
726732
Filefile;
727733

728-
DO_DB(elog(LOG,"AllocateVfd. Size %lu",SizeVfdCache));
734+
DO_DB(elog(LOG,"AllocateVfd. Size %lu",(unsigned long)SizeVfdCache));
729735

730736
Assert(SizeVfdCache>0);/* InitFileAccess not called? */
731737

@@ -882,8 +888,11 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
882888

883889
if (vfdP->fd<0)
884890
{
891+
intsave_errno=errno;
892+
885893
FreeVfd(file);
886894
free(fnamecopy);
895+
errno=save_errno;
887896
return-1;
888897
}
889898
++nfile;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp