diff options
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 65047f9c8ea..52bc471853f 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.61 1997/11/10 05:10:21 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.62 1997/11/17 03:47:28 scrappy Exp $ * * NOTES * @@ -123,6 +123,32 @@ static Dllist *PortList; static short PostPortName = -1; static short ActiveBackends = FALSE; + /* This is a boolean indicating that there is at least one backend + that is accessing the current shared memory and semaphores. + Between the time that we start up, or throw away shared memory + segments and start over, and the time we generate the next + backend (because we received a connection request), it is false. + Other times, it is true. + */ +static short shmem_seq = 0; + /* This is a sequence number that indicates how many times we've had + to throw away the shared memory and start over because we doubted + its integrity. It starts off at zero and is incremented every + time we start over. We use this to ensure that we use a new + IPC shared memory key for the new shared memory segment in case + the old segment isn't entirely gone yet. + + The sequence actually cycles back to 0 after 9, so pathologically + there could be an IPC failure if 10 sets of backends are all stuck + and won't release IPC resources. + */ + +static IpcMemoryKey ipc_key; + /* This is the base IPC shared memory key. Other keys are generated by + adding to this. + */ + + static int NextBackendId = MAXINT; /* XXX why? */ static char *progname = (char *) NULL; @@ -904,11 +930,11 @@ ConnCreate(int serverFd, int *newFdP) static void reset_shared(short port) { - IPCKey key; - - key = SystemPortAddressCreateIPCKey((SystemPortAddress) port); - CreateSharedMemoryAndSemaphores(key); - ActiveBackends = FALSE; + ipc_key = port * 1000 + shmem_seq * 100; + CreateSharedMemoryAndSemaphores(ipc_key); + ActiveBackends = FALSE; + shmem_seq += 1; + if (shmem_seq >= 10) shmem_seq -= 10; } /* @@ -1079,9 +1105,10 @@ BackendStartup(StartupInfo *packet, /* client's startup packet */ Backend *bn; /* for backend cleanup */ int pid, i; - static char envEntry[4][2 * ARGV_SIZE]; +#define NR_ENVIRONMENT_VBL 5 + static char envEntry[NR_ENVIRONMENT_VBL][2 * ARGV_SIZE]; - for (i = 0; i < 4; ++i) + for (i = 0; i < NR_ENVIRONMENT_VBL; ++i) { MemSet(envEntry[i], 0, 2 * ARGV_SIZE); } @@ -1101,6 +1128,9 @@ BackendStartup(StartupInfo *packet, /* client's startup packet */ sprintf(envEntry[3], "PGDATA=%s", DataDir); putenv(envEntry[3]); } + sprintf(envEntry[4], "IPC_KEY=%d", ipc_key); + putenv(envEntry[4]); + if (DebugLvl > 2) { char **p; |