122714Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 362532Sbostic * Copyright (c) 1988, 1993 462532Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822714Sdist 922714Sdist #ifndef lint 10*63753Seric static char sccsid[] = "@(#)stats.c 8.2 (Berkeley) 07/11/93"; 1133731Sbostic #endif /* not lint */ 1222714Sdist 134286Seric # include "sendmail.h" 1427681Sbloom # include "mailstats.h" 154286Seric 169383Seric struct statistics Stat; 1724944Seric 18*63753Seric bool GotStats = FALSE; /* set when we have stats to merge */ 19*63753Seric 2024944Seric #define ONE_K 1000 /* one thousand (twenty-four?) */ 2124944Seric #define KBYTES(x) (((x) + (ONE_K - 1)) / ONE_K) 229383Seric /* 239383Seric ** MARKSTATS -- mark statistics 249383Seric */ 259383Seric 269383Seric markstats(e, to) 279383Seric register ENVELOPE *e; 289383Seric register ADDRESS *to; 299383Seric { 309383Seric if (to == NULL) 319383Seric { 3225689Seric if (e->e_from.q_mailer != NULL) 3324945Seric { 3424945Seric Stat.stat_nf[e->e_from.q_mailer->m_mno]++; 3524945Seric Stat.stat_bf[e->e_from.q_mailer->m_mno] += 3655012Seric KBYTES(e->e_msgsize); 3724945Seric } 389383Seric } 399383Seric else 409383Seric { 419383Seric Stat.stat_nt[to->q_mailer->m_mno]++; 4255012Seric Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(e->e_msgsize); 439383Seric } 44*63753Seric GotStats = TRUE; 459383Seric } 469383Seric /* 474286Seric ** POSTSTATS -- post statistics in the statistics file 484286Seric ** 494286Seric ** Parameters: 504286Seric ** sfile -- the name of the statistics file. 514286Seric ** 524286Seric ** Returns: 534286Seric ** none. 544286Seric ** 554286Seric ** Side Effects: 564286Seric ** merges the Stat structure with the sfile file. 574286Seric */ 584286Seric 594286Seric poststats(sfile) 604286Seric char *sfile; 614286Seric { 624286Seric register int fd; 634286Seric struct statistics stat; 6423123Seric extern off_t lseek(); 654286Seric 66*63753Seric if (sfile == NULL || !GotStats) 6723516Seric return; 6823516Seric 694319Seric (void) time(&Stat.stat_itime); 704286Seric Stat.stat_size = sizeof Stat; 714286Seric 724286Seric fd = open(sfile, 2); 734286Seric if (fd < 0) 7411937Seric { 7511937Seric errno = 0; 764286Seric return; 7711937Seric } 784319Seric if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 794286Seric stat.stat_size == sizeof stat) 804286Seric { 814286Seric /* merge current statistics into statfile */ 824286Seric register int i; 834286Seric 844286Seric for (i = 0; i < MAXMAILERS; i++) 854286Seric { 864286Seric stat.stat_nf[i] += Stat.stat_nf[i]; 874286Seric stat.stat_bf[i] += Stat.stat_bf[i]; 884286Seric stat.stat_nt[i] += Stat.stat_nt[i]; 894286Seric stat.stat_bt[i] += Stat.stat_bt[i]; 904286Seric } 914286Seric } 924286Seric else 9316887Seric bcopy((char *) &Stat, (char *) &stat, sizeof stat); 944286Seric 954286Seric /* write out results */ 9623123Seric (void) lseek(fd, (off_t) 0, 0); 974319Seric (void) write(fd, (char *) &stat, sizeof stat); 984319Seric (void) close(fd); 99*63753Seric 100*63753Seric /* clear the structure to avoid future disappointment */ 101*63753Seric bzero(&Stat, sizeof stat); 102*63753Seric GotStats = FALSE; 1034286Seric } 104