@@ -476,6 +476,7 @@ static void MaybeStartSlotSyncWorker(void);
476
476
477
477
static pid_t waitpid (pid_t pid , int * exitstatus , int options );
478
478
static void WINAPI pgwin32_deadchild_callback (PVOID lpParameter , BOOLEAN TimerOrWaitFired );
479
+ static void pgwin32_register_deadchild_callback (HANDLE procHandle , DWORD procId );
479
480
480
481
static HANDLE win32ChildQueue ;
481
482
@@ -4623,7 +4624,6 @@ internal_forkexec(int argc, char *argv[], ClientSocket *client_sock, BackgroundW
4623
4624
BackendParameters * param ;
4624
4625
SECURITY_ATTRIBUTES sa ;
4625
4626
char paramHandleStr [32 ];
4626
- win32_deadchild_waitinfo * childinfo ;
4627
4627
4628
4628
/* Make sure caller set up argv properly */
4629
4629
Assert (argc >= 3 );
@@ -4783,26 +4783,10 @@ internal_forkexec(int argc, char *argv[], ClientSocket *client_sock, BackgroundW
4783
4783
return -1 ;
4784
4784
}
4785
4785
4786
- /*
4787
- * Queue a waiter to signal when this child dies. The wait will be handled
4788
- * automatically by an operating system thread pool. The memory will be
4789
- * freed by a later call to waitpid().
4790
- */
4791
- childinfo = palloc (sizeof (win32_deadchild_waitinfo ));
4792
- childinfo -> procHandle = pi .hProcess ;
4793
- childinfo -> procId = pi .dwProcessId ;
4794
-
4795
- if (!RegisterWaitForSingleObject (& childinfo -> waitHandle ,
4796
- pi .hProcess ,
4797
- pgwin32_deadchild_callback ,
4798
- childinfo ,
4799
- INFINITE ,
4800
- WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD ))
4801
- ereport (FATAL ,
4802
- (errmsg_internal ("could not register process for wait: error code %lu" ,
4803
- GetLastError ())));
4786
+ /* Set up notification when the child process dies */
4787
+ pgwin32_register_deadchild_callback (pi .hProcess , pi .dwProcessId );
4804
4788
4805
- /* Don't close pi.hProcess here - waitpid() needs access to it */
4789
+ /* Don't close pi.hProcess, it's owned by the deadchild callback now */
4806
4790
4807
4791
CloseHandle (pi .hThread );
4808
4792
@@ -6526,6 +6510,32 @@ pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
6526
6510
/* Queue SIGCHLD signal. */
6527
6511
pg_queue_signal (SIGCHLD );
6528
6512
}
6513
+
6514
+ /*
6515
+ * Queue a waiter to signal when this child dies. The wait will be handled
6516
+ * automatically by an operating system thread pool. The memory and the
6517
+ * process handle will be freed by a later call to waitpid().
6518
+ */
6519
+ static void
6520
+ pgwin32_register_deadchild_callback (HANDLE procHandle , DWORD procId )
6521
+ {
6522
+ win32_deadchild_waitinfo * childinfo ;
6523
+
6524
+ childinfo = palloc (sizeof (win32_deadchild_waitinfo ));
6525
+ childinfo -> procHandle = procHandle ;
6526
+ childinfo -> procId = procId ;
6527
+
6528
+ if (!RegisterWaitForSingleObject (& childinfo -> waitHandle ,
6529
+ procHandle ,
6530
+ pgwin32_deadchild_callback ,
6531
+ childinfo ,
6532
+ INFINITE ,
6533
+ WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD ))
6534
+ ereport (FATAL ,
6535
+ (errmsg_internal ("could not register process for wait: error code %lu" ,
6536
+ GetLastError ())));
6537
+ }
6538
+
6529
6539
#endif /* WIN32 */
6530
6540
6531
6541
/*
0 commit comments