|
10 | 10 | * |
11 | 11 | * |
12 | 12 | * IDENTIFICATION |
13 | | - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.99 1999/01/17 06:18:34 momjian Exp $ |
| 13 | + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.100 1999/01/30 20:04:37 tgl Exp $ |
14 | 14 | * |
15 | 15 | * NOTES |
16 | 16 | * |
@@ -244,6 +244,7 @@ static intinitMasks(fd_set *rmask, fd_set *wmask); |
244 | 244 | staticlongPostmasterRandom(void); |
245 | 245 | staticvoidRandomSalt(char*salt); |
246 | 246 | staticvoidSignalChildren(SIGNAL_ARGS); |
| 247 | +staticintCountChildren(void); |
247 | 248 |
|
248 | 249 | #ifdefCYR_RECODE |
249 | 250 | voidGetCharSetByHost(char*,int,char*); |
@@ -667,8 +668,8 @@ ServerLoop(void) |
667 | 668 | { |
668 | 669 | if (errno==EINTR) |
669 | 670 | continue; |
670 | | -fprintf(stderr,"%s: ServerLoop: select failed\n", |
671 | | -progname); |
| 671 | +fprintf(stderr,"%s: ServerLoop: select failed: %s\n", |
| 672 | +progname,strerror(errno)); |
672 | 673 | returnSTATUS_ERROR; |
673 | 674 | } |
674 | 675 |
|
@@ -763,19 +764,24 @@ ServerLoop(void) |
763 | 764 |
|
764 | 765 | if (status==STATUS_OK&&port->pktInfo.state==Idle) |
765 | 766 | { |
766 | | - |
767 | | -/* |
768 | | - * If the backend start fails then keep the connection |
769 | | - * open to report it. Otherwise, pretend there is an |
770 | | - * error to close the connection which will now be managed |
771 | | - * by the backend. |
772 | | - */ |
773 | | - |
774 | | -if (BackendStartup(port)!=STATUS_OK) |
| 767 | +/* Can't start backend if max backend count is exceeded. */ |
| 768 | +if (CountChildren() >=MaxBackendId) |
775 | 769 | PacketSendError(&port->pktInfo, |
776 | | -"Backend startup failed"); |
| 770 | +"Sorry, too many clients already"); |
777 | 771 | else |
778 | | -status=STATUS_ERROR; |
| 772 | +{ |
| 773 | +/* |
| 774 | + * If the backend start fails then keep the connection |
| 775 | + * open to report it. Otherwise, pretend there is an |
| 776 | + * error to close the connection which will now be managed |
| 777 | + * by the backend. |
| 778 | + */ |
| 779 | +if (BackendStartup(port)!=STATUS_OK) |
| 780 | +PacketSendError(&port->pktInfo, |
| 781 | +"Backend startup failed"); |
| 782 | +else |
| 783 | +status=STATUS_ERROR; |
| 784 | +} |
779 | 785 | } |
780 | 786 |
|
781 | 787 | /* Close the connection if required. */ |
@@ -1332,8 +1338,8 @@ BackendStartup(Port *port) |
1332 | 1338 | /* in parent */ |
1333 | 1339 | if (pid<0) |
1334 | 1340 | { |
1335 | | -fprintf(stderr,"%s: BackendStartup: fork failed\n", |
1336 | | -progname); |
| 1341 | +fprintf(stderr,"%s: BackendStartup: fork failed: %s\n", |
| 1342 | +progname,strerror(errno)); |
1337 | 1343 | returnSTATUS_ERROR; |
1338 | 1344 | } |
1339 | 1345 |
|
@@ -1641,3 +1647,23 @@ PostmasterRandom(void) |
1641 | 1647 |
|
1642 | 1648 | returnrandom() ^random_seed; |
1643 | 1649 | } |
| 1650 | + |
| 1651 | +/* |
| 1652 | + * Count up number of child processes. |
| 1653 | + */ |
| 1654 | +staticint |
| 1655 | +CountChildren(void) |
| 1656 | +{ |
| 1657 | +Dlelem*curr; |
| 1658 | +Backend*bp; |
| 1659 | +intmypid=getpid(); |
| 1660 | +intcnt=0; |
| 1661 | + |
| 1662 | +for (curr=DLGetHead(BackendList);curr;curr=DLGetSucc(curr)) |
| 1663 | +{ |
| 1664 | +bp= (Backend*)DLE_VAL(curr); |
| 1665 | +if (bp->pid!=mypid) |
| 1666 | +cnt++; |
| 1667 | +} |
| 1668 | +returncnt; |
| 1669 | +} |