122714Sdist /* 2*34921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 633731Sbostic * Redistribution and use in source and binary forms are permitted 7*34921Sbostic * provided that the above copyright notice and this paragraph are 8*34921Sbostic * duplicated in all such forms and that any documentation, 9*34921Sbostic * advertising materials, and other materials related to such 10*34921Sbostic * distribution and use acknowledge that the software was developed 11*34921Sbostic * by the University of California, Berkeley. The name of the 12*34921Sbostic * University may not be used to endorse or promote products derived 13*34921Sbostic * from this software without specific prior written permission. 14*34921Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15*34921Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16*34921Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1733731Sbostic */ 1822714Sdist 1922714Sdist #ifndef lint 20*34921Sbostic static char sccsid[] = "@(#)stats.c 5.10 (Berkeley) 06/30/88"; 2133731Sbostic #endif /* not lint */ 2222714Sdist 234286Seric # include "sendmail.h" 2427681Sbloom # include "mailstats.h" 254286Seric 269383Seric struct statistics Stat; 2724944Seric 2824944Seric #define ONE_K 1000 /* one thousand (twenty-four?) */ 2924944Seric #define KBYTES(x) (((x) + (ONE_K - 1)) / ONE_K) 309383Seric /* 319383Seric ** MARKSTATS -- mark statistics 329383Seric */ 339383Seric 349383Seric markstats(e, to) 359383Seric register ENVELOPE *e; 369383Seric register ADDRESS *to; 379383Seric { 389383Seric if (to == NULL) 399383Seric { 4025689Seric if (e->e_from.q_mailer != NULL) 4124945Seric { 4224945Seric Stat.stat_nf[e->e_from.q_mailer->m_mno]++; 4324945Seric Stat.stat_bf[e->e_from.q_mailer->m_mno] += 4424945Seric KBYTES(CurEnv->e_msgsize); 4524945Seric } 469383Seric } 479383Seric else 489383Seric { 499383Seric Stat.stat_nt[to->q_mailer->m_mno]++; 5024944Seric Stat.stat_bt[to->q_mailer->m_mno] += KBYTES(CurEnv->e_msgsize); 519383Seric } 529383Seric } 539383Seric /* 544286Seric ** POSTSTATS -- post statistics in the statistics file 554286Seric ** 564286Seric ** Parameters: 574286Seric ** sfile -- the name of the statistics file. 584286Seric ** 594286Seric ** Returns: 604286Seric ** none. 614286Seric ** 624286Seric ** Side Effects: 634286Seric ** merges the Stat structure with the sfile file. 644286Seric */ 654286Seric 664286Seric poststats(sfile) 674286Seric char *sfile; 684286Seric { 694286Seric register int fd; 704286Seric struct statistics stat; 7123123Seric extern off_t lseek(); 724286Seric 7323516Seric if (sfile == NULL) 7423516Seric return; 7523516Seric 764319Seric (void) time(&Stat.stat_itime); 774286Seric Stat.stat_size = sizeof Stat; 784286Seric 794286Seric fd = open(sfile, 2); 804286Seric if (fd < 0) 8111937Seric { 8211937Seric errno = 0; 834286Seric return; 8411937Seric } 854319Seric if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 864286Seric stat.stat_size == sizeof stat) 874286Seric { 884286Seric /* merge current statistics into statfile */ 894286Seric register int i; 904286Seric 914286Seric for (i = 0; i < MAXMAILERS; i++) 924286Seric { 934286Seric stat.stat_nf[i] += Stat.stat_nf[i]; 944286Seric stat.stat_bf[i] += Stat.stat_bf[i]; 954286Seric stat.stat_nt[i] += Stat.stat_nt[i]; 964286Seric stat.stat_bt[i] += Stat.stat_bt[i]; 974286Seric } 984286Seric } 994286Seric else 10016887Seric bcopy((char *) &Stat, (char *) &stat, sizeof stat); 1014286Seric 1024286Seric /* write out results */ 10323123Seric (void) lseek(fd, (off_t) 0, 0); 1044319Seric (void) write(fd, (char *) &stat, sizeof stat); 1054319Seric (void) close(fd); 1064286Seric } 107