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

Commit6563fb2

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 parente7bfc7e commit6563fb2

File tree

1 file changed

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

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,15 @@ intmax_safe_fds = 32;/* default if not changed */
128128
/* Debugging.... */
129129

130130
#ifdefFDDEBUG
131-
#defineDO_DB(A) A
131+
#defineDO_DB(A) \
132+
do { \
133+
int_do_db_save_errno = errno; \
134+
A; \
135+
errno = _do_db_save_errno; \
136+
} while (0)
132137
#else
133-
#defineDO_DB(A)/* A */
138+
#defineDO_DB(A) \
139+
((void) 0)
134140
#endif
135141

136142
#defineVFD_CLOSED (-1)
@@ -703,7 +709,7 @@ LruInsert(File file)
703709
if (vfdP->fd<0)
704710
{
705711
DO_DB(elog(LOG,"RE_OPEN FAILED: %d",errno));
706-
returnvfdP->fd;
712+
return-1;
707713
}
708714
else
709715
{
@@ -754,7 +760,7 @@ AllocateVfd(void)
754760
Indexi;
755761
Filefile;
756762

757-
DO_DB(elog(LOG,"AllocateVfd. Size %lu",SizeVfdCache));
763+
DO_DB(elog(LOG,"AllocateVfd. Size %lu",(unsigned long)SizeVfdCache));
758764

759765
Assert(SizeVfdCache>0);/* InitFileAccess not called? */
760766

@@ -911,8 +917,11 @@ PathNameOpenFile(FileName fileName, int fileFlags, int fileMode)
911917

912918
if (vfdP->fd<0)
913919
{
920+
intsave_errno=errno;
921+
914922
FreeVfd(file);
915923
free(fnamecopy);
924+
errno=save_errno;
916925
return-1;
917926
}
918927
++nfile;
@@ -1554,7 +1563,6 @@ OpenTransientFile(FileName fileName, int fileFlags, int fileMode)
15541563
{
15551564
intfd;
15561565

1557-
15581566
DO_DB(elog(LOG,"OpenTransientFile: Allocated %d (%s)",
15591567
numAllocatedDescs,fileName));
15601568

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp