diff options
author | Bruce Momjian <bruce@momjian.us> | 2010-12-24 09:45:15 -0500 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2010-12-24 09:45:52 -0500 |
commit | 075354ad1bc0496c30dbd4dafb0f88a4d3e54cbc (patch) | |
tree | b1534a62642ca169ef424f6f8962965e70caea0f /src/backend/utils/init/miscinit.c | |
parent | 4b1742a192a60b9c063fd7e93f5aed7a697bece1 (diff) | |
download | postgresql-075354ad1bc0496c30dbd4dafb0f88a4d3e54cbc.tar.gz postgresql-075354ad1bc0496c30dbd4dafb0f88a4d3e54cbc.zip |
Improve "pg_ctl -w start" server detection by writing the postmaster
port and socket directory into postmaster.pid, and have pg_ctl read from
that file, for use by PQping().
Diffstat (limited to 'src/backend/utils/init/miscinit.c')
-rw-r--r-- | src/backend/utils/init/miscinit.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 14ed9147a19..deb2d582b2a 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -33,6 +33,7 @@ #include "mb/pg_wchar.h" #include "miscadmin.h" #include "postmaster/autovacuum.h" +#include "postmaster/postmaster.h" #include "storage/fd.h" #include "storage/ipc.h" #include "storage/pg_shmem.h" @@ -658,7 +659,7 @@ CreateLockFile(const char *filename, bool amPostmaster, bool isDDLock, const char *refName) { int fd; - char buffer[MAXPGPATH + 100]; + char buffer[MAXPGPATH * 2 + 256]; int ntries; int len; int encoded_pid; @@ -868,9 +869,9 @@ CreateLockFile(const char *filename, bool amPostmaster, /* * Successfully created the file, now fill it. */ - snprintf(buffer, sizeof(buffer), "%d\n%s\n", + snprintf(buffer, sizeof(buffer), "%d\n%s\n%d\n%s\n", amPostmaster ? (int) my_pid : -((int) my_pid), - DataDir); + DataDir, PostPortNumber, UnixSocketDir); errno = 0; if (write(fd, buffer, strlen(buffer)) != strlen(buffer)) { @@ -994,8 +995,9 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2) { int fd; int len; + int lineno; char *ptr; - char buffer[BLCKSZ]; + char buffer[MAXPGPATH * 2 + 256]; fd = open(DIRECTORY_LOCK_FILE, O_RDWR | PG_BINARY, 0); if (fd < 0) @@ -1019,18 +1021,20 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2) buffer[len] = '\0'; /* - * Skip over first two lines (PID and path). + * Skip over first four lines (PID, pgdata, portnum, socketdir). */ - ptr = strchr(buffer, '\n'); - if (ptr == NULL || - (ptr = strchr(ptr + 1, '\n')) == NULL) + ptr = buffer; + for (lineno = 1; lineno <= 4; lineno++) { - elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE); - close(fd); - return; + if ((ptr = strchr(ptr, '\n')) == NULL) + { + elog(LOG, "bogus data in \"%s\"", DIRECTORY_LOCK_FILE); + close(fd); + return; + } + ptr++; } - ptr++; - + /* * Append key information. Format to try to keep it the same length * always (trailing junk won't hurt, but might confuse humans). |