mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Ensure that close() and fclose() are checked for errors, at least in
cases involving writes. Per recent discussion about the possibility of close-time failures on some filesystems. There is a TODO item for this, too.
This commit is contained in:
5
src/backend/utils/cache/relcache.c
vendored
5
src/backend/utils/cache/relcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.194 2003/12/28 21:57:37 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.195 2004/01/26 22:35:32 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -3330,7 +3330,8 @@ write_relcache_init_file(void)
|
||||
MemoryContextSwitchTo(oldcxt);
|
||||
}
|
||||
|
||||
FreeFile(fp);
|
||||
if (FreeFile(fp))
|
||||
elog(FATAL, "could not write init file");
|
||||
|
||||
/*
|
||||
* Now we have to check whether the data we've so painstakingly
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.119 2004/01/08 06:01:21 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.120 2004/01/26 22:35:32 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -622,7 +622,16 @@ CreateLockFile(const char *filename, bool amPostmaster,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write lock file \"%s\": %m", filename)));
|
||||
}
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
unlink(filename);
|
||||
errno = save_errno;
|
||||
ereport(FATAL,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write lock file \"%s\": %m", filename)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Arrange for automatic removal of lockfile at proc_exit.
|
||||
@@ -776,7 +785,13 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write to file \"%s\": %m",
|
||||
directoryLockFile)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.180 2004/01/24 20:00:45 wieck Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.181 2004/01/26 22:35:32 tgl Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@@ -3971,7 +3971,16 @@ write_nondefault_variables(GucContext context)
|
||||
}
|
||||
}
|
||||
|
||||
FreeFile(fp);
|
||||
if (FreeFile(fp))
|
||||
{
|
||||
free(new_filename);
|
||||
free(filename);
|
||||
ereport(elevel,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write to file \"%s\": %m", CONFIG_EXEC_PARAMS)));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Put new file in place, this could delay on Win32 */
|
||||
rename(new_filename, filename);
|
||||
free(new_filename);
|
||||
|
||||
Reference in New Issue
Block a user