Skip to content

Commit bada44a

Browse files
committed
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.
1 parent c0577c9 commit bada44a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -825,29 +825,34 @@ CreateLockFile(const char *filename, bool amPostmaster,
825825
*/
826826
if (isDDLock)
827827
{
828-
char *ptr;
828+
char *ptr = NULL;
829829
unsigned long id1,
830830
id2;
831+
int lineno;
831832

832-
ptr = strchr(buffer, '\n');
833-
if (ptr != NULL &&
834-
(ptr = strchr(ptr + 1, '\n')) != NULL)
833+
for (lineno = 1; lineno <= 4; lineno++)
835834
{
836-
ptr++;
837-
if (sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
835+
if ((ptr = strchr(ptr, '\n')) == NULL)
838836
{
839-
if (PGSharedMemoryIsInUse(id1, id2))
840-
ereport(FATAL,
841-
(errcode(ERRCODE_LOCK_FILE_EXISTS),
842-
errmsg("pre-existing shared memory block "
843-
"(key %lu, ID %lu) is still in use",
844-
id1, id2),
845-
errhint("If you're sure there are no old "
846-
"server processes still running, remove "
847-
"the shared memory block "
848-
"or just delete the file \"%s\".",
849-
filename)));
837+
elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
838+
break;
850839
}
840+
ptr++;
841+
}
842+
843+
if (ptr && sscanf(ptr, "%lu %lu", &id1, &id2) == 2)
844+
{
845+
if (PGSharedMemoryIsInUse(id1, id2))
846+
ereport(FATAL,
847+
(errcode(ERRCODE_LOCK_FILE_EXISTS),
848+
errmsg("pre-existing shared memory block "
849+
"(key %lu, ID %lu) is still in use",
850+
id1, id2),
851+
errhint("If you're sure there are no old "
852+
"server processes still running, remove "
853+
"the shared memory block "
854+
"or just delete the file \"%s\".",
855+
filename)));
851856
}
852857
}
853858

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy