diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-02 19:05:59 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-04-02 19:05:59 +0000 |
commit | 43225228859332051b0497d6732b906e2c753f85 (patch) | |
tree | e1545792a305da6620c54b122c51c207dd70accd /gnu/usr.sbin/sendmail/mailstats | |
parent | 0b21c002091512c23501e805cd064cdc94f0a312 (diff) |
stock sendmail 8.10.0 with $Id -> $Sendmail
Diffstat (limited to 'gnu/usr.sbin/sendmail/mailstats')
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/Build | 13 | ||||
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/Makefile | 17 | ||||
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/Makefile.m4 | 20 | ||||
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/mailstats.0 | 66 | ||||
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/mailstats.8 | 107 | ||||
-rw-r--r-- | gnu/usr.sbin/sendmail/mailstats/mailstats.c | 313 |
6 files changed, 536 insertions, 0 deletions
diff --git a/gnu/usr.sbin/sendmail/mailstats/Build b/gnu/usr.sbin/sendmail/mailstats/Build new file mode 100644 index 00000000000..59beb2a4e17 --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/Build @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (c) 1999 Sendmail, Inc. and its suppliers. +# All rights reserved. +# +# By using this file, you agree to the terms and conditions set +# forth in the LICENSE file which can be found at the top level of +# the sendmail distribution. +# +# +# $Sendmail: Build,v 8.4 1999/03/02 02:33:27 peterh Exp $ + +exec ../devtools/bin/Build $* diff --git a/gnu/usr.sbin/sendmail/mailstats/Makefile b/gnu/usr.sbin/sendmail/mailstats/Makefile new file mode 100644 index 00000000000..e1b3b3caadb --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/Makefile @@ -0,0 +1,17 @@ +# $Sendmail: Makefile,v 8.5 1999/09/23 22:36:36 ca Exp $ + +SHELL= /bin/sh +BUILD= ./Build +OPTIONS= $(CONFIG) $(FLAGS) + +all: FRC + $(SHELL) $(BUILD) $(OPTIONS) $@ +clean: FRC + $(SHELL) $(BUILD) $(OPTIONS) $@ +install: FRC + $(SHELL) $(BUILD) $(OPTIONS) $@ + +fresh: FRC + $(SHELL) $(BUILD) $(OPTIONS) -c + +FRC: diff --git a/gnu/usr.sbin/sendmail/mailstats/Makefile.m4 b/gnu/usr.sbin/sendmail/mailstats/Makefile.m4 new file mode 100644 index 00000000000..5a9259d1318 --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/Makefile.m4 @@ -0,0 +1,20 @@ +include(confBUILDTOOLSDIR`/M4/switch.m4') + +# sendmail dir +SMSRCDIR= ifdef(`confSMSRCDIR', `confSMSRCDIR', `${SRCDIR}/sendmail') +PREPENDDEF(`confENVDEF', `confMAPDEF') +PREPENDDEF(`confINCDIRS', `-I${SMSRCDIR} ') + +bldPRODUCT_START(`executable', `mailstats') +define(`bldINSTALL_DIR', `S') +define(`bldSOURCES', `mailstats.c ') +bldPUSH_SMLIB(`smutil') +APPENDDEF(`confENVDEF', `-DNOT_SENDMAIL') +bldPRODUCT_END + +bldPRODUCT_START(`manpage', `mailstats') +define(`bldSOURCES', `mailstats.8') +bldPRODUCT_END + +bldFINISH + diff --git a/gnu/usr.sbin/sendmail/mailstats/mailstats.0 b/gnu/usr.sbin/sendmail/mailstats/mailstats.0 new file mode 100644 index 00000000000..e2dc8d3f111 --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/mailstats.0 @@ -0,0 +1,66 @@ + + + +MAILSTATS(1) MAILSTATS(1) + + +NNAAMMEE + mmaaiillssttaattss - display mail statistics + +SSYYNNOOPPSSIISS + mmaaiillssttaattss [--oo] [--pp] [--CC _c_f_f_i_l_e] [--ff _s_t_f_i_l_e] + +DDEESSCCRRIIPPTTIIOONN + The mmaaiillssttaattss utility displays the current mail statis- + tics. + + First, the time at which statistics started being kept is + displayed, in the format specified by ctime(3). Then, the + statistics for each mailer are displayed on a single line, + each with the following whitespace separated fields: + + MM The mailer number. + mmssggssffrr Number of messages from the mailer. + bbyytteess__ffrroomm Kbytes from the mailer. + mmssggssttoo Number of messages to the mailer. + bbyytteess__ttoo Kbytes to the mailer. + mmssggssrreejj Number of messages rejected. + mmssggssddiiss Number of messages discarded. + MMaaiilleerr The name of the mailer. + + After this display, a line totaling the values for all of + the mailers is displayed (preceeded with a ``T''), sepa- + rated from the previous information by a line containing + only equals (``='') characters. Another line preceeded + with a ``C'' lists the number of connections. + + The options are as follows: + + --CC Read the specified file instead of the default + sseennddmmaaiill ``cf'' file. + + --ff Read the specified statistics file instead of the + statistics file specified in the sseennddmmaaiill ``cf'' + file. + + --pp Output information in program-readable mode and + clear statistics. + + --oo Don't display the name of the mailer in the output. + + The mmaaiillssttaattss utility exits 0 on success, and >0 if an + error occurs. + +FFIILLEESS + /etc/mail/sendmail.cf The default sseennddmmaaiill ``cf'' file. + /etc/mail/statistics The default sseennddmmaaiill statistics + file. + +SSEEEE AALLSSOO + mailq(1), sendmail(8) + + + + April 25, 1996 1 + + diff --git a/gnu/usr.sbin/sendmail/mailstats/mailstats.8 b/gnu/usr.sbin/sendmail/mailstats/mailstats.8 new file mode 100644 index 00000000000..052d2206b2e --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/mailstats.8 @@ -0,0 +1,107 @@ +.\" Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers. +.\" All rights reserved. +.\" +.\" By using this file, you agree to the terms and conditions set +.\" forth in the LICENSE file which can be found at the top level of +.\" the sendmail distribution. +.\" +.\" +.\" $Sendmail: mailstats.8,v 8.16 2000/02/01 05:49:53 gshapiro Exp $ +.\" +.TH MAILSTATS 1 "April 25, 1996" +.SH NAME +.B mailstats +\- display mail statistics +.SH SYNOPSIS +.B mailstats +.RB [ \-o "] [" \-p ] +.RB [ \-C +.IR cffile ] +.RB [ \-f +.IR stfile ] +.SH DESCRIPTION +The +.B mailstats +utility displays the current mail statistics. +.PP +First, the time at which statistics started being kept is displayed, +in the format specified by +ctime(3). +Then, +the statistics for each mailer are displayed on a single line, +each with the following whitespace separated fields: +.sp +.RS +.PD 0.2v +.TP 1.2i +.B M +The mailer number. +.TP +.B msgsfr +Number of messages from the mailer. +.TP +.B bytes_from +Kbytes from the mailer. +.TP +.B msgsto +Number of messages to the mailer. +.TP +.B bytes_to +Kbytes to the mailer. +.TP +.B msgsrej +Number of messages rejected. +.TP +.B msgsdis +Number of messages discarded. +.TP +.B Mailer +The name of the mailer. +.PD +.RE +.PP +After this display, a line totaling the values for all of the mailers +is displayed (preceeded with a ``T''), +separated from the previous information by a line containing only equals +(``='') +characters. +Another line preceeded with a ``C'' lists the number of connections. +.PP +The options are as follows: +.TP +.B \-C +Read the specified file instead of the default +.B sendmail +``cf'' file. +.TP +.B \-f +Read the specified statistics file instead of the statistics file +specified in the +.B sendmail +``cf'' file. +.TP +.B \-p +Output information in program-readable mode and clear statistics. +.TP +.B \-o +Don't display the name of the mailer in the output. +.PP +The +.B mailstats +utility exits 0 on success, and >0 if an error occurs. +.SH FILES +.PD 0.2v +.TP 2.5i +/etc/mail/sendmail.cf +The default +.B sendmail +``cf'' file. +.TP +/etc/mail/statistics +The default +.B sendmail +statistics file. +.PD +.SH SEE ALSO +mailq(1), +sendmail(8) diff --git a/gnu/usr.sbin/sendmail/mailstats/mailstats.c b/gnu/usr.sbin/sendmail/mailstats/mailstats.c new file mode 100644 index 00000000000..74746da99e5 --- /dev/null +++ b/gnu/usr.sbin/sendmail/mailstats/mailstats.c @@ -0,0 +1,313 @@ +/* + * Copyright (c) 1998, 1999 Sendmail, Inc. and its suppliers. + * All rights reserved. + * Copyright (c) 1983 Eric P. Allman. All rights reserved. + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + * + * + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1998, 1999 Sendmail, Inc. and its suppliers.\n\ + All rights reserved.\n\ + Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* ! lint */ + +#ifndef lint +static char id[] = "@(#)$Sendmail: mailstats.c,v 8.53 1999/10/13 05:43:54 gshapiro Exp $"; +#endif /* ! lint */ + +#include <unistd.h> +#include <stddef.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <time.h> +#ifdef EX_OK +# undef EX_OK /* unistd.h may have another use for this */ +#endif /* EX_OK */ +#include <sysexits.h> + +#include <sendmail/sendmail.h> +#include <sendmail/mailstats.h> +#include <sendmail/pathnames.h> + +#define MNAMELEN 20 /* max length of mailer name */ + +int +main(argc, argv) + int argc; + char **argv; +{ + register int i; + int mno; + int save_errno; + int ch, fd; + char *sfile; + char *cfile; + FILE *cfp; + bool mnames; + bool progmode; + long frmsgs = 0, frbytes = 0, tomsgs = 0, tobytes = 0, rejmsgs = 0; + long dismsgs = 0; + time_t now; + char mtable[MAXMAILERS][MNAMELEN + 1]; + char sfilebuf[MAXLINE]; + char buf[MAXLINE]; + struct statistics stats; + extern char *ctime(); + extern char *optarg; + extern int optind; + + cfile = _PATH_SENDMAILCF; + sfile = NULL; + mnames = TRUE; + progmode = FALSE; + while ((ch = getopt(argc, argv, "C:f:op")) != EOF) + { + switch (ch) + { + case 'C': + cfile = optarg; + break; + + case 'f': + sfile = optarg; + break; + + case 'o': + mnames = FALSE; + break; + + case 'p': + progmode = TRUE; + break; + + case '?': + default: + usage: + (void) fputs("usage: mailstats [-C cffile] [-f stfile] -o -p\n", + stderr); + exit(EX_USAGE); + } + } + argc -= optind; + argv += optind; + + if (argc != 0) + goto usage; + + if ((cfp = fopen(cfile, "r")) == NULL) + { + save_errno = errno; + fprintf(stderr, "mailstats: "); + errno = save_errno; + perror(cfile); + exit(EX_NOINPUT); + } + + mno = 0; + (void) strlcpy(mtable[mno++], "prog", MNAMELEN + 1); + (void) strlcpy(mtable[mno++], "*file*", MNAMELEN + 1); + (void) strlcpy(mtable[mno++], "*include*", MNAMELEN + 1); + + while (fgets(buf, sizeof(buf), cfp) != NULL) + { + register char *b; + char *s; + register char *m; + + b = buf; + switch (*b++) + { + case 'M': /* mailer definition */ + break; + + case 'O': /* option -- see if .st file */ + if (strncasecmp(b, " StatusFile", 11) == 0 && + !(isascii(b[11]) && isalnum(b[11]))) + { + /* new form -- find value */ + b = strchr(b, '='); + if (b == NULL) + continue; + while (isascii(*++b) && isspace(*b)) + continue; + } + else if (*b++ != 'S') + { + /* something else boring */ + continue; + } + + /* this is the S or StatusFile option -- save it */ + if (strlcpy(sfilebuf, b, sizeof sfilebuf) >= + sizeof sfilebuf) + { + fprintf(stderr, + "StatusFile filename too long: %.30s...\n", + b); + exit(EX_CONFIG); + } + b = strchr(sfilebuf, '#'); + if (b == NULL) + b = strchr(sfilebuf, '\n'); + if (b == NULL) + b = &sfilebuf[strlen(sfilebuf)]; + while (isascii(*--b) && isspace(*b)) + continue; + *++b = '\0'; + if (sfile == NULL) + sfile = sfilebuf; + + default: + continue; + } + + if (mno >= MAXMAILERS) + { + fprintf(stderr, + "Too many mailers defined, %d max.\n", + MAXMAILERS); + exit(EX_SOFTWARE); + } + m = mtable[mno]; + s = m + MNAMELEN; /* is [MNAMELEN + 1] */ + while (*b != ',' && !(isascii(*b) && isspace(*b)) && + *b != '\0' && m < s) + *m++ = *b++; + *m = '\0'; + for (i = 0; i < mno; i++) + { + if (strcmp(mtable[i], mtable[mno]) == 0) + break; + } + if (i == mno) + mno++; + } + (void) fclose(cfp); + for (; mno < MAXMAILERS; mno++) + mtable[mno][0]='\0'; + + if (sfile == NULL) + { + fprintf(stderr, "mailstats: no statistics file located\n"); + exit (EX_OSFILE); + } + + if ((fd = open(sfile, O_RDONLY)) < 0 || + (i = read(fd, &stats, sizeof stats)) < 0) + { + save_errno = errno; + (void) fputs("mailstats: ", stderr); + errno = save_errno; + perror(sfile); + exit(EX_NOINPUT); + } + if (i == 0) + { + (void) sleep(1); + if ((i = read(fd, &stats, sizeof stats)) < 0) + { + save_errno = errno; + (void) fputs("mailstats: ", stderr); + errno = save_errno; + perror(sfile); + exit(EX_NOINPUT); + } + else if (i == 0) + { + memset((ARBPTR_T) &stats, '\0', sizeof stats); + (void) time(&stats.stat_itime); + } + } + if (i != 0) + { + if (stats.stat_magic != STAT_MAGIC) + { + fprintf(stderr, + "mailstats: incorrect magic number in %s\n", + sfile); + exit(EX_OSERR); + } + else if (stats.stat_version != STAT_VERSION) + { + fprintf(stderr, + "mailstats version (%d) incompatible with %s version (%d)\n", + STAT_VERSION, sfile, stats.stat_version); + exit(EX_OSERR); + } + else if (i != sizeof stats || stats.stat_size != sizeof(stats)) + { + (void) fputs("mailstats: file size changed.\n", stderr); + exit(EX_OSERR); + } + } + + if (progmode) + { + (void) time(&now); + printf("%ld %ld\n", (long) stats.stat_itime, (long) now); + } + else + { + printf("Statistics from %s", ctime(&stats.stat_itime)); + printf(" M msgsfr bytes_from msgsto bytes_to msgsrej msgsdis%s\n", + mnames ? " Mailer" : ""); + } + for (i = 0; i < MAXMAILERS; i++) + { + if (stats.stat_nf[i] || stats.stat_nt[i] || + stats.stat_nr[i] || stats.stat_nd[i]) + { + char *format; + + if (progmode) + format = "%2d %8ld %10ld %8ld %10ld %6ld %6ld"; + else + format = "%2d %8ld %10ldK %8ld %10ldK %6ld %6ld"; + printf(format, i, + stats.stat_nf[i], stats.stat_bf[i], + stats.stat_nt[i], stats.stat_bt[i], + stats.stat_nr[i], stats.stat_nd[i]); + if (mnames) + printf(" %s", mtable[i]); + printf("\n"); + frmsgs += stats.stat_nf[i]; + frbytes += stats.stat_bf[i]; + tomsgs += stats.stat_nt[i]; + tobytes += stats.stat_bt[i]; + rejmsgs += stats.stat_nr[i]; + dismsgs += stats.stat_nd[i]; + } + } + if (progmode) + { + printf(" T %8ld %10ld %8ld %10ld %6ld %6ld\n", + frmsgs, frbytes, tomsgs, tobytes, rejmsgs, dismsgs); + printf(" C %8ld %8ld %6ld\n", + stats.stat_cf, stats.stat_ct, stats.stat_cr); + (void) close(fd); + fd = open(sfile, O_RDWR | O_TRUNC); + if (fd >= 0) + (void) close(fd); + } + else + { + printf("=============================================================\n"); + printf(" T %8ld %10ldK %8ld %10ldK %6ld %6ld\n", + frmsgs, frbytes, tomsgs, tobytes, rejmsgs, dismsgs); + printf(" C %8ld %10s %8ld %10s %6ld\n", + stats.stat_cf, "", stats.stat_ct, "", stats.stat_cr); + } + exit(EX_OK); + /* NOTREACHED */ + return EX_OK; +} |