mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +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:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.8 2003/11/29 19:51:40 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.9 2004/01/26 22:35:31 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -144,7 +144,8 @@ typedef enum
|
||||
SLRU_CREATE_FAILED,
|
||||
SLRU_SEEK_FAILED,
|
||||
SLRU_READ_FAILED,
|
||||
SLRU_WRITE_FAILED
|
||||
SLRU_WRITE_FAILED,
|
||||
SLRU_CLOSE_FAILED
|
||||
} SlruErrorCause;
|
||||
static SlruErrorCause slru_errcause;
|
||||
static int slru_errno;
|
||||
@@ -510,7 +511,13 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
{
|
||||
slru_errcause = SLRU_CLOSE_FAILED;
|
||||
slru_errno = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -587,7 +594,13 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno)
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
{
|
||||
slru_errcause = SLRU_CLOSE_FAILED;
|
||||
slru_errno = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -642,6 +655,13 @@ SlruReportIOError(SlruCtl ctl, int pageno, TransactionId xid)
|
||||
errdetail("could not write to file \"%s\" at offset %u: %m",
|
||||
path, offset)));
|
||||
break;
|
||||
case SLRU_CLOSE_FAILED:
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not access status of transaction %u", xid),
|
||||
errdetail("could not close file \"%s\": %m",
|
||||
path)));
|
||||
break;
|
||||
default:
|
||||
/* can't get here, we trust */
|
||||
elog(ERROR, "unrecognized SimpleLru error cause: %d",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.132 2004/01/19 19:04:40 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.133 2004/01/26 22:35:31 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1044,7 +1044,7 @@ XLogWrite(XLogwrtRqst WriteRqst)
|
||||
*/
|
||||
if (openLogFile >= 0)
|
||||
{
|
||||
if (close(openLogFile) != 0)
|
||||
if (close(openLogFile))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close log file %u, segment %u: %m",
|
||||
@@ -1162,7 +1162,7 @@ XLogWrite(XLogwrtRqst WriteRqst)
|
||||
if (openLogFile >= 0 &&
|
||||
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
|
||||
{
|
||||
if (close(openLogFile) != 0)
|
||||
if (close(openLogFile))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close log file %u, segment %u: %m",
|
||||
@@ -1427,7 +1427,10 @@ XLogFileInit(uint32 log, uint32 seg,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close file \"%s\": %m", tmppath)));
|
||||
|
||||
/*
|
||||
* Now move the segment into place with its final name.
|
||||
@@ -2205,7 +2208,10 @@ WriteControlFile(void)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync control file: %m")));
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close control file: %m")));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2382,7 +2388,10 @@ UpdateControlFile(void)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync control file: %m")));
|
||||
|
||||
close(fd);
|
||||
if (close(fd))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close control file: %m")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2535,7 +2544,11 @@ BootStrapXLOG(void)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync bootstrap transaction log file: %m")));
|
||||
|
||||
close(openLogFile);
|
||||
if (close(openLogFile))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close bootstrap transaction log file: %m")));
|
||||
|
||||
openLogFile = -1;
|
||||
|
||||
memset(ControlFile, 0, sizeof(ControlFileData));
|
||||
@@ -3577,7 +3590,7 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
|
||||
openLogId, openLogSeg)));
|
||||
if (open_sync_bit != new_sync_bit)
|
||||
{
|
||||
if (close(openLogFile) != 0)
|
||||
if (close(openLogFile))
|
||||
ereport(PANIC,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not close log file %u, segment %u: %m",
|
||||
|
||||
Reference in New Issue
Block a user