{
WaitEventSet *new_event_set;
- new_event_set = CreateWaitEventSet(TopMemoryContext, 1);
+ new_event_set = CreateWaitEventSet(TopMemoryContext, 2);
AddWaitEventToSet(new_event_set, WL_LATCH_SET, PGINVALID_SOCKET,
MyLatch, NULL);
+ AddWaitEventToSet(new_event_set, WL_POSTMASTER_DEATH, PGINVALID_SOCKET,
+ NULL, NULL);
/* Don't set cv_wait_event_set until we have a correct WES. */
cv_wait_event_set = new_event_set;
}
CHECK_FOR_INTERRUPTS();
/*
- * Wait for latch to be set. We don't care about the result because
- * our contract permits spurious returns.
+ * Wait for latch to be set. (If we're awakened for some other
+ * reason, the code below will cope anyway.)
*/
WaitEventSetWait(cv_wait_event_set, -1, &event, 1, wait_event_info);
+ if (event.events & WL_POSTMASTER_DEATH)
+ {
+ /*
+ * Emergency bailout if postmaster has died. This is to avoid the
+ * necessity for manual cleanup of all postmaster children.
+ */
+ exit(1);
+ }
+
/* Reset latch before examining the state of the wait list. */
ResetLatch(MyLatch);