home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / stats.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-24  |  2.7 KB  |  108 lines

  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. static char  rcsid[] = "@(#)$Id: stats.c,v 5.11.0.5 1991/06/24 20:27:43 paul Exp $";
  24. #endif /* not lint */
  25.  
  26. # include "sendmail.h"
  27. # include "mailstats.h"
  28.  
  29. struct statistics    Stat;
  30.  
  31. /*
  32. **  MARKSTATS -- mark statistics
  33. */
  34.  
  35. void
  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] += CurEnv->e_msgsize;
  46.         }
  47.     }
  48.     else
  49.     {
  50.         Stat.stat_nt[to->q_mailer->m_mno]++;
  51.         Stat.stat_bt[to->q_mailer->m_mno] += 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. void
  68. poststats(sfile)
  69.     char *sfile;
  70. {
  71.     register int fd;
  72.     struct statistics stat;
  73.  
  74.     if (sfile == NULL)
  75.         return;
  76.  
  77.     (void) time((TIME_TYPE *) &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.