Commit | Line | Data |
---|---|---|
b2a81223 | 1 | /* |
dc45ba8c | 2 | * Copyright (c) 1983 Eric P. Allman |
bee79b64 KB |
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 | |
dc45ba8c KB |
7 | * provided that the above copyright notice and this paragraph are |
8 | * duplicated in all such forms and that any documentation, | |
9 | * advertising materials, and other materials related to such | |
10 | * distribution and use acknowledge that the software was developed | |
11 | * by the University of California, Berkeley. The name of the | |
12 | * University may not be used to endorse or promote products derived | |
13 | * from this software without specific prior written permission. | |
14 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
15 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
16 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
bee79b64 | 17 | */ |
b2a81223 DF |
18 | |
19 | #ifndef lint | |
ca67e7b4 | 20 | static char sccsid[] = "@(#)stats.c 5.10 (Berkeley) 6/30/88"; |
bee79b64 | 21 | #endif /* not lint */ |
b2a81223 | 22 | |
334bcb35 | 23 | # include "sendmail.h" |
13083572 | 24 | # include "mailstats.h" |
7338e3d4 EA |
25 | |
26 | struct statistics Stat; | |
2e3062fe EA |
27 | |
28 | #define ONE_K 1000 /* one thousand (twenty-four?) */ | |
29 | #define KBYTES(x) (((x) + (ONE_K - 1)) / ONE_K) | |
7338e3d4 EA |
30 | \f/* |
31 | ** MARKSTATS -- mark statistics | |
32 | */ | |
33 | ||
34 | markstats(e, to) | |
35 | register ENVELOPE *e; | |
36 | register ADDRESS *to; | |
37 | { | |
38 | if (to == NULL) | |
39 | { | |
a1a07282 | 40 | if (e->e_from.q_mailer != NULL) |
189a3471 MAN |
41 | { |
42 | Stat.stat_nf[e->e_from.q_mailer->m_mno]++; | |
43 | Stat.stat_bf[e->e_from.q_mailer->m_mno] += | |
650a0daf | 44 | KBYTES(CurEnv->e_msgsize); |
189a3471 | 45 | } |
7338e3d4 EA |
46 | } |
47 | else | |
48 | { | |
49 | Stat.stat_nt[to->q_mailer->m_mno]++; | |
2e3062fe | 50 | Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize); |
7338e3d4 EA |
51 | } |
52 | } | |
53 | \f/* | |
334bcb35 EA |
54 | ** POSTSTATS -- post statistics in the statistics file |
55 | ** | |
56 | ** Parameters: | |
57 | ** sfile -- the name of the statistics file. | |
58 | ** | |
59 | ** Returns: | |
60 | ** none. | |
61 | ** | |
62 | ** Side Effects: | |
63 | ** merges the Stat structure with the sfile file. | |
64 | */ | |
65 | ||
334bcb35 EA |
66 | poststats(sfile) |
67 | char *sfile; | |
68 | { | |
69 | register int fd; | |
70 | struct statistics stat; | |
17a67c62 | 71 | extern off_t lseek(); |
334bcb35 | 72 | |
666b39ad EA |
73 | if (sfile == NULL) |
74 | return; | |
75 | ||
74c5fe7c | 76 | (void) time(&Stat.stat_itime); |
334bcb35 EA |
77 | Stat.stat_size = sizeof Stat; |
78 | ||
79 | fd = open(sfile, 2); | |
80 | if (fd < 0) | |
70faa7c8 EA |
81 | { |
82 | errno = 0; | |
334bcb35 | 83 | return; |
70faa7c8 | 84 | } |
74c5fe7c | 85 | if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && |
334bcb35 EA |
86 | stat.stat_size == sizeof stat) |
87 | { | |
88 | /* merge current statistics into statfile */ | |
89 | register int i; | |
90 | ||
91 | for (i = 0; i < MAXMAILERS; i++) | |
92 | { | |
93 | stat.stat_nf[i] += Stat.stat_nf[i]; | |
94 | stat.stat_bf[i] += Stat.stat_bf[i]; | |
95 | stat.stat_nt[i] += Stat.stat_nt[i]; | |
96 | stat.stat_bt[i] += Stat.stat_bt[i]; | |
97 | } | |
98 | } | |
99 | else | |
83f674d8 | 100 | bcopy((char *) &Stat, (char *) &stat, sizeof stat); |
334bcb35 EA |
101 | |
102 | /* write out results */ | |
17a67c62 | 103 | (void) lseek(fd, (off_t) 0, 0); |
74c5fe7c EA |
104 | (void) write(fd, (char *) &stat, sizeof stat); |
105 | (void) close(fd); | |
334bcb35 | 106 | } |