From johnl@iecc.com Wed Nov 05 04:10:01 2003 X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil] ["4108" "" "4" "November" "2003" "23:08:30" "-0500" "John R Levine" "johnl@iecc.com" nil "140" "For qmail.org, patch to qmailanalog" "^From:" nil nil "11" nil "For qmail.org, patch to qmailanalog" nil nil nil nil nil nil] nil) Return-Path: Delivered-To: nelson@desk.crynwr.com Received: (qmail 7390 invoked from network); 5 Nov 2003 04:10:01 -0000 Received: from unknown (HELO ns.crynwr.com) (192.203.178.14) by desk.crynwr.com with SMTP; 5 Nov 2003 04:10:01 -0000 Received: (qmail 19093 invoked by uid 500); 5 Nov 2003 04:08:36 -0000 Delivered-To: nelson@crynwr.com Received: (qmail 19089 invoked from network); 5 Nov 2003 04:08:34 -0000 Received: from tom.iecc.com (208.31.42.38) by pdam.crynwr.com with SMTP; 5 Nov 2003 04:08:34 -0000 Received: (qmail 12405 invoked from network); 5 Nov 2003 04:08:30 -0000 Received: (ofmipd 208.31.42.39); 5 Nov 2003 04:08:08 -0000 Message-ID: Cleverness: None detected MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII From: "John R Levine" To: "Russell Nelson" Subject: For qmail.org, patch to qmailanalog Date: 4 Nov 2003 23:08:30 -0500 I'm working on the log analysis part of the book. Dan never updated qmailanalog to handle the date stamps that multilog creates. Here's the patch to do so. The interesting bits are stolen from Russ Alberry's tai64frac which in turn stole them from Dan's tai64ocal. It turns new dates into old dates rather than updating the code to use new dates, because the analysis code is all awk scripts subtracting one timestamp from another to find out how long deliveries took. Yes, I tested it. R's, John ----- snip ----- This small patch modifies the matchup program to handle tai64 format dates. Lines that start with @ have dates translated to the older seconds.nanoseconds format that qmailanalog wants. Lines that don't start with @ are left alone, so that the pending file that matchup writes can be processed properly. John Levine, johnl@iecc.com, Nov 2003 diff -C2 qmailanalog-dist/matchup.c qmailanalog-0.70/matchup.c *** qmailanalog-dist/matchup.c Tue Nov 4 17:50:09 2003 --- qmailanalog-0.70/matchup.c Tue Nov 4 23:01:21 2003 *************** *** 184,187 **** --- 184,228 ---- } + /* turn TAI date into old fashioned date */ + /* dates without @ are left alone */ + + static char datebuf[FMT_ULONG+FMT_ULONG+2]; /* ssssssssss.ffffffffff\n */ + + char * + datize(s) + char *s; + { + int c; + int len; + unsigned long u; + unsigned long seconds = 0; + unsigned long nanoseconds = 0; + + if(*s != '@') return s; + s++; + + while ((c = *s++)) { + u = c - '0'; + if (u >= 10) { + u = c - 'a'; + if (u >= 6) break; + u += 10; + } + seconds <<= 4; + seconds += nanoseconds >> 28; + nanoseconds &= 0xfffffff; + nanoseconds <<= 4; + nanoseconds += u; + } + seconds -= 4611686018427387914ULL; + + len = fmt_ulong(datebuf, seconds); + datebuf[len++] = '.'; + len += fmt_ulong(datebuf+len, nanoseconds); + datebuf[len] = 0; + + return datebuf; + } + stralloc line = {0}; int match; *************** *** 210,214 **** dstart.u[dpos] = pool.len; ! if (!stralloc_cats(&pool,line.s + field[0])) nomem(); if (!stralloc_0(&pool)) nomem(); --- 251,255 ---- dstart.u[dpos] = pool.len; ! if (!stralloc_cats(&pool,datize(line.s + field[0]))) nomem(); if (!stralloc_0(&pool)) nomem(); *************** *** 268,272 **** outs(pool.s + birth.u[mpos]); outs(" "); outs(pool.s + dstart.u[dpos]); ! outs(" "); outs(line.s + field[0]); outs(" "); out(strnum,fmt_ulong(strnum,bytes.u[mpos])); outs(" "); outs(pool.s + sender.u[mpos]); --- 309,313 ---- outs(pool.s + birth.u[mpos]); outs(" "); outs(pool.s + dstart.u[dpos]); ! outs(" "); outs(datize(line.s + field[0])); outs(" "); out(strnum,fmt_ulong(strnum,bytes.u[mpos])); outs(" "); outs(pool.s + sender.u[mpos]); *************** *** 280,284 **** outs(pool.s + dstart.u[dpos]); outs(" "); outs(pool.s + dstart.u[dpos]); ! outs(" "); outs(line.s + field[0]); outs(" 0 ? "); outs(pool.s + dchan.u[dpos]); outs("."); outs(pool.s + drecip.u[dpos]); --- 321,325 ---- outs(pool.s + dstart.u[dpos]); outs(" "); outs(pool.s + dstart.u[dpos]); ! outs(" "); outs(datize(line.s + field[0])); outs(" 0 ? "); outs(pool.s + dchan.u[dpos]); outs("."); outs(pool.s + drecip.u[dpos]); *************** *** 314,318 **** outs("m "); outs(pool.s + birth.u[mpos]); ! outs(" "); outs(line.s + field[0]); outs(" "); out(strnum,fmt_ulong(strnum,bytes.u[mpos])); outs(" "); out(strnum,fmt_ulong(strnum,numk.u[mpos])); --- 355,359 ---- outs("m "); outs(pool.s + birth.u[mpos]); ! outs(" "); outs(datize(line.s + field[0])); outs(" "); out(strnum,fmt_ulong(strnum,bytes.u[mpos])); outs(" "); out(strnum,fmt_ulong(strnum,numk.u[mpos])); *************** *** 345,349 **** birth.u[mpos] = pool.len; ! if (!stralloc_cats(&pool,line.s + field[0])) nomem(); if (!stralloc_0(&pool)) nomem(); --- 386,390 ---- birth.u[mpos] = pool.len; ! if (!stralloc_cats(&pool,datize(line.s + field[0]))) nomem(); if (!stralloc_0(&pool)) nomem();