mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +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",
|
||||
|
||||
Reference in New Issue
Block a user