Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.68' '-r1.69' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- lmtp2nntp.c 2001/10/08 14:30:11 1.68 +++ lmtp2nntp.c 2001/10/09 08:22:29 1.69 @@ -132,8 +132,11 @@ char *option_deliverymodefakedsn; int option_maxmessagesize; int option_waittime; + int option_timeout; char *option_mailfrom; unsigned int option_levelmask; + char *option_pidfile; + int option_killflag; l2_stream_t *l2; sa_addr_t *saaAltio; sa_t *saAltio; @@ -187,10 +190,13 @@ "[-d deliverymode] " "[-g groupmode] " "[-h host[:port][,host[:port], ...]] " + "[-k] " "[-l level[:logfile]] " "[-m mailfrom] " "[-n nodename] " + "[-p pidfile] " "[-s size] " + "[-t timeout] " "[-v] " "[-w waittime] " "newsgroup [newsgroup ...] " @@ -339,6 +345,7 @@ l2_channel_t *chBuf; l2_channel_t *chFile; pid_t pid; + FILE *fd; /* library version check (run-time) */ if (l2_version.v_hex < L2_VERSION_HEX_REQ) { @@ -362,8 +369,11 @@ ctx->option_deliverymodefakedsn = "5.7.1"; /* Delivery not authorized, message refused */ ctx->option_maxmessagesize = 8 * 1024 * 1024; ctx->option_waittime = -1; + ctx->option_timeout = 3; ctx->option_mailfrom = NULL; ctx->option_levelmask = L2_LEVEL_NONE; + ctx->option_pidfile = NULL; + ctx->option_killflag = FALSE; ctx->l2 = NULL; ctx->saaAltio = NULL; ctx->saAltio = NULL; @@ -397,7 +407,7 @@ */ /* read in the arguments */ - while ((i = getopt(argc, argv, "a:b:d:g:h:l:m:n:s:vw:")) != -1) { + while ((i = getopt(argc, argv, "a:b:d:g:h:kl:m:n:p:s:t:vw:")) != -1) { switch (i) { case 'a': /*POD [B<-a> I] */ if ((rc = sa_addr_create(&ctx->saaAltio)) != SA_OK) { @@ -552,6 +562,9 @@ } free(azHosts); break; + case 'k': /*POD [B<-k>] */ + ctx->option_killflag = TRUE; + break; case 'l': /*POD [B<-l> I[:I]] */ if ((cp = strrchr(optarg, ':')) != NULL) { *cp++ = NUL; @@ -594,6 +607,9 @@ } strcpy(ctx->uname.nodename, optarg); break; + case 'p': /*POD [B<-p> I] */ + ctx->option_pidfile = strdup(optarg); + break; case 's': /*POD [B<-s> I] */ ctx->option_maxmessagesize = atoi(optarg); if(ctx->option_maxmessagesize < 64) { @@ -601,6 +617,13 @@ CU(ERR_EXECUTION); } break; + case 't': /*POD [B<-t> I] */ + ctx->option_timeout = atoi(optarg); + if(ctx->option_timeout < 0) { + fprintf(stderr, "%s:Error: timeout %d to option -t must be a positive integer.\n", ctx->progname, ctx->option_waittime); + CU(ERR_EXECUTION); + } + break; case 'v': /*POD [B<-v>] (version)*/ fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu); CU(0); @@ -633,7 +656,7 @@ } if (l2_stream_formatter(ctx->l2, 'P', formatter_prefix, &ctx->ctx) != L2_OK) { - fprintf(stderr, "%s:Error: logging failed to register formatter\n", ctx->progname); + fprintf(stderr, "%s:Error: logging failed to register prefix formatter\n", ctx->progname); CU(ERR_EXECUTION); } if (l2_stream_formatter(ctx->l2, 'D', l2_util_fmt_dump, NULL) != L2_OK) { @@ -702,6 +725,26 @@ CU(ERR_EXECUTION); } + if ((ctx->option_pidfile != NULL) && ctx->option_killflag) { + if ((fd = fopen(ctx->option_pidfile, "r")) == NULL) + log1(ctx, ERROR, "cannot open pidfile \"%s\" for reading %m", ctx->option_pidfile); + else { + if (fscanf(fd, "%d\n", &pid) != 1) { + fclose(fd); + log1(ctx, ERROR, "cannot extract pid from pidfile \"%s\"", ctx->option_pidfile); + } + else { + fclose(fd); + log1(ctx, TRACE, "going to kill pid[%d]", pid); + if (kill(pid, SIGHUP) == -1) + log1(ctx, ERROR, "killing pid[%d] failed %m", pid); + if (unlink(ctx->option_pidfile) == -1) + log1(ctx, ERROR, "unlinking pidfile \"%s\" failed %m", ctx->option_pidfile); + } + } + CU(0); + } + catchsignal(0, ctx); signal(SIGCHLD, (void(*)())catchsignal); signal(SIGHUP, (void(*)())catchsignal); @@ -715,7 +758,6 @@ signal(SIGUSR1, SIG_IGN ); signal(SIGUSR2, SIG_IGN ); - /* loop for LMTP protocol with support for alternate io through daemon */ if (ctx->saAltio == NULL) { /* initialize LMTP context */ @@ -757,8 +799,17 @@ } else { pid = getpid(); daemonize(); + if (ctx->option_pidfile != NULL) { + if ((fd = fopen(ctx->option_pidfile, "w+")) == NULL) + log1(ctx, ERROR, "cannot open pidfile \"%s\" for writing %m", ctx->option_pidfile); + else { + fprintf(fd, "%d\n", getpid()); + fclose(fd); + } + } log1(ctx, NOTICE, "startup daemonized, previous pid[%d]", pid); l2_stream_flush(ctx->l2); - sa_timeout(ctx->saAltio, SA_TIMEOUT_ALL, 9, 0); + + sa_timeout(ctx->saAltio, SA_TIMEOUT_ALL, ctx->option_timeout, 0); sa_timeout(ctx->saAltio, SA_TIMEOUT_ACCEPT, 0, 0); while ((rc = sa_accept(ctx->saAltio, &ctx->saaIO, &ctx->saIO)) == SA_OK) { l2_stream_flush(ctx->l2); /* must flush before fork() */ @@ -818,6 +869,8 @@ CUS: log0(ctx, NOTICE, "graceful shutdown shortly before exit - no more logging"); l2_stream_destroy(ctx->l2); + if (ctx->option_pidfile != NULL) + free(ctx->option_pidfile); if (ctx->option_logfile != NULL) free(ctx->option_logfile); if (ctx->progname != NULL) Index: ossp-pkg/lmtp2nntp/lmtp2nntp.pod RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v' 2>/dev/null --- lmtp2nntp.pod 2001/10/08 14:30:11 1.24 +++ lmtp2nntp.pod 2001/10/09 08:22:29 1.25 @@ -38,9 +38,12 @@ [B<-d> I] [B<-g> I] [B<-h> I[I<:port>][,I[I<:port>], ...]] +[B<-k>] [B<-m> I] [B<-n> I] +[B<-p> I] [B<-s> I] +[B<-t> I] [B<-l> I[:I]] [B<-v>] [B<-w> I] @@ -63,6 +66,14 @@ =over 4 +=item B<-a> I + +Alternate IO allows reading and writing from/to a UNIX domain or TCP sockets +instead stdin/stdout. This places the program in daemon mode. The syntax for +altio is either "unix:/path/to/socket" or "inet://address:port". If "unix:/" +and "inet://" prefixes are ommited the program tries to guess the desired mode +based on the existing of a leading slash. + =item B<-b> I[I<:port>] Bind address and/or port to be used by the LMTP client. If an address is @@ -113,13 +124,11 @@ In regard to this program they must provide the same groups and talk to each other. -=item B<-a> I +=item B<-k> -Alternate IO allows reading and writing from/to a UNIX domain or TCP sockets -instead stdin/stdout. This places the program in daemon mode. The syntax for -altio is either "unix:/path/to/socket" or "inet://address:port". If "unix:/" -and "inet://" prefixes are ommited the program tries to guess the desired mode -based on the existing of a leading slash. +Kill the daemon. After processing the -k option the program is terminated so +it renders most other options invalid not including -p and -l. The pid must be +listed in pidfile using -p option. =item B<-m> I @@ -132,11 +141,22 @@ Own FQDN used in LMTP and NNTP protocols. This overrides the nodename returned by uname(3). +=item B<-p> I + +Pidfile to remember the process ID when -a option forces us to run as a +daemon. Also to be used with -k. + =item B<-s> I Size limitation on message in bytes. Default is 8388608 (8M). Values below 64 are considered unacceptable small. +=item B<-t> I + +Timeout for the LMTP daemon managing alternate IO (see -a) to wait for input +after having accepted a connection. Value is given in seconds, the default is +three. Zero means to wait infinite. Use low numbers to prevend DoS attacks. + =item B<-l> I[:I] The level measures the degree and importance of output and can be any of @@ -158,8 +178,8 @@ Specify the time the NNTP client waits for the initial connect to complete and the time to wait for every server's response. Value is given in seconds and -must be greater than or equal to 1 second. The default is OS dependent for the -connect and a 3 second timeout waiting for a server's response. +must be greater than or equal to one second. The default is OS dependent for +the connect and a three second timeout waiting for a server's response. =item I [I ...]