index e6b6676706fdb596a07a97e2b3eb49fc9d039224..973f5840671f75e557937ff3e9429992defac668 100644 (file)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.184 2010年04月20日 23:48:47 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.185 2010年08月16日 17:32:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -818,6 +818,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
* admin) but has left orphan backends behind. Check for this by
* looking to see if there is an associated shmem segment that is
* still in use.
+ *
+ * Note: because postmaster.pid is written in two steps, we might not
+ * find the shmem ID values in it; we can't treat that as an error.
*/
if (isDDLock)
{
@@ -881,7 +884,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
(errcode_for_file_access(),
errmsg("could not write lock file \"%s\": %m", filename)));
}
- if (close(fd))
+ if (pg_fsync(fd) != 0)
+ {
+ int save_errno = errno;
+
+ close(fd);
+ unlink(filename);
+ errno = save_errno;
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not write lock file \"%s\": %m", filename)));
+ }
+ if (close(fd) != 0)
{
int save_errno = errno;
@@ -1042,7 +1056,14 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
close(fd);
return;
}
- if (close(fd))
+ if (pg_fsync(fd) != 0)
+ {
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not write to file \"%s\": %m",
+ DIRECTORY_LOCK_FILE)));
+ }
+ if (close(fd) != 0)
{
ereport(LOG,
(errcode_for_file_access(),