3737 *
3838 *
3939 * IDENTIFICATION
40- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.400 2004/05/29 22:48:19 tgl Exp $
40+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.401 2004/05/30 03:50:11 tgl Exp $
4141 *
4242 * NOTES
4343 *
@@ -276,6 +276,8 @@ static DWORD WINAPI win32_sigchld_waiter(LPVOID param);
276276static pid_t * win32_childPIDArray ;
277277static HANDLE * win32_childHNDArray ;
278278static unsigned long win32_numChildren = 0 ;
279+
280+ HANDLE PostmasterHandle ;
279281#endif
280282
281283static pid_t backend_forkexec (Port * port );
@@ -748,6 +750,21 @@ PostmasterMain(int argc, char *argv[])
748750ereport (FATAL ,
749751(errcode (ERRCODE_OUT_OF_MEMORY ),
750752errmsg ("out of memory" )));
753+
754+ /*
755+ * Set up a handle that child processes can use to check whether the
756+ * postmaster is still running.
757+ */
758+ if (DuplicateHandle (GetCurrentProcess (),
759+ GetCurrentProcess (),
760+ GetCurrentProcess (),
761+ & PostmasterHandle ,
762+ 0 ,
763+ TRUE,
764+ DUPLICATE_SAME_ACCESS )== 0 )
765+ ereport (FATAL ,
766+ (errmsg_internal ("could not duplicate postmaster handle: %d" ,
767+ (int )GetLastError ())));
751768#endif
752769
753770/*
@@ -3221,6 +3238,9 @@ write_backend_variables(char *filename, Port *port)
32213238
32223239write_var (debug_flag ,fp );
32233240write_var (PostmasterPid ,fp );
3241+ #ifdef WIN32
3242+ write_var (PostmasterHandle ,fp );
3243+ #endif
32243244
32253245StrNCpy (str_buf ,my_exec_path ,MAXPGPATH );
32263246write_array_var (str_buf ,fp );
@@ -3289,6 +3309,9 @@ read_backend_variables(char *filename, Port *port)
32893309
32903310read_var (debug_flag ,fp );
32913311read_var (PostmasterPid ,fp );
3312+ #ifdef WIN32
3313+ read_var (PostmasterHandle ,fp );
3314+ #endif
32923315
32933316read_array_var (str_buf ,fp );
32943317StrNCpy (my_exec_path ,str_buf ,MAXPGPATH );
@@ -3360,7 +3383,7 @@ ShmemBackendArrayRemove(pid_t pid)
33603383}
33613384
33623385ereport (WARNING ,
3363- (errmsg_internal ("unable to find backend entry with pid %d" ,
3386+ (errmsg_internal ("could not find backend entry with pid %d" ,
33643387 (int )pid )));
33653388}
33663389
@@ -3411,22 +3434,22 @@ win32_forkexec(const char *path, char *argv[])
34113434win32_AddChild (pi .dwProcessId ,pi .hProcess );
34123435}
34133436
3414- if (! DuplicateHandle (GetCurrentProcess (),
3415- pi .hProcess ,
3416- GetCurrentProcess (),
3417- & childHandleCopy ,
3418- 0 ,
3419- FALSE,
3420- DUPLICATE_SAME_ACCESS ))
3437+ if (DuplicateHandle (GetCurrentProcess (),
3438+ pi .hProcess ,
3439+ GetCurrentProcess (),
3440+ & childHandleCopy ,
3441+ 0 ,
3442+ FALSE,
3443+ DUPLICATE_SAME_ACCESS )== 0 )
34213444ereport (FATAL ,
3422- (errmsg_internal ("failed to duplicate child handle: %d" ,
3445+ (errmsg_internal ("could not duplicate child handle: %d" ,
34233446 (int )GetLastError ())));
34243447
34253448waiterThread = CreateThread (NULL ,64 * 1024 ,win32_sigchld_waiter ,
34263449(LPVOID )childHandleCopy ,0 ,NULL );
34273450if (!waiterThread )
34283451ereport (FATAL ,
3429- (errmsg_internal ("failed to create sigchld waiter thread: %d" ,
3452+ (errmsg_internal ("could not create sigchld waiter thread: %d" ,
34303453 (int )GetLastError ())));
34313454CloseHandle (waiterThread );
34323455
@@ -3460,7 +3483,7 @@ win32_AddChild(pid_t pid, HANDLE handle)
34603483}
34613484else
34623485ereport (FATAL ,
3463- (errmsg_internal ("unable to add child entry with pid %lu" ,
3486+ (errmsg_internal ("no room for child entry with pid %lu" ,
34643487 (unsigned long )pid )));
34653488}
34663489
@@ -3486,7 +3509,7 @@ win32_RemoveChild(pid_t pid)
34863509}
34873510
34883511ereport (WARNING ,
3489- (errmsg_internal ("unable to find child entry with pid %lu" ,
3512+ (errmsg_internal ("could not find child entry with pid %lu" ,
34903513 (unsigned long )pid )));
34913514}
34923515
@@ -3562,7 +3585,7 @@ win32_sigchld_waiter(LPVOID param)
35623585if (r == WAIT_OBJECT_0 )
35633586pg_queue_signal (SIGCHLD );
35643587else
3565- fprintf (stderr ,"ERROR:Failed to wait on child process handle: %i \n" ,
3588+ fprintf (stderr ,"ERROR:failed to wait on child process handle: %d \n" ,
35663589(int )GetLastError ());
35673590CloseHandle (procHandle );
35683591return 0 ;