1 # include "sendmail.h" 2 3 static char SccsId[] = "@(#)stats.c 3.2 09/06/81"; 4 5 /* 6 ** POSTSTATS -- post statistics in the statistics file 7 ** 8 ** Parameters: 9 ** sfile -- the name of the statistics file. 10 ** 11 ** Returns: 12 ** none. 13 ** 14 ** Side Effects: 15 ** merges the Stat structure with the sfile file. 16 */ 17 18 struct statistics Stat; 19 20 poststats(sfile) 21 char *sfile; 22 { 23 register int fd; 24 struct statistics stat; 25 extern long lseek(); 26 extern long time(); 27 28 (void) time(&Stat.stat_itime); 29 Stat.stat_size = sizeof Stat; 30 31 fd = open(sfile, 2); 32 if (fd < 0) 33 return; 34 if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 35 stat.stat_size == sizeof stat) 36 { 37 /* merge current statistics into statfile */ 38 register int i; 39 40 for (i = 0; i < MAXMAILERS; i++) 41 { 42 stat.stat_nf[i] += Stat.stat_nf[i]; 43 stat.stat_bf[i] += Stat.stat_bf[i]; 44 stat.stat_nt[i] += Stat.stat_nt[i]; 45 stat.stat_bt[i] += Stat.stat_bt[i]; 46 } 47 } 48 else 49 bmove((char *) &Stat, (char *) &stat, sizeof stat); 50 51 /* write out results */ 52 (void) lseek(fd, 0L, 0); 53 (void) write(fd, (char *) &stat, sizeof stat); 54 (void) close(fd); 55 } 56 /* 57 ** KBYTES -- given a number, returns the number of Kbytes. 58 ** 59 ** Used in statistics gathering of message sizes to try to avoid 60 ** wraparound (at least for a while.....) 61 ** 62 ** Parameters: 63 ** bytes -- actual number of bytes. 64 ** 65 ** Returns: 66 ** number of kbytes. 67 ** 68 ** Side Effects: 69 ** none. 70 ** 71 ** Notes: 72 ** This function is actually a ceiling function to 73 ** the nearest K. 74 ** Honestly folks, floating point might be better. 75 ** Or perhaps a "statistical" log method. 76 */ 77 78 long 79 kbytes(bytes) 80 long bytes; 81 { 82 return ((bytes + 999) / 1000); 83 } 84