--- lmtp2nntp.c 2001/10/12 10:08:57 1.85
+++ lmtp2nntp.c 2001/10/12 10:25:35 1.86
@@ -157,6 +157,8 @@
int option_daemon;
int option_aclc;
struct acl option_acl[MAXACLS];
+ int option_maxchilds;
+ int active_childs;
l2_stream_t *l2;
sa_addr_t *saaAltio;
sa_t *saAltio;
@@ -349,6 +351,7 @@
case SIGCHLD:
log1(ctx, NOTICE, "caught signal %d - wait for child", sig);
pid = wait(NULL);
+ ctx->active_childs--;
log2(ctx, NOTICE, "caught signal %d - child [%ld] terminated", sig, (long)pid);
return;
case SIGUSR1:
@@ -435,6 +438,8 @@
ctx->option_killflag = FALSE;
ctx->option_uid = getuid();
ctx->option_daemon = FALSE;
+ ctx->option_maxchilds = 10;
+ ctx->active_childs = 0;
ctx->l2 = NULL;
ctx->saaAltio = NULL;
ctx->saAltio = NULL;
@@ -476,8 +481,15 @@
*/
/* read in the arguments */
- while ((i = getopt(argc, argv, "DKP:a:b:c:d:g:l:m:n:o:s:t:u:v")) != -1) {
+ while ((i = getopt(argc, argv, "C:DKP:a:b:c:d:g:l:m:n:o:s:t:u:v")) != -1) {
switch (i) {
+ case 'C': /*POD [B<-C> I<numchilds>] */
+ ctx->option_maxchilds = atoi(optarg);
+ if (ctx->option_maxchilds <= 0) {
+ fprintf(stderr, "%s:Error: Invalid number of maximum children (%d) to option -C\n", ctx->progname, ctx->option_maxchilds);
+ CU(ERR_EXECUTION);
+ }
+ break;
case 'D': /*POD [B<-D>] */
ctx->option_daemon = TRUE;
break;
@@ -1070,7 +1082,20 @@
sa_timeout(ctx->saAltio, SA_TIMEOUT_ACCEPT, ctx->option_timeout_lmtp_accept, 0);
sa_timeout(ctx->saAltio, SA_TIMEOUT_READ, ctx->option_timeout_lmtp_read, 0);
sa_timeout(ctx->saAltio, SA_TIMEOUT_WRITE, ctx->option_timeout_lmtp_write, 0);
- while ((rc = sa_accept(ctx->saAltio, &ctx->saaIO, &ctx->saIO)) == SA_OK) {
+ while (1) {
+ while (ctx->active_childs >= ctx->option_maxchilds) {
+ log1(ctx, ERROR, "maximum number of childs (%d) reached - waiting (1s)", ctx->option_maxchilds);
+ sleep(1);
+ }
+
+ if ((rc = sa_accept(ctx->saAltio, &ctx->saaIO, &ctx->saIO)) != SA_OK) {
+ if (rc == SA_ERR_SYS)
+ log3(ctx, ERROR, "accept failed: %s: (%d) %s", sa_error(rc), errno, strerror(errno));
+ else
+ log1(ctx, ERROR, "accept failed: %s", sa_error(rc));
+ sleep(10);
+ continue;
+ }
/* Access Control List */
bOk = FALSE;
@@ -1135,6 +1160,7 @@
}
if (pid != 0) {
log1(ctx, INFO, "daemon forked process, new child pid[%d]", pid);
+ ctx->active_childs++;
sa_destroy(ctx->saIO);
sa_addr_destroy(ctx->saaIO);
continue;
@@ -1180,10 +1206,6 @@
lmtp_destroy(lmtp);
CU(0);
}
- if (rc == SA_ERR_SYS)
- log3(ctx, ERROR, "accept failed: %s: (%d) %s", sa_error(rc), errno, strerror(errno));
- else
- log1(ctx, ERROR, "accept failed: %s", sa_error(rc));
}
CU(0);
|