1 # include "sendmail.h" 2 3 SCCSID(@(#)stats.c 3.4 12/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 27 (void) time(&Stat.stat_itime); 28 Stat.stat_size = sizeof Stat; 29 30 fd = open(sfile, 2); 31 if (fd < 0) 32 return; 33 if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 34 stat.stat_size == sizeof stat) 35 { 36 /* merge current statistics into statfile */ 37 register int i; 38 39 for (i = 0; i < MAXMAILERS; i++) 40 { 41 stat.stat_nf[i] += Stat.stat_nf[i]; 42 stat.stat_bf[i] += Stat.stat_bf[i]; 43 stat.stat_nt[i] += Stat.stat_nt[i]; 44 stat.stat_bt[i] += Stat.stat_bt[i]; 45 } 46 } 47 else 48 bmove((char *) &Stat, (char *) &stat, sizeof stat); 49 50 /* write out results */ 51 (void) lseek(fd, 0L, 0); 52 (void) write(fd, (char *) &stat, sizeof stat); 53 (void) close(fd); 54 } 55 /* 56 ** KBYTES -- given a number, returns the number of Kbytes. 57 ** 58 ** Used in statistics gathering of message sizes to try to avoid 59 ** wraparound (at least for a while.....) 60 ** 61 ** Parameters: 62 ** bytes -- actual number of bytes. 63 ** 64 ** Returns: 65 ** number of kbytes. 66 ** 67 ** Side Effects: 68 ** none. 69 ** 70 ** Notes: 71 ** This function is actually a ceiling function to 72 ** the nearest K. 73 ** Honestly folks, floating point might be better. 74 ** Or perhaps a "statistical" log method. 75 */ 76 77 long 78 kbytes(bytes) 79 long bytes; 80 { 81 return ((bytes + 999) / 1000); 82 } 83