Skip to content

Commit 9d39e94

Browse files
committed
Fix filling of postmaster.pid in bootstrap/standalone mode.
We failed to ever fill the sixth line (LISTEN_ADDR), which caused the attempt to fill the seventh line (SHMEM_KEY) to fail, so that the shared memory key never got added to the file in standalone mode. This has been broken since we added more content to our lock files in 9.1. To fix, tweak the logic in CreateLockFile to add an empty LISTEN_ADDR line in standalone mode. This is a tad grotty, but since that function already knows almost everything there is to know about the contents of lock files, it doesn't seem that it's any better to hack it elsewhere. It's not clear how significant this bug really is, since a standalone backend should never have any children and thus it seems not critical to be able to check the nattch count of the shmem segment externally. But I'm going to back-patch the fix anyway. This problem had escaped notice because of an ancient (and in hindsight pretty dubious) decision to suppress LOG-level messages by default in standalone mode; so that the elog(LOG) complaint in AddToDataDirLockFile that should have warned of the problem didn't do anything. Fixing that is material for a separate patch though.
1 parent f0fc1d4 commit 9d39e94

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
890890

891891
/*
892892
* Successfully created the file, now fill it. See comment in miscadmin.h
893-
* about the contents. Note that we write the same info into both datadir
894-
* and socket lockfiles; although more stuff may get added to the datadir
895-
* lockfile later.
893+
* about the contents. Note that we write the same first five lines into
894+
* both datadir and socket lockfiles; although more stuff may get added to
895+
* the datadir lockfile later.
896896
*/
897897
snprintf(buffer, sizeof(buffer), "%d\n%s\n%ld\n%d\n%s\n",
898898
amPostmaster ? (int) my_pid : -((int) my_pid),
@@ -906,6 +906,13 @@ CreateLockFile(const char *filename, bool amPostmaster,
906906
#endif
907907
);
908908

909+
/*
910+
* In a standalone backend, the next line (LOCK_FILE_LINE_LISTEN_ADDR)
911+
* will never receive data, so fill it in as empty now.
912+
*/
913+
if (isDDLock && !amPostmaster)
914+
strlcat(buffer, "\n", sizeof(buffer));
915+
909916
errno = 0;
910917
if (write(fd, buffer, strlen(buffer)) != strlen(buffer))
911918
{
@@ -1060,7 +1067,8 @@ AddToDataDirLockFile(int target_line, const char *str)
10601067
{
10611068
if ((ptr = strchr(ptr, '\n')) == NULL)
10621069
{
1063-
elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
1070+
elog(LOG, "incomplete data in \"%s\": found only %d newlines while trying to add line %d",
1071+
DIRECTORY_LOCK_FILE, lineno - 1, target_line);
10641072
close(fd);
10651073
return;
10661074
}

0 commit comments

Comments
 (0)