diff options
author | Andreas Beckmann <debian@abeckmann.de> | 2012-10-01 19:58:36 +0200 |
---|---|---|
committer | Andreas Beckmann <debian@abeckmann.de> | 2012-10-01 19:58:36 +0200 |
commit | 6c193ce1dd1d07ebdc1372e38bc4908ab1c37705 (patch) | |
tree | 3dfb801c5b92bf817d0417afd1b3637a59f689fa /mailstats | |
download | sendmail-upstream/8.8.8.tar.gz |
Imported Upstream version 8.8.8upstream/8.8.8
Diffstat (limited to 'mailstats')
-rw-r--r-- | mailstats/Makefile | 8 | ||||
-rw-r--r-- | mailstats/Makefile.dist | 78 | ||||
-rw-r--r-- | mailstats/mailstats.0 | 47 | ||||
-rw-r--r-- | mailstats/mailstats.8 | 80 | ||||
-rw-r--r-- | mailstats/mailstats.c | 247 |
5 files changed, 460 insertions, 0 deletions
diff --git a/mailstats/Makefile b/mailstats/Makefile new file mode 100644 index 0000000..d1a3996 --- /dev/null +++ b/mailstats/Makefile @@ -0,0 +1,8 @@ +# @(#)Makefile 8.2 (Berkeley) 9/21/96 + +PROG= mailstats +MAN8= mailstats.0 +CFLAGS+=-I${.CURDIR}/../src + +.include "../../Makefile.inc" +.include <bsd.prog.mk> diff --git a/mailstats/Makefile.dist b/mailstats/Makefile.dist new file mode 100644 index 0000000..5bf0f20 --- /dev/null +++ b/mailstats/Makefile.dist @@ -0,0 +1,78 @@ +# +# This Makefile is designed to work on the old "make" program. It does +# not use the obj subdirectory. It also does not install documentation +# automatically -- think of it as a quick start for sites that have the +# old make program (I recommend that you get and port the new make if you +# are going to be doing any signficant work on sendmail). +# +# @(#)Makefile.dist 8.2 (Berkeley) 9/21/96 +# + +# use O=-O (usual) or O=-g (debugging) +O= -O + +# location of sendmail source directory +SRCDIR= ../src + +# environment definitions (e.g., -D_AIX3) +ENVDEF= + +# see also conf.h for additional compilation flags + +# include directories +INCDIRS=-I${SRCDIR} -I/usr/sww/include + +# loader options +LDOPTS= + +# library directories +LIBDIRS=-L/usr/sww/lib + +# libraries required on your system +LIBS= + +# location of mailstats binary (usually /usr/sbin or /usr/etc) +BINDIR= ${DESTDIR}/usr/sbin + +# additional .o files needed +OBJADD= + +################### end of user configuration flags ###################### + +CFLAGS= -I. $O ${INCDIRS} ${ENVDEF} + +OBJS= mailstats.o ${OBJADD} + +LINKS= ${DESTDIR}/usr/ucb/newaliases ${DESTDIR}/usr/ucb/mailq +BINOWN= bin +BINGRP= bin +BINMODE=555 + +ALL= mailstats mailstats.0 + +all: ${ALL} + +mailstats: ${BEFORE} ${OBJS} + ${CC} -o mailstats ${LDOPTS} ${OBJS} ${LIBDIRS} ${LIBS} + +#NROFF= nroff -h +NROFF= groff -Tascii +MANDOC= -mandoc + +mailstats.0: mailstats.8 + ${NROFF} ${MANDOC} mailstats.8 > mailstats.0 + +install: install-mailstats install-docs + +install-mailstats: mailstats + install -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} mailstats ${BINDIR} + +# doesn't actually install them -- you may want to install pre-nroff versions +install-docs: mailstats.0 + +clean: + rm -f ${OBJS} mailstats mailstats.0 + +# dependencies +# gross overkill, and yet still not quite enough.... +${OBJS}: ${SRCDIR}/sendmail.h ${SRCDIR}/mailstats.h ${SRCDIR}/conf.h diff --git a/mailstats/mailstats.0 b/mailstats/mailstats.0 new file mode 100644 index 0000000..b6fbcf2 --- /dev/null +++ b/mailstats/mailstats.0 @@ -0,0 +1,47 @@ +MAILSTATS(1) BSD Reference Manual MAILSTATS(1) + +NNAAMMEE + mmaaiillssttaattss - display mail statistics + +SSYYNNOOPPSSIISS + mmaaiillssttaattss [--oo] [--CC _c_f_f_i_l_e] [--ff _s_t_f_i_l_e] + +DDEESSCCRRIIPPTTIIOONN + The mmaaiillssttaattss utility displays the current mail statistics. + + 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 sepa- + rated 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. + MMaaiilleerr The name of the mailer. + + After this display, a line totaling the values for all of the mailers is + displayed, separated from the previous information by a line containing + only equals (``='') characters. + + 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. + + --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/sendmail.cf The default sseennddmmaaiill ``cf'' file. + /var/log/sendmail.st The default sseennddmmaaiill statistics file. + +SSEEEE AALLSSOO + mailq(1), sendmail(8) + +3rd Berkeley Distribution April 25, 1996 1 diff --git a/mailstats/mailstats.8 b/mailstats/mailstats.8 new file mode 100644 index 0000000..3fe87c9 --- /dev/null +++ b/mailstats/mailstats.8 @@ -0,0 +1,80 @@ +.\" @(#)mailstats.8 8.1 (Berkeley) 9/21/96 +.Dd April 25, 1996 +.Dt MAILSTATS 1 +.Os BSD 3 +.Sh NAME +.Nm mailstats +.Nd display mail statistics +.Sh SYNOPSIS +.Nm mailstats +.Op Fl o +.Op Fl C Ar cffile +.Op Fl f Ar stfile +.Sh DESCRIPTION +The +.Nm mailstats +utility displays the current mail statistics. +.Pp +First, the time at which statistics started being kept is displayed, +in the format specified by +.Xr ctime 3 . +Then, +the statistics for each mailer are displayed on a single line, +each with the following whitespace separated fields: +.Pp +.Bl -tag -width 10n -offset indent -compact +.It Sy M +The mailer number. +.It Sy msgsfr +Number of messages from the mailer. +.It Sy bytes_from +Kbytes from the mailer. +.It Sy msgsto +Number of messages to the mailer. +.It Sy bytes_to +Kbytes to the mailer. +.It Sy Mailer +The name of the mailer. +.El +.Pp +After this display, a line totaling the values for all of the mailers +is displayed, +separated from the previous information by a line containing only equals +.Pq Dq \&= +characters. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl C +Read the specified file instead of the default +.Nm sendmail +.Dq cf +file. +.It Fl f +Read the specified statistics file instead of the statistics file +specified in the +.Nm sendmail +.Dq cf +file. +.It Fl o +Don't display the name of the mailer in the output. +.El +.Pp +The +.Nm mailstats +utility exits 0 on success, and >0 if an error occurs. +.Sh FILES +.Bl -tag -width /var/log/sendmail.stXX -compact +.It Pa /etc/sendmail.cf +The default +.Nm sendmail +.Dq cf +file. +.It Pa /var/log/sendmail.st +The default +.Nm sendmail +statistics file. +.El +.Sh SEE ALSO +.Xr mailq 1 , +.Xr sendmail 8 diff --git a/mailstats/mailstats.c b/mailstats/mailstats.c new file mode 100644 index 0000000..ffbb2bb --- /dev/null +++ b/mailstats/mailstats.c @@ -0,0 +1,247 @@ +/* + * Copyright (c) 1983 Eric P. Allman + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)mailstats.c 8.10 (Berkeley) 5/30/97"; +#endif /* not lint */ + +#define NOT_SENDMAIL +#include <sendmail.h> +#include <mailstats.h> +#include <pathnames.h> + +#define MNAMELEN 20 /* max length of mailer name */ + +main(argc, argv) + int argc; + char **argv; +{ + extern char *optarg; + extern int optind; + struct statistics stat; + register int i; + int mno; + int ch, fd; + char *sfile; + char *cfile; + FILE *cfp; + bool mnames; + long frmsgs = 0, frbytes = 0, tomsgs = 0, tobytes = 0; + char mtable[MAXMAILERS][MNAMELEN+1]; + char sfilebuf[MAXLINE]; + char buf[MAXLINE]; + extern char *ctime(); + + cfile = _PATH_SENDMAILCF; + sfile = NULL; + mnames = TRUE; + while ((ch = getopt(argc, argv, "C:f:o")) != EOF) + { + switch (ch) + { + case 'C': + cfile = optarg; + break; + + case 'f': + sfile = optarg; + break; + + case 'o': + mnames = FALSE; + break; + + case '?': + default: + usage: + fputs("usage: mailstats [-C cffile] [-f stfile] -o\n", + stderr); + exit(EX_USAGE); + } + } + argc -= optind; + argv += optind; + + if (argc != 0) + goto usage; + + if ((cfp = fopen(cfile, "r")) == NULL) + { + fprintf(stderr, "mailstats: "); + perror(cfile); + exit(EX_NOINPUT); + } + + mno = 0; + (void) strcpy(mtable[mno++], "prog"); + (void) strcpy(mtable[mno++], "*file*"); + (void) strcpy(mtable[mno++], "*include*"); + + 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 && + !isalnum(b[11])) + { + /* new form -- find value */ + b = strchr(b, '='); + if (b == NULL) + continue; + while (isspace(*++b)) + continue; + } + else if (*b++ != 'S') + { + /* something else boring */ + continue; + } + + /* this is the S or StatusFile option -- save it */ + if (strlen(b) >= sizeof sfilebuf) + { + fprintf(stderr, + "StatusFile filename too long: %.30s...\n", + s); + exit(EX_CONFIG); + } + strcpy(sfilebuf, b); + b = strchr(sfilebuf, '#'); + if (b == NULL) + b = strchr(sfilebuf, '\n'); + if (b == NULL) + b = &sfilebuf[strlen(sfilebuf)]; + while (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 != ',' && !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, &stat, sizeof stat)) < 0) + { + fputs("mailstats: ", stderr); + perror(sfile); + exit(EX_NOINPUT); + } + if (i == 0) + { + sleep(1); + i = read(fd, &stat, sizeof stat); + if (i == 0) + { + bzero((ARBPTR_T) &stat, sizeof stat); + (void) time(&stat.stat_itime); + } + } + else if (i != sizeof stat || stat.stat_size != sizeof(stat)) + { + fputs("mailstats: file size changed.\n", stderr); + exit(EX_OSERR); + } + + printf("Statistics from %s", ctime(&stat.stat_itime)); + printf(" M msgsfr bytes_from msgsto bytes_to%s\n", + mnames ? " Mailer" : ""); + for (i = 0; i < MAXMAILERS; i++) + { + if (stat.stat_nf[i] || stat.stat_nt[i]) + { + printf("%2d %6ld %10ldK %6ld %10ldK", i, + stat.stat_nf[i], stat.stat_bf[i], + stat.stat_nt[i], stat.stat_bt[i]); + if (mnames) + printf(" %s", mtable[i]); + printf("\n"); + frmsgs += stat.stat_nf[i]; + frbytes += stat.stat_bf[i]; + tomsgs += stat.stat_nt[i]; + tobytes += stat.stat_bt[i]; + } + } + printf("========================================\n"); + printf(" T %6ld %10ldK %6ld %10ldK\n", + frmsgs, frbytes, tomsgs, tobytes); + exit(EX_OK); +} |