1 /* 2 ** Sendmail 3 ** Copyright (c) 1983 Eric P. Allman 4 ** Berkeley, California 5 ** 6 ** Copyright (c) 1983 Regents of the University of California. 7 ** All rights reserved. The Berkeley software License Agreement 8 ** specifies the terms and conditions for redistribution. 9 */ 10 11 #ifndef lint 12 static char SccsId[] = "@(#)stats.c 5.4.1.1 (Berkeley) 09/19/85"; 13 #endif not lint 14 15 # include "sendmail.h" 16 17 /* 18 ** Statistics structure. 19 */ 20 21 struct statistics 22 { 23 time_t stat_itime; /* file initialization time */ 24 short stat_size; /* size of this structure */ 25 long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 26 long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 27 long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 28 long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 29 }; 30 31 struct statistics Stat; 32 33 #define ONE_K 1000 /* one thousand (twenty-four?) */ 34 #define KBYTES(x) (((x) + (ONE_K - 1)) / ONE_K) 35 /* 36 ** MARKSTATS -- mark statistics 37 */ 38 39 markstats(e, to) 40 register ENVELOPE *e; 41 register ADDRESS *to; 42 { 43 if (to == NULL) 44 { 45 Stat.stat_nf[e->e_from.q_mailer->m_mno]++; 46 Stat.stat_bf[e->e_from.q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize); 47 } 48 else 49 { 50 Stat.stat_nt[to->q_mailer->m_mno]++; 51 Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize); 52 } 53 } 54 /* 55 ** POSTSTATS -- post statistics in the statistics file 56 ** 57 ** Parameters: 58 ** sfile -- the name of the statistics file. 59 ** 60 ** Returns: 61 ** none. 62 ** 63 ** Side Effects: 64 ** merges the Stat structure with the sfile file. 65 */ 66 67 poststats(sfile) 68 char *sfile; 69 { 70 register int fd; 71 struct statistics stat; 72 extern off_t lseek(); 73 74 if (sfile == NULL) 75 return; 76 77 (void) time(&Stat.stat_itime); 78 Stat.stat_size = sizeof Stat; 79 80 fd = open(sfile, 2); 81 if (fd < 0) 82 { 83 errno = 0; 84 return; 85 } 86 if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 87 stat.stat_size == sizeof stat) 88 { 89 /* merge current statistics into statfile */ 90 register int i; 91 92 for (i = 0; i < MAXMAILERS; i++) 93 { 94 stat.stat_nf[i] += Stat.stat_nf[i]; 95 stat.stat_bf[i] += Stat.stat_bf[i]; 96 stat.stat_nt[i] += Stat.stat_nt[i]; 97 stat.stat_bt[i] += Stat.stat_bt[i]; 98 } 99 } 100 else 101 bcopy((char *) &Stat, (char *) &stat, sizeof stat); 102 103 /* write out results */ 104 (void) lseek(fd, (off_t) 0, 0); 105 (void) write(fd, (char *) &stat, sizeof stat); 106 (void) close(fd); 107 } 108