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

Commit1b192fc

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 parente150773 commit1b192fc

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
@@ -108,9 +108,15 @@ static intmax_safe_fds = 32;/* default if not changed */
108108
/* Debugging.... */
109109

110110
#ifdefFDDEBUG
111-
#defineDO_DB(A) A
111+
#defineDO_DB(A) \
112+
do { \
113+
int_do_db_save_errno = errno; \
114+
A; \
115+
errno = _do_db_save_errno; \
116+
} while (0)
112117
#else
113-
#defineDO_DB(A)/* A */
118+
#defineDO_DB(A) \
119+
((void) 0)
114120
#endif
115121

116122
#defineVFD_CLOSED (-1)
@@ -661,7 +667,7 @@ LruInsert(File file)
661667
if (vfdP->fd<0)
662668
{
663669
DO_DB(elog(LOG,"RE_OPEN FAILED: %d",errno));
664-
returnvfdP->fd;
670+
return-1;
665671
}
666672
else
667673
{
@@ -712,7 +718,7 @@ AllocateVfd(void)
712718
Indexi;
713719
Filefile;
714720

715-
DO_DB(elog(LOG,"AllocateVfd. Size %lu",SizeVfdCache));
721+
DO_DB(elog(LOG,"AllocateVfd. Size %lu",(unsigned long)SizeVfdCache));
716722

717723
Assert(SizeVfdCache>0);/* InitFileAccess not called? */
718724

@@ -869,8 +875,11 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
869875

870876
if (vfdP->fd<0)
871877
{
878+
intsave_errno=errno;
879+
872880
FreeVfd(file);
873881
free(fnamecopy);
882+
errno=save_errno;
874883
return-1;
875884
}
876885
++nfile;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp