1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Fix code to properly pull out shared memory key now that the

postmaster.pid file is larger than in previous major versions.
This is a bug introduced when I added lines to the file recently.
This commit is contained in:
Bruce Momjian 2010-12-27 23:11:33 -05:00
parent c0577c92a8
commit bada44a2a2

View File

@ -825,29 +825,34 @@ CreateLockFile(const char *filename, bool amPostmaster,
*/ */
if (isDDLock) if (isDDLock)
{ {
char *ptr; char *ptr = NULL;
unsigned long id1, unsigned long id1,
id2; id2;
int lineno;
ptr = strchr(buffer, '\n'); for (lineno = 1; lineno <= 4; lineno++)
if (ptr != NULL &&
(ptr = strchr(ptr + 1, '\n')) != NULL)
{ {
ptr++; if ((ptr = strchr(ptr, '\n')) == NULL)
if (sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
{ {
if (PGSharedMemoryIsInUse(id1, id2)) elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
ereport(FATAL, break;
(errcode(ERRCODE_LOCK_FILE_EXISTS),
errmsg("pre-existing shared memory block "
"(key %lu, ID %lu) is still in use",
id1, id2),
errhint("If you're sure there are no old "
"server processes still running, remove "
"the shared memory block "
"or just delete the file \"%s\".",
filename)));
} }
ptr++;
}
if (ptr && sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
{
if (PGSharedMemoryIsInUse(id1, id2))
ereport(FATAL,
(errcode(ERRCODE_LOCK_FILE_EXISTS),
errmsg("pre-existing shared memory block "
"(key %lu, ID %lu) is still in use",
id1, id2),
errhint("If you're sure there are no old "
"server processes still running, remove "
"the shared memory block "
"or just delete the file \"%s\".",
filename)));
} }
} }