Index: ossp-pkg/lmtp2nntp/00TODO RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v rcsdiff -q -kk '-r1.38' '-r1.39' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/00TODO,v' 2>/dev/null --- 00TODO 2001/10/12 10:08:57 1.38 +++ 00TODO 2001/10/12 10:25:35 1.39 @@ -4,6 +4,9 @@ option -U currently has to be specified before option -b in order to set the owner/modes of Unix Domains sockets correctly. + on waiting for childs to finish: maximum number of seconds to wait at all + and if childs still are running, kill them (-> we have to remember pid_t's) + Proposal for future URL-style logging option syntax -L streamlog -l syslog:[mask]//[localhost[:port]][/tag=value ...] with /tag=value i.e. facility=local0 Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.85' '-r1.86' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- 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] */ + 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);