diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-01-26 22:35:32 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-01-26 22:35:32 +0000 |
commit | c77f363384c3f4a6bbc73f501d2459e94382a30b (patch) | |
tree | c722b460526c687c1ec9c546aed71b52fbcb3cc4 /src/backend/access/transam | |
parent | e0707cbae9cb5360cd044231fda921fffe8095c5 (diff) | |
download | postgresql-c77f363384c3f4a6bbc73f501d2459e94382a30b.tar.gz postgresql-c77f363384c3f4a6bbc73f501d2459e94382a30b.zip |
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.
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r-- | src/backend/access/transam/slru.c | 28 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 29 |
2 files changed, 45 insertions, 12 deletions
diff --git a/src/backend/access/transam/slru.c b/src/backend/access/transam/slru.c index a9bf0fcd2cb..73c481c46b7 100644 --- a/src/backend/access/transam/slru.c +++ b/src/backend/access/transam/slru.c @@ -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", diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 81ff16dd633..fe1ecd453c5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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", |