@@ -88,7 +88,6 @@ typedef int InheritableSocket;
88
88
typedef struct
89
89
{
90
90
char DataDir [MAXPGPATH ];
91
- int MyPMChildSlot ;
92
91
#ifndef WIN32
93
92
unsigned long UsedShmemSegID ;
94
93
#else
@@ -130,6 +129,8 @@ typedef struct
130
129
char my_exec_path [MAXPGPATH ];
131
130
char pkglib_path [MAXPGPATH ];
132
131
132
+ int MyPMChildSlot ;
133
+
133
134
/*
134
135
* These are only used by backend processes, but are here because passing
135
136
* a socket needs some special handling on Windows. 'client_sock' is an
@@ -151,13 +152,16 @@ typedef struct
151
152
static void read_backend_variables (char * id , char * * startup_data , size_t * startup_data_len );
152
153
static void restore_backend_variables (BackendParameters * param );
153
154
154
- static bool save_backend_variables (BackendParameters * param , ClientSocket * client_sock ,
155
+ static bool save_backend_variables (BackendParameters * param , int child_slot ,
156
+ ClientSocket * client_sock ,
155
157
#ifdef WIN32
156
158
HANDLE childProcess , pid_t childPid ,
157
159
#endif
158
160
char * startup_data , size_t startup_data_len );
159
161
160
- static pid_t internal_forkexec (const char * child_kind , char * startup_data , size_t startup_data_len , ClientSocket * client_sock );
162
+ static pid_t internal_forkexec (const char * child_kind , int child_slot ,
163
+ char * startup_data , size_t startup_data_len ,
164
+ ClientSocket * client_sock );
161
165
162
166
#endif /* EXEC_BACKEND */
163
167
@@ -215,11 +219,12 @@ PostmasterChildName(BackendType child_type)
215
219
* appropriate, and fds and other resources that we've inherited from
216
220
* postmaster that are not needed in a child process have been closed.
217
221
*
218
- * 'startup_data' is an optional contiguous chunk of data that is passed to
219
- * the child process.
222
+ * 'child_slot' is the PMChildFlags array index reserved for the child
223
+ * process. 'startup_data' is an optional contiguous chunk of data that is
224
+ * passed to the child process.
220
225
*/
221
226
pid_t
222
- postmaster_child_launch (BackendType child_type ,
227
+ postmaster_child_launch (BackendType child_type , int child_slot ,
223
228
char * startup_data , size_t startup_data_len ,
224
229
ClientSocket * client_sock )
225
230
{
@@ -228,7 +233,7 @@ postmaster_child_launch(BackendType child_type,
228
233
Assert (IsPostmasterEnvironment && !IsUnderPostmaster );
229
234
230
235
#ifdef EXEC_BACKEND
231
- pid = internal_forkexec (child_process_kinds [child_type ].name ,
236
+ pid = internal_forkexec (child_process_kinds [child_type ].name , child_slot ,
232
237
startup_data , startup_data_len , client_sock );
233
238
/* the child process will arrive in SubPostmasterMain */
234
239
#else /* !EXEC_BACKEND */
@@ -256,6 +261,7 @@ postmaster_child_launch(BackendType child_type,
256
261
*/
257
262
MemoryContextSwitchTo (TopMemoryContext );
258
263
264
+ MyPMChildSlot = child_slot ;
259
265
if (client_sock )
260
266
{
261
267
MyClientSocket = palloc (sizeof (ClientSocket ));
@@ -282,7 +288,8 @@ postmaster_child_launch(BackendType child_type,
282
288
* - fork():s, and then exec():s the child process
283
289
*/
284
290
static pid_t
285
- internal_forkexec (const char * child_kind , char * startup_data , size_t startup_data_len , ClientSocket * client_sock )
291
+ internal_forkexec (const char * child_kind , int child_slot ,
292
+ char * startup_data , size_t startup_data_len , ClientSocket * client_sock )
286
293
{
287
294
static unsigned long tmpBackendFileNum = 0 ;
288
295
pid_t pid ;
@@ -302,7 +309,7 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
302
309
*/
303
310
paramsz = SizeOfBackendParameters (startup_data_len );
304
311
param = palloc0 (paramsz );
305
- if (!save_backend_variables (param , client_sock , startup_data , startup_data_len ))
312
+ if (!save_backend_variables (param , child_slot , client_sock , startup_data , startup_data_len ))
306
313
{
307
314
pfree (param );
308
315
return -1 ; /* log made by save_backend_variables */
@@ -391,7 +398,8 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
391
398
* file is complete.
392
399
*/
393
400
static pid_t
394
- internal_forkexec (const char * child_kind , char * startup_data , size_t startup_data_len , ClientSocket * client_sock )
401
+ internal_forkexec (const char * child_kind , int child_slot ,
402
+ char * startup_data , size_t startup_data_len , ClientSocket * client_sock )
395
403
{
396
404
int retry_count = 0 ;
397
405
STARTUPINFO si ;
@@ -472,7 +480,9 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
472
480
return -1 ;
473
481
}
474
482
475
- if (!save_backend_variables (param , client_sock , pi .hProcess , pi .dwProcessId , startup_data , startup_data_len ))
483
+ if (!save_backend_variables (param , child_slot , client_sock ,
484
+ pi .hProcess , pi .dwProcessId ,
485
+ startup_data , startup_data_len ))
476
486
{
477
487
/*
478
488
* log made by save_backend_variables, but we have to clean up the
@@ -684,7 +694,8 @@ static void read_inheritable_socket(SOCKET *dest, InheritableSocket *src);
684
694
685
695
/* Save critical backend variables into the BackendParameters struct */
686
696
static bool
687
- save_backend_variables (BackendParameters * param , ClientSocket * client_sock ,
697
+ save_backend_variables (BackendParameters * param ,
698
+ int child_slot , ClientSocket * client_sock ,
688
699
#ifdef WIN32
689
700
HANDLE childProcess , pid_t childPid ,
690
701
#endif
@@ -701,7 +712,7 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
701
712
702
713
strlcpy (param -> DataDir , DataDir , MAXPGPATH );
703
714
704
- param -> MyPMChildSlot = MyPMChildSlot ;
715
+ param -> MyPMChildSlot = child_slot ;
705
716
706
717
#ifdef WIN32
707
718
param -> ShmemProtectiveRegion = ShmemProtectiveRegion ;
0 commit comments