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

Commit9d8bc2f

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 parentee24949 commit9d8bc2f

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)
@@ -664,7 +670,7 @@ LruInsert(File file)
664670
if (vfdP->fd<0)
665671
{
666672
DO_DB(elog(LOG,"RE_OPEN FAILED: %d",errno));
667-
returnvfdP->fd;
673+
return-1;
668674
}
669675
else
670676
{
@@ -715,7 +721,7 @@ AllocateVfd(void)
715721
Indexi;
716722
Filefile;
717723

718-
DO_DB(elog(LOG,"AllocateVfd. Size %lu",SizeVfdCache));
724+
DO_DB(elog(LOG,"AllocateVfd. Size %lu",(unsigned long)SizeVfdCache));
719725

720726
Assert(SizeVfdCache>0);/* InitFileAccess not called? */
721727

@@ -872,8 +878,11 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
872878

873879
if (vfdP->fd<0)
874880
{
881+
intsave_errno=errno;
882+
875883
FreeVfd(file);
876884
free(fnamecopy);
885+
errno=save_errno;
877886
return-1;
878887
}
879888
++nfile;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp