|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Eric P. Allman
3: * Copyright (c) 1988 Regents of the University of California.
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms are permitted provided
7: * that: (1) source distributions retain this entire copyright notice and
8: * comment, and (2) distributions including binaries display the following
9: * acknowledgement: ``This product includes software developed by the
10: * University of California, Berkeley and its contributors'' in the
11: * documentation or other materials provided with the distribution and in
12: * all advertising materials mentioning features or use of this software.
13: * Neither the name of the University nor the names of its contributors may
14: * be used to endorse or promote products derived from this software without
15: * specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: */
20:
21: #ifndef lint
22: static char sccsid[] = "@(#)stats.c 5.11 (Berkeley) 6/1/90";
23: #endif /* not lint */
24:
25: # include "sendmail.h"
26: # include "mailstats.h"
27:
28: struct statistics Stat;
29:
30: #define ONE_K 1000 /* one thousand (twenty-four?) */
31: #define KBYTES(x) (((x) + (ONE_K - 1)) / ONE_K)
32: /*
33: ** MARKSTATS -- mark statistics
34: */
35:
36: markstats(e, to)
37: register ENVELOPE *e;
38: register ADDRESS *to;
39: {
40: if (to == NULL)
41: {
42: if (e->e_from.q_mailer != NULL)
43: {
44: Stat.stat_nf[e->e_from.q_mailer->m_mno]++;
45: Stat.stat_bf[e->e_from.q_mailer->m_mno] +=
46: KBYTES(CurEnv->e_msgsize);
47: }
48: }
49: else
50: {
51: Stat.stat_nt[to->q_mailer->m_mno]++;
52: Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize);
53: }
54: }
55: /*
56: ** POSTSTATS -- post statistics in the statistics file
57: **
58: ** Parameters:
59: ** sfile -- the name of the statistics file.
60: **
61: ** Returns:
62: ** none.
63: **
64: ** Side Effects:
65: ** merges the Stat structure with the sfile file.
66: */
67:
68: poststats(sfile)
69: char *sfile;
70: {
71: register int fd;
72: struct statistics stat;
73: extern off_t lseek();
74:
75: if (sfile == NULL)
76: return;
77:
78: (void) time(&Stat.stat_itime);
79: Stat.stat_size = sizeof Stat;
80:
81: fd = open(sfile, 2);
82: if (fd < 0)
83: {
84: errno = 0;
85: return;
86: }
87: if (read(fd, (char *) &stat, sizeof stat) == sizeof stat &&
88: stat.stat_size == sizeof stat)
89: {
90: /* merge current statistics into statfile */
91: register int i;
92:
93: for (i = 0; i < MAXMAILERS; i++)
94: {
95: stat.stat_nf[i] += Stat.stat_nf[i];
96: stat.stat_bf[i] += Stat.stat_bf[i];
97: stat.stat_nt[i] += Stat.stat_nt[i];
98: stat.stat_bt[i] += Stat.stat_bt[i];
99: }
100: }
101: else
102: bcopy((char *) &Stat, (char *) &stat, sizeof stat);
103:
104: /* write out results */
105: (void) lseek(fd, (off_t) 0, 0);
106: (void) write(fd, (char *) &stat, sizeof stat);
107: (void) close(fd);
108: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.