10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.61 1997/11/10 05:10:21 momjian Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.62 1997/11/17 03:47:28 scrappy Exp $
14
14
*
15
15
* NOTES
16
16
*
@@ -123,6 +123,32 @@ static Dllist *PortList;
123
123
124
124
static short PostPortName = -1 ;
125
125
static short ActiveBackends = FALSE;
126
+ /* This is a boolean indicating that there is at least one backend
127
+ that is accessing the current shared memory and semaphores.
128
+ Between the time that we start up, or throw away shared memory
129
+ segments and start over, and the time we generate the next
130
+ backend (because we received a connection request), it is false.
131
+ Other times, it is true.
132
+ */
133
+ static short shmem_seq = 0 ;
134
+ /* This is a sequence number that indicates how many times we've had
135
+ to throw away the shared memory and start over because we doubted
136
+ its integrity. It starts off at zero and is incremented every
137
+ time we start over. We use this to ensure that we use a new
138
+ IPC shared memory key for the new shared memory segment in case
139
+ the old segment isn't entirely gone yet.
140
+
141
+ The sequence actually cycles back to 0 after 9, so pathologically
142
+ there could be an IPC failure if 10 sets of backends are all stuck
143
+ and won't release IPC resources.
144
+ */
145
+
146
+ static IpcMemoryKey ipc_key ;
147
+ /* This is the base IPC shared memory key. Other keys are generated by
148
+ adding to this.
149
+ */
150
+
151
+
126
152
static int NextBackendId = MAXINT ; /* XXX why? */
127
153
static char * progname = (char * ) NULL ;
128
154
@@ -904,11 +930,11 @@ ConnCreate(int serverFd, int *newFdP)
904
930
static void
905
931
reset_shared (short port )
906
932
{
907
- IPCKey key ;
908
-
909
- key = SystemPortAddressCreateIPCKey (( SystemPortAddress ) port ) ;
910
- CreateSharedMemoryAndSemaphores ( key ) ;
911
- ActiveBackends = FALSE ;
933
+ ipc_key = port * 1000 + shmem_seq * 100 ;
934
+ CreateSharedMemoryAndSemaphores ( ipc_key );
935
+ ActiveBackends = FALSE ;
936
+ shmem_seq += 1 ;
937
+ if ( shmem_seq >= 10 ) shmem_seq -= 10 ;
912
938
}
913
939
914
940
/*
@@ -1079,9 +1105,10 @@ BackendStartup(StartupInfo *packet, /* client's startup packet */
1079
1105
Backend * bn ; /* for backend cleanup */
1080
1106
int pid ,
1081
1107
i ;
1082
- static char envEntry [4 ][2 * ARGV_SIZE ];
1108
+ #define NR_ENVIRONMENT_VBL 5
1109
+ static char envEntry [NR_ENVIRONMENT_VBL ][2 * ARGV_SIZE ];
1083
1110
1084
- for (i = 0 ; i < 4 ; ++ i )
1111
+ for (i = 0 ; i < NR_ENVIRONMENT_VBL ; ++ i )
1085
1112
{
1086
1113
MemSet (envEntry [i ], 0 , 2 * ARGV_SIZE );
1087
1114
}
@@ -1101,6 +1128,9 @@ BackendStartup(StartupInfo *packet, /* client's startup packet */
1101
1128
sprintf (envEntry [3 ], "PGDATA=%s" , DataDir );
1102
1129
putenv (envEntry [3 ]);
1103
1130
}
1131
+ sprintf (envEntry [4 ], "IPC_KEY=%d" , ipc_key );
1132
+ putenv (envEntry [4 ]);
1133
+
1104
1134
if (DebugLvl > 2 )
1105
1135
{
1106
1136
char * * p ;
0 commit comments