37
37
*
38
38
*
39
39
* 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 $
41
41
*
42
42
* NOTES
43
43
*
@@ -276,6 +276,8 @@ static DWORD WINAPI win32_sigchld_waiter(LPVOID param);
276
276
static pid_t * win32_childPIDArray ;
277
277
static HANDLE * win32_childHNDArray ;
278
278
static unsigned long win32_numChildren = 0 ;
279
+
280
+ HANDLE PostmasterHandle ;
279
281
#endif
280
282
281
283
static pid_t backend_forkexec (Port * port );
@@ -748,6 +750,21 @@ PostmasterMain(int argc, char *argv[])
748
750
ereport (FATAL ,
749
751
(errcode (ERRCODE_OUT_OF_MEMORY ),
750
752
errmsg ("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 ())));
751
768
#endif
752
769
753
770
/*
@@ -3221,6 +3238,9 @@ write_backend_variables(char *filename, Port *port)
3221
3238
3222
3239
write_var (debug_flag , fp );
3223
3240
write_var (PostmasterPid , fp );
3241
+ #ifdef WIN32
3242
+ write_var (PostmasterHandle , fp );
3243
+ #endif
3224
3244
3225
3245
StrNCpy (str_buf , my_exec_path , MAXPGPATH );
3226
3246
write_array_var (str_buf , fp );
@@ -3289,6 +3309,9 @@ read_backend_variables(char *filename, Port *port)
3289
3309
3290
3310
read_var (debug_flag , fp );
3291
3311
read_var (PostmasterPid , fp );
3312
+ #ifdef WIN32
3313
+ read_var (PostmasterHandle , fp );
3314
+ #endif
3292
3315
3293
3316
read_array_var (str_buf , fp );
3294
3317
StrNCpy (my_exec_path , str_buf , MAXPGPATH );
@@ -3360,7 +3383,7 @@ ShmemBackendArrayRemove(pid_t pid)
3360
3383
}
3361
3384
3362
3385
ereport (WARNING ,
3363
- (errmsg_internal ("unable to find backend entry with pid %d" ,
3386
+ (errmsg_internal ("could not find backend entry with pid %d" ,
3364
3387
(int ) pid )));
3365
3388
}
3366
3389
@@ -3411,22 +3434,22 @@ win32_forkexec(const char *path, char *argv[])
3411
3434
win32_AddChild (pi .dwProcessId , pi .hProcess );
3412
3435
}
3413
3436
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 )
3421
3444
ereport (FATAL ,
3422
- (errmsg_internal ("failed to duplicate child handle: %d" ,
3445
+ (errmsg_internal ("could not duplicate child handle: %d" ,
3423
3446
(int ) GetLastError ())));
3424
3447
3425
3448
waiterThread = CreateThread (NULL , 64 * 1024 , win32_sigchld_waiter ,
3426
3449
(LPVOID ) childHandleCopy , 0 , NULL );
3427
3450
if (!waiterThread )
3428
3451
ereport (FATAL ,
3429
- (errmsg_internal ("failed to create sigchld waiter thread: %d" ,
3452
+ (errmsg_internal ("could not create sigchld waiter thread: %d" ,
3430
3453
(int ) GetLastError ())));
3431
3454
CloseHandle (waiterThread );
3432
3455
@@ -3460,7 +3483,7 @@ win32_AddChild(pid_t pid, HANDLE handle)
3460
3483
}
3461
3484
else
3462
3485
ereport (FATAL ,
3463
- (errmsg_internal ("unable to add child entry with pid %lu" ,
3486
+ (errmsg_internal ("no room for child entry with pid %lu" ,
3464
3487
(unsigned long ) pid )));
3465
3488
}
3466
3489
@@ -3486,7 +3509,7 @@ win32_RemoveChild(pid_t pid)
3486
3509
}
3487
3510
3488
3511
ereport (WARNING ,
3489
- (errmsg_internal ("unable to find child entry with pid %lu" ,
3512
+ (errmsg_internal ("could not find child entry with pid %lu" ,
3490
3513
(unsigned long ) pid )));
3491
3514
}
3492
3515
@@ -3562,7 +3585,7 @@ win32_sigchld_waiter(LPVOID param)
3562
3585
if (r == WAIT_OBJECT_0 )
3563
3586
pg_queue_signal (SIGCHLD );
3564
3587
else
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" ,
3566
3589
(int ) GetLastError ());
3567
3590
CloseHandle (procHandle );
3568
3591
return 0 ;
0 commit comments