@@ -606,9 +606,9 @@ PostmasterMain(int argc, char *argv[])
606
606
* In the postmaster, we want to install non-ignored handlers *without*
607
607
* SA_RESTART. This is because they'll be blocked at all times except
608
608
* when ServerLoop is waiting for something to happen, and during that
609
- * window, we want signals to exit the pselect (2) wait so that ServerLoop
609
+ * window, we want signals to exit the select (2) wait so that ServerLoop
610
610
* can respond if anything interesting happened. On some platforms,
611
- * signals marked SA_RESTART would not cause the pselect () wait to end.
611
+ * signals marked SA_RESTART would not cause the select () wait to end.
612
612
* Child processes will generally want SA_RESTART, but we expect them to
613
613
* set up their own handlers before unblocking signals.
614
614
*
@@ -1642,8 +1642,6 @@ ServerLoop(void)
1642
1642
for (;;)
1643
1643
{
1644
1644
fd_set rmask ;
1645
- fd_set * rmask_p ;
1646
- struct timeval timeout ;
1647
1645
int selres ;
1648
1646
time_t now ;
1649
1647
@@ -1653,64 +1651,37 @@ ServerLoop(void)
1653
1651
* We block all signals except while sleeping. That makes it safe for
1654
1652
* signal handlers, which again block all signals while executing, to
1655
1653
* do nontrivial work.
1654
+ *
1655
+ * If we are in PM_WAIT_DEAD_END state, then we don't want to accept
1656
+ * any new connections, so we don't call select(), and just sleep.
1656
1657
*/
1658
+ memcpy ((char * ) & rmask , (char * ) & readmask , sizeof (fd_set ));
1659
+
1657
1660
if (pmState == PM_WAIT_DEAD_END )
1658
1661
{
1659
- /*
1660
- * If we are in PM_WAIT_DEAD_END state, then we don't want to
1661
- * accept any new connections, so pass a null rmask.
1662
- */
1663
- rmask_p = NULL ;
1664
- timeout .tv_sec = 0 ;
1665
- timeout .tv_usec = 100000 ; /* 100 msec seems reasonable */
1662
+ PG_SETMASK (& UnBlockSig );
1663
+
1664
+ pg_usleep (100000L ); /* 100 msec seems reasonable */
1665
+ selres = 0 ;
1666
+
1667
+ PG_SETMASK (& BlockSig );
1666
1668
}
1667
1669
else
1668
1670
{
1669
- /* Normal case: check sockets, and compute a suitable timeout */
1670
- memcpy (& rmask , & readmask , sizeof (fd_set ));
1671
- rmask_p = & rmask ;
1671
+ /* must set timeout each time; some OSes change it! */
1672
+ struct timeval timeout ;
1672
1673
1673
1674
/* Needs to run with blocked signals! */
1674
1675
DetermineSleepTime (& timeout );
1675
- }
1676
1676
1677
- /*
1678
- * We prefer to wait with pselect(2) if available, as using that,
1679
- * together with *not* using SA_RESTART for signals, guarantees that
1680
- * we will get kicked off the wait if a signal occurs.
1681
- *
1682
- * If we lack pselect(2), fake it with select(2). This has a race
1683
- * condition: a signal that was already pending will be delivered
1684
- * before we reach the select(), and therefore the select() will wait,
1685
- * even though we might wish to do something in response. Therefore,
1686
- * beware of putting any time-critical signal response logic into
1687
- * ServerLoop rather than into the signal handler itself. It will run
1688
- * eventually, but maybe not till after a timeout delay.
1689
- *
1690
- * Some implementations of pselect() are reportedly not atomic, making
1691
- * the first alternative here functionally equivalent to the second.
1692
- * Not much we can do about that though.
1693
- */
1694
- {
1695
- #ifdef HAVE_PSELECT
1696
- /* pselect uses a randomly different timeout API, sigh */
1697
- struct timespec ptimeout ;
1698
-
1699
- ptimeout .tv_sec = timeout .tv_sec ;
1700
- ptimeout .tv_nsec = timeout .tv_usec * 1000 ;
1701
-
1702
- selres = pselect (nSockets , rmask_p , NULL , NULL ,
1703
- & ptimeout , & UnBlockSig );
1704
- #else
1705
1677
PG_SETMASK (& UnBlockSig );
1706
1678
1707
- selres = select (nSockets , rmask_p , NULL , NULL , & timeout );
1679
+ selres = select (nSockets , & rmask , NULL , NULL , & timeout );
1708
1680
1709
1681
PG_SETMASK (& BlockSig );
1710
- #endif
1711
1682
}
1712
1683
1713
- /* Now check the select()/pselect() result */
1684
+ /* Now check the select() result */
1714
1685
if (selres < 0 )
1715
1686
{
1716
1687
if (errno != EINTR && errno != EWOULDBLOCK )
0 commit comments