@@ -88,7 +88,6 @@ typedef int InheritableSocket;
8888typedef struct
8989{
9090char DataDir [MAXPGPATH ];
91- int MyPMChildSlot ;
9291#ifndef WIN32
9392unsigned long UsedShmemSegID ;
9493#else
@@ -130,6 +129,8 @@ typedef struct
130129char my_exec_path [MAXPGPATH ];
131130char pkglib_path [MAXPGPATH ];
132131
132+ int MyPMChildSlot ;
133+
133134/*
134135 * These are only used by backend processes, but are here because passing
135136 * a socket needs some special handling on Windows. 'client_sock' is an
@@ -151,13 +152,16 @@ typedef struct
151152static void read_backend_variables (char * id ,char * * startup_data ,size_t * startup_data_len );
152153static void restore_backend_variables (BackendParameters * param );
153154
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 ,
155157#ifdef WIN32
156158HANDLE childProcess ,pid_t childPid ,
157159#endif
158160char * startup_data ,size_t startup_data_len );
159161
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 );
161165
162166#endif /* EXEC_BACKEND */
163167
@@ -215,11 +219,12 @@ PostmasterChildName(BackendType child_type)
215219 * appropriate, and fds and other resources that we've inherited from
216220 * postmaster that are not needed in a child process have been closed.
217221 *
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.
220225 */
221226pid_t
222- postmaster_child_launch (BackendType child_type ,
227+ postmaster_child_launch (BackendType child_type ,int child_slot ,
223228char * startup_data ,size_t startup_data_len ,
224229ClientSocket * client_sock )
225230{
@@ -228,7 +233,7 @@ postmaster_child_launch(BackendType child_type,
228233Assert (IsPostmasterEnvironment && !IsUnderPostmaster );
229234
230235#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 ,
232237startup_data ,startup_data_len ,client_sock );
233238/* the child process will arrive in SubPostmasterMain */
234239#else /* !EXEC_BACKEND */
@@ -256,6 +261,7 @@ postmaster_child_launch(BackendType child_type,
256261 */
257262MemoryContextSwitchTo (TopMemoryContext );
258263
264+ MyPMChildSlot = child_slot ;
259265if (client_sock )
260266{
261267MyClientSocket = palloc (sizeof (ClientSocket ));
@@ -282,7 +288,8 @@ postmaster_child_launch(BackendType child_type,
282288 * - fork():s, and then exec():s the child process
283289 */
284290static 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 )
286293{
287294static unsigned long tmpBackendFileNum = 0 ;
288295pid_t pid ;
@@ -302,7 +309,7 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
302309 */
303310paramsz = SizeOfBackendParameters (startup_data_len );
304311param = 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 ))
306313{
307314pfree (param );
308315return -1 ;/* log made by save_backend_variables */
@@ -391,7 +398,8 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
391398 * file is complete.
392399 */
393400static 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 )
395403{
396404int retry_count = 0 ;
397405STARTUPINFO si ;
@@ -472,7 +480,9 @@ internal_forkexec(const char *child_kind, char *startup_data, size_t startup_dat
472480return -1 ;
473481}
474482
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 ))
476486{
477487/*
478488 * 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);
684694
685695/* Save critical backend variables into the BackendParameters struct */
686696static bool
687- save_backend_variables (BackendParameters * param ,ClientSocket * client_sock ,
697+ save_backend_variables (BackendParameters * param ,
698+ int child_slot ,ClientSocket * client_sock ,
688699#ifdef WIN32
689700HANDLE childProcess ,pid_t childPid ,
690701#endif
@@ -701,7 +712,7 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
701712
702713strlcpy (param -> DataDir ,DataDir ,MAXPGPATH );
703714
704- param -> MyPMChildSlot = MyPMChildSlot ;
715+ param -> MyPMChildSlot = child_slot ;
705716
706717#ifdef WIN32
707718param -> ShmemProtectiveRegion = ShmemProtectiveRegion ;