summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-12-16 15:02:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-12-16 15:02:07 -0500
commit9d39e9499944b61e0db4e8d2157ba58e8bc52b89 (patch)
treecfe7212a0848663540fcd35ee5980f5ffcc4d698
parentf0fc1d4c890135ec879860f7d0c49b34d492d99f (diff)
downloadpostgresql-9d39e9499944b61e0db4e8d2157ba58e8bc52b89.tar.gz
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.
-rw-r--r--src/backend/utils/init/miscinit.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 347a777da9..f6cd0c0675 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -890,9 +890,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
/*
* Successfully created the file, now fill it. See comment in miscadmin.h
- * about the contents. Note that we write the same info into both datadir
- * and socket lockfiles; although more stuff may get added to the datadir
- * lockfile later.
+ * about the contents. Note that we write the same first five lines into
+ * both datadir and socket lockfiles; although more stuff may get added to
+ * the datadir lockfile later.
*/
snprintf(buffer, sizeof(buffer), "%d\n%s\n%ld\n%d\n%s\n",
amPostmaster ? (int) my_pid : -((int) my_pid),
@@ -906,6 +906,13 @@ CreateLockFile(const char *filename, bool amPostmaster,
#endif
);
+ /*
+ * In a standalone backend, the next line (LOCK_FILE_LINE_LISTEN_ADDR)
+ * will never receive data, so fill it in as empty now.
+ */
+ if (isDDLock && !amPostmaster)
+ strlcat(buffer, "\n", sizeof(buffer));
+
errno = 0;
if (write(fd, buffer, strlen(buffer)) != strlen(buffer))
{
@@ -1060,7 +1067,8 @@ AddToDataDirLockFile(int target_line, const char *str)
{
if ((ptr = strchr(ptr, '\n')) == NULL)
{
- elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE);
+ elog(LOG, "incomplete data in \"%s\": found only %d newlines while trying to add line %d",
+ DIRECTORY_LOCK_FILE, lineno - 1, target_line);
close(fd);
return;
}