xref: /titanic_52/usr/src/cmd/sendmail/aux/mailstats.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers.
3*7c478bd9Sstevel@tonic-gate  *	All rights reserved.
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Eric P. Allman.  All rights reserved.
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
6*7c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
9*7c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
10*7c478bd9Sstevel@tonic-gate  * the sendmail distribution.
11*7c478bd9Sstevel@tonic-gate  *
12*7c478bd9Sstevel@tonic-gate  *
13*7c478bd9Sstevel@tonic-gate  */
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <sm/gen.h>
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate SM_IDSTR(copyright,
20*7c478bd9Sstevel@tonic-gate "@(#) Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers.\n\
21*7c478bd9Sstevel@tonic-gate 	All rights reserved.\n\
22*7c478bd9Sstevel@tonic-gate      Copyright (c) 1988, 1993\n\
23*7c478bd9Sstevel@tonic-gate 	The Regents of the University of California.  All rights reserved.\n")
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate SM_IDSTR(id, "@(#)$Id: mailstats.c,v 8.100 2002/06/27 23:24:06 gshapiro Exp $")
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <unistd.h>
28*7c478bd9Sstevel@tonic-gate #include <stddef.h>
29*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
30*7c478bd9Sstevel@tonic-gate #include <ctype.h>
31*7c478bd9Sstevel@tonic-gate #include <string.h>
32*7c478bd9Sstevel@tonic-gate #include <time.h>
33*7c478bd9Sstevel@tonic-gate #ifdef EX_OK
34*7c478bd9Sstevel@tonic-gate # undef EX_OK		/* unistd.h may have another use for this */
35*7c478bd9Sstevel@tonic-gate #endif /* EX_OK */
36*7c478bd9Sstevel@tonic-gate #include <sysexits.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #include <sm/errstring.h>
39*7c478bd9Sstevel@tonic-gate #include <sm/limits.h>
40*7c478bd9Sstevel@tonic-gate #include <sendmail/sendmail.h>
41*7c478bd9Sstevel@tonic-gate #include <sendmail/mailstats.h>
42*7c478bd9Sstevel@tonic-gate #include <sendmail/pathnames.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #define MNAMELEN	20	/* max length of mailer name */
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate int
48*7c478bd9Sstevel@tonic-gate main(argc, argv)
49*7c478bd9Sstevel@tonic-gate 	int argc;
50*7c478bd9Sstevel@tonic-gate 	char **argv;
51*7c478bd9Sstevel@tonic-gate {
52*7c478bd9Sstevel@tonic-gate 	register int i;
53*7c478bd9Sstevel@tonic-gate 	int mno;
54*7c478bd9Sstevel@tonic-gate 	int save_errno;
55*7c478bd9Sstevel@tonic-gate 	int ch, fd;
56*7c478bd9Sstevel@tonic-gate 	char *sfile;
57*7c478bd9Sstevel@tonic-gate 	char *cfile;
58*7c478bd9Sstevel@tonic-gate 	SM_FILE_T *cfp;
59*7c478bd9Sstevel@tonic-gate 	bool mnames;
60*7c478bd9Sstevel@tonic-gate 	bool progmode;
61*7c478bd9Sstevel@tonic-gate 	bool trunc;
62*7c478bd9Sstevel@tonic-gate 	long frmsgs = 0, frbytes = 0, tomsgs = 0, tobytes = 0, rejmsgs = 0;
63*7c478bd9Sstevel@tonic-gate 	long dismsgs = 0;
64*7c478bd9Sstevel@tonic-gate 	long quarmsgs = 0;
65*7c478bd9Sstevel@tonic-gate 	time_t now;
66*7c478bd9Sstevel@tonic-gate 	char mtable[MAXMAILERS][MNAMELEN + 1];
67*7c478bd9Sstevel@tonic-gate 	char sfilebuf[MAXPATHLEN];
68*7c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
69*7c478bd9Sstevel@tonic-gate 	struct statistics stats;
70*7c478bd9Sstevel@tonic-gate 	extern char *ctime();
71*7c478bd9Sstevel@tonic-gate 	extern char *optarg;
72*7c478bd9Sstevel@tonic-gate 	extern int optind;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	cfile = getcfname(0, 0, SM_GET_SENDMAIL_CF, NULL);
75*7c478bd9Sstevel@tonic-gate 	sfile = NULL;
76*7c478bd9Sstevel@tonic-gate 	mnames = true;
77*7c478bd9Sstevel@tonic-gate 	progmode = false;
78*7c478bd9Sstevel@tonic-gate 	trunc = false;
79*7c478bd9Sstevel@tonic-gate 	while ((ch = getopt(argc, argv, "cC:f:opP")) != -1)
80*7c478bd9Sstevel@tonic-gate 	{
81*7c478bd9Sstevel@tonic-gate 		switch (ch)
82*7c478bd9Sstevel@tonic-gate 		{
83*7c478bd9Sstevel@tonic-gate 		  case 'c':
84*7c478bd9Sstevel@tonic-gate 			cfile = getcfname(0, 0, SM_GET_SUBMIT_CF, NULL);
85*7c478bd9Sstevel@tonic-gate 			break;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 		  case 'C':
88*7c478bd9Sstevel@tonic-gate 			cfile = optarg;
89*7c478bd9Sstevel@tonic-gate 			break;
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 		  case 'f':
92*7c478bd9Sstevel@tonic-gate 			sfile = optarg;
93*7c478bd9Sstevel@tonic-gate 			break;
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 		  case 'o':
96*7c478bd9Sstevel@tonic-gate 			mnames = false;
97*7c478bd9Sstevel@tonic-gate 			break;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 		  case 'p':
100*7c478bd9Sstevel@tonic-gate 			trunc = true;
101*7c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 		  case 'P':
104*7c478bd9Sstevel@tonic-gate 			progmode = true;
105*7c478bd9Sstevel@tonic-gate 			break;
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate 		  case '?':
108*7c478bd9Sstevel@tonic-gate 		  default:
109*7c478bd9Sstevel@tonic-gate   usage:
110*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT,
111*7c478bd9Sstevel@tonic-gate 			    "usage: mailstats [-C cffile] [-c] [-P] [-f stfile] [-o] [-p]\n");
112*7c478bd9Sstevel@tonic-gate 			exit(EX_USAGE);
113*7c478bd9Sstevel@tonic-gate 		}
114*7c478bd9Sstevel@tonic-gate 	}
115*7c478bd9Sstevel@tonic-gate 	argc -= optind;
116*7c478bd9Sstevel@tonic-gate 	argv += optind;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	if (argc != 0)
119*7c478bd9Sstevel@tonic-gate 		goto usage;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	if ((cfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, cfile, SM_IO_RDONLY,
122*7c478bd9Sstevel@tonic-gate 			      NULL)) == NULL)
123*7c478bd9Sstevel@tonic-gate 	{
124*7c478bd9Sstevel@tonic-gate 		save_errno = errno;
125*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "mailstats: ");
126*7c478bd9Sstevel@tonic-gate 		errno = save_errno;
127*7c478bd9Sstevel@tonic-gate 		sm_perror(cfile);
128*7c478bd9Sstevel@tonic-gate 		exit(EX_NOINPUT);
129*7c478bd9Sstevel@tonic-gate 	}
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	mno = 0;
132*7c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(mtable[mno++], "prog", MNAMELEN + 1);
133*7c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(mtable[mno++], "*file*", MNAMELEN + 1);
134*7c478bd9Sstevel@tonic-gate 	(void) sm_strlcpy(mtable[mno++], "*include*", MNAMELEN + 1);
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	while (sm_io_fgets(cfp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL)
137*7c478bd9Sstevel@tonic-gate 	{
138*7c478bd9Sstevel@tonic-gate 		register char *b;
139*7c478bd9Sstevel@tonic-gate 		char *s;
140*7c478bd9Sstevel@tonic-gate 		register char *m;
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 		b = strchr(buf, '#');
143*7c478bd9Sstevel@tonic-gate 		if (b == NULL)
144*7c478bd9Sstevel@tonic-gate 			b = strchr(buf, '\n');
145*7c478bd9Sstevel@tonic-gate 		if (b == NULL)
146*7c478bd9Sstevel@tonic-gate 			b = &buf[strlen(buf)];
147*7c478bd9Sstevel@tonic-gate 		while (isascii(*--b) && isspace(*b))
148*7c478bd9Sstevel@tonic-gate 			continue;
149*7c478bd9Sstevel@tonic-gate 		*++b = '\0';
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 		b = buf;
152*7c478bd9Sstevel@tonic-gate 		switch (*b++)
153*7c478bd9Sstevel@tonic-gate 		{
154*7c478bd9Sstevel@tonic-gate 		  case 'M':		/* mailer definition */
155*7c478bd9Sstevel@tonic-gate 			break;
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 		  case 'O':		/* option -- see if .st file */
158*7c478bd9Sstevel@tonic-gate 			if (sm_strncasecmp(b, " StatusFile", 11) == 0 &&
159*7c478bd9Sstevel@tonic-gate 			    !(isascii(b[11]) && isalnum(b[11])))
160*7c478bd9Sstevel@tonic-gate 			{
161*7c478bd9Sstevel@tonic-gate 				/* new form -- find value */
162*7c478bd9Sstevel@tonic-gate 				b = strchr(b, '=');
163*7c478bd9Sstevel@tonic-gate 				if (b == NULL)
164*7c478bd9Sstevel@tonic-gate 					continue;
165*7c478bd9Sstevel@tonic-gate 				while (isascii(*++b) && isspace(*b))
166*7c478bd9Sstevel@tonic-gate 					continue;
167*7c478bd9Sstevel@tonic-gate 			}
168*7c478bd9Sstevel@tonic-gate 			else if (*b++ != 'S')
169*7c478bd9Sstevel@tonic-gate 			{
170*7c478bd9Sstevel@tonic-gate 				/* something else boring */
171*7c478bd9Sstevel@tonic-gate 				continue;
172*7c478bd9Sstevel@tonic-gate 			}
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 			/* this is the S or StatusFile option -- save it */
175*7c478bd9Sstevel@tonic-gate 			if (sm_strlcpy(sfilebuf, b, sizeof sfilebuf) >=
176*7c478bd9Sstevel@tonic-gate 			    sizeof sfilebuf)
177*7c478bd9Sstevel@tonic-gate 			{
178*7c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
179*7c478bd9Sstevel@tonic-gate 						     "StatusFile filename too long: %.30s...\n",
180*7c478bd9Sstevel@tonic-gate 						     b);
181*7c478bd9Sstevel@tonic-gate 				exit(EX_CONFIG);
182*7c478bd9Sstevel@tonic-gate 			}
183*7c478bd9Sstevel@tonic-gate 			if (sfile == NULL)
184*7c478bd9Sstevel@tonic-gate 				sfile = sfilebuf;
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 		  default:
187*7c478bd9Sstevel@tonic-gate 			continue;
188*7c478bd9Sstevel@tonic-gate 		}
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 		if (mno >= MAXMAILERS)
191*7c478bd9Sstevel@tonic-gate 		{
192*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
193*7c478bd9Sstevel@tonic-gate 					     "Too many mailers defined, %d max.\n",
194*7c478bd9Sstevel@tonic-gate 					     MAXMAILERS);
195*7c478bd9Sstevel@tonic-gate 			exit(EX_SOFTWARE);
196*7c478bd9Sstevel@tonic-gate 		}
197*7c478bd9Sstevel@tonic-gate 		m = mtable[mno];
198*7c478bd9Sstevel@tonic-gate 		s = m + MNAMELEN;		/* is [MNAMELEN + 1] */
199*7c478bd9Sstevel@tonic-gate 		while (*b != ',' && !(isascii(*b) && isspace(*b)) &&
200*7c478bd9Sstevel@tonic-gate 		       *b != '\0' && m < s)
201*7c478bd9Sstevel@tonic-gate 			*m++ = *b++;
202*7c478bd9Sstevel@tonic-gate 		*m = '\0';
203*7c478bd9Sstevel@tonic-gate 		for (i = 0; i < mno; i++)
204*7c478bd9Sstevel@tonic-gate 		{
205*7c478bd9Sstevel@tonic-gate 			if (strcmp(mtable[i], mtable[mno]) == 0)
206*7c478bd9Sstevel@tonic-gate 				break;
207*7c478bd9Sstevel@tonic-gate 		}
208*7c478bd9Sstevel@tonic-gate 		if (i == mno)
209*7c478bd9Sstevel@tonic-gate 			mno++;
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate 	(void) sm_io_close(cfp, SM_TIME_DEFAULT);
212*7c478bd9Sstevel@tonic-gate 	for (; mno < MAXMAILERS; mno++)
213*7c478bd9Sstevel@tonic-gate 		mtable[mno][0] = '\0';
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 	if (sfile == NULL)
216*7c478bd9Sstevel@tonic-gate 	{
217*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
218*7c478bd9Sstevel@tonic-gate 				     "mailstats: no statistics file located\n");
219*7c478bd9Sstevel@tonic-gate 		exit(EX_OSFILE);
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	fd = open(sfile, O_RDONLY, 0600);
223*7c478bd9Sstevel@tonic-gate 	if ((fd < 0) || (i = read(fd, &stats, sizeof stats)) < 0)
224*7c478bd9Sstevel@tonic-gate 	{
225*7c478bd9Sstevel@tonic-gate 		save_errno = errno;
226*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, "mailstats: ");
227*7c478bd9Sstevel@tonic-gate 		errno = save_errno;
228*7c478bd9Sstevel@tonic-gate 		sm_perror(sfile);
229*7c478bd9Sstevel@tonic-gate 		exit(EX_NOINPUT);
230*7c478bd9Sstevel@tonic-gate 	}
231*7c478bd9Sstevel@tonic-gate 	if (i == 0)
232*7c478bd9Sstevel@tonic-gate 	{
233*7c478bd9Sstevel@tonic-gate 		(void) sleep(1);
234*7c478bd9Sstevel@tonic-gate 		if ((i = read(fd, &stats, sizeof stats)) < 0)
235*7c478bd9Sstevel@tonic-gate 		{
236*7c478bd9Sstevel@tonic-gate 			save_errno = errno;
237*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT,
238*7c478bd9Sstevel@tonic-gate 					   "mailstats: ");
239*7c478bd9Sstevel@tonic-gate 			errno = save_errno;
240*7c478bd9Sstevel@tonic-gate 			sm_perror(sfile);
241*7c478bd9Sstevel@tonic-gate 			exit(EX_NOINPUT);
242*7c478bd9Sstevel@tonic-gate 		}
243*7c478bd9Sstevel@tonic-gate 		else if (i == 0)
244*7c478bd9Sstevel@tonic-gate 		{
245*7c478bd9Sstevel@tonic-gate 			memset((ARBPTR_T) &stats, '\0', sizeof stats);
246*7c478bd9Sstevel@tonic-gate 			(void) time(&stats.stat_itime);
247*7c478bd9Sstevel@tonic-gate 		}
248*7c478bd9Sstevel@tonic-gate 	}
249*7c478bd9Sstevel@tonic-gate 	if (i != 0)
250*7c478bd9Sstevel@tonic-gate 	{
251*7c478bd9Sstevel@tonic-gate 		if (stats.stat_magic != STAT_MAGIC)
252*7c478bd9Sstevel@tonic-gate 		{
253*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
254*7c478bd9Sstevel@tonic-gate 					     "mailstats: incorrect magic number in %s\n",
255*7c478bd9Sstevel@tonic-gate 					     sfile);
256*7c478bd9Sstevel@tonic-gate 			exit(EX_OSERR);
257*7c478bd9Sstevel@tonic-gate 		}
258*7c478bd9Sstevel@tonic-gate 		else if (stats.stat_version != STAT_VERSION)
259*7c478bd9Sstevel@tonic-gate 		{
260*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
261*7c478bd9Sstevel@tonic-gate 					     "mailstats version (%d) incompatible with %s version (%d)\n",
262*7c478bd9Sstevel@tonic-gate 					     STAT_VERSION, sfile,
263*7c478bd9Sstevel@tonic-gate 					     stats.stat_version);
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 			exit(EX_OSERR);
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 		else if (i != sizeof stats || stats.stat_size != sizeof(stats))
268*7c478bd9Sstevel@tonic-gate 		{
269*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fputs(smioerr, SM_TIME_DEFAULT,
270*7c478bd9Sstevel@tonic-gate 					   "mailstats: file size changed.\n");
271*7c478bd9Sstevel@tonic-gate 			exit(EX_OSERR);
272*7c478bd9Sstevel@tonic-gate 		}
273*7c478bd9Sstevel@tonic-gate 	}
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 	if (progmode)
276*7c478bd9Sstevel@tonic-gate 	{
277*7c478bd9Sstevel@tonic-gate 		(void) time(&now);
278*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%ld %ld\n",
279*7c478bd9Sstevel@tonic-gate 				     (long) stats.stat_itime, (long) now);
280*7c478bd9Sstevel@tonic-gate 	}
281*7c478bd9Sstevel@tonic-gate 	else
282*7c478bd9Sstevel@tonic-gate 	{
283*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
284*7c478bd9Sstevel@tonic-gate 				     "Statistics from %s",
285*7c478bd9Sstevel@tonic-gate 				     ctime(&stats.stat_itime));
286*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
287*7c478bd9Sstevel@tonic-gate 				     " M   msgsfr  bytes_from   msgsto    bytes_to  msgsrej msgsdis");
288*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, " msgsqur");
289*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s\n",
290*7c478bd9Sstevel@tonic-gate 				     mnames ? "  Mailer" : "");
291*7c478bd9Sstevel@tonic-gate 	}
292*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < MAXMAILERS; i++)
293*7c478bd9Sstevel@tonic-gate 	{
294*7c478bd9Sstevel@tonic-gate 		if (stats.stat_nf[i] || stats.stat_nt[i] ||
295*7c478bd9Sstevel@tonic-gate 		    stats.stat_nq[i] ||
296*7c478bd9Sstevel@tonic-gate 		    stats.stat_nr[i] || stats.stat_nd[i])
297*7c478bd9Sstevel@tonic-gate 		{
298*7c478bd9Sstevel@tonic-gate 			char *format;
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 			if (progmode)
301*7c478bd9Sstevel@tonic-gate 				format = "%2d %8ld %10ld %8ld %10ld   %6ld  %6ld";
302*7c478bd9Sstevel@tonic-gate 			else
303*7c478bd9Sstevel@tonic-gate 				format = "%2d %8ld %10ldK %8ld %10ldK   %6ld  %6ld";
304*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
305*7c478bd9Sstevel@tonic-gate 					     format, i,
306*7c478bd9Sstevel@tonic-gate 					     stats.stat_nf[i],
307*7c478bd9Sstevel@tonic-gate 					     stats.stat_bf[i],
308*7c478bd9Sstevel@tonic-gate 					     stats.stat_nt[i],
309*7c478bd9Sstevel@tonic-gate 					     stats.stat_bt[i],
310*7c478bd9Sstevel@tonic-gate 					     stats.stat_nr[i],
311*7c478bd9Sstevel@tonic-gate 					     stats.stat_nd[i]);
312*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
313*7c478bd9Sstevel@tonic-gate 					     "  %6ld", stats.stat_nq[i]);
314*7c478bd9Sstevel@tonic-gate 			if (mnames)
315*7c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
316*7c478bd9Sstevel@tonic-gate 						     "  %s",
317*7c478bd9Sstevel@tonic-gate 						      mtable[i]);
318*7c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "\n");
319*7c478bd9Sstevel@tonic-gate 			frmsgs += stats.stat_nf[i];
320*7c478bd9Sstevel@tonic-gate 			frbytes += stats.stat_bf[i];
321*7c478bd9Sstevel@tonic-gate 			tomsgs += stats.stat_nt[i];
322*7c478bd9Sstevel@tonic-gate 			tobytes += stats.stat_bt[i];
323*7c478bd9Sstevel@tonic-gate 			rejmsgs += stats.stat_nr[i];
324*7c478bd9Sstevel@tonic-gate 			dismsgs += stats.stat_nd[i];
325*7c478bd9Sstevel@tonic-gate 			quarmsgs += stats.stat_nq[i];
326*7c478bd9Sstevel@tonic-gate 		}
327*7c478bd9Sstevel@tonic-gate 	}
328*7c478bd9Sstevel@tonic-gate 	if (progmode)
329*7c478bd9Sstevel@tonic-gate 	{
330*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
331*7c478bd9Sstevel@tonic-gate 				     " T %8ld %10ld %8ld %10ld   %6ld  %6ld",
332*7c478bd9Sstevel@tonic-gate 				     frmsgs, frbytes, tomsgs, tobytes, rejmsgs,
333*7c478bd9Sstevel@tonic-gate 				     dismsgs);
334*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
335*7c478bd9Sstevel@tonic-gate 				     "  %6ld", quarmsgs);
336*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "\n");
337*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
338*7c478bd9Sstevel@tonic-gate 				     " C %8ld %8ld %6ld\n",
339*7c478bd9Sstevel@tonic-gate 				     stats.stat_cf, stats.stat_ct,
340*7c478bd9Sstevel@tonic-gate 				     stats.stat_cr);
341*7c478bd9Sstevel@tonic-gate 		(void) close(fd);
342*7c478bd9Sstevel@tonic-gate 		if (trunc)
343*7c478bd9Sstevel@tonic-gate 		{
344*7c478bd9Sstevel@tonic-gate 			fd = open(sfile, O_RDWR | O_TRUNC, 0600);
345*7c478bd9Sstevel@tonic-gate 			if (fd >= 0)
346*7c478bd9Sstevel@tonic-gate 				(void) close(fd);
347*7c478bd9Sstevel@tonic-gate 		}
348*7c478bd9Sstevel@tonic-gate 	}
349*7c478bd9Sstevel@tonic-gate 	else
350*7c478bd9Sstevel@tonic-gate 	{
351*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
352*7c478bd9Sstevel@tonic-gate 				     "=============================================================");
353*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "========");
354*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "\n");
355*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
356*7c478bd9Sstevel@tonic-gate 				     " T %8ld %10ldK %8ld %10ldK   %6ld  %6ld",
357*7c478bd9Sstevel@tonic-gate 				     frmsgs, frbytes, tomsgs, tobytes, rejmsgs,
358*7c478bd9Sstevel@tonic-gate 				     dismsgs);
359*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
360*7c478bd9Sstevel@tonic-gate 				     "  %6ld", quarmsgs);
361*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "\n");
362*7c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
363*7c478bd9Sstevel@tonic-gate 				     " C %8ld %10s  %8ld %10s    %6ld\n",
364*7c478bd9Sstevel@tonic-gate 				     stats.stat_cf, "", stats.stat_ct, "",
365*7c478bd9Sstevel@tonic-gate 				     stats.stat_cr);
366*7c478bd9Sstevel@tonic-gate 	}
367*7c478bd9Sstevel@tonic-gate 	exit(EX_OK);
368*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
369*7c478bd9Sstevel@tonic-gate 	return EX_OK;
370*7c478bd9Sstevel@tonic-gate }
371