From: phk Date: Fri, 21 Jul 2006 15:25:09 +0000 (+0000) Subject: Work on logtailer api a bit: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=898d3815038667eb5405997ad77fb66a1889bd1f;p=varnish Work on logtailer api a bit: By default, start at the last entry in shared memory. To dump the entire segment from the start, specify '-d' option. Terminate programs when '-r $file' reaches EOF git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@539 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index 11049dec..2ccce6c7 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -240,8 +240,10 @@ main(int argc, char **argv) v = 0; while (1) { - p = VSL_NextLog(vd); - if (p == NULL) { + i = VSL_NextLog(vd, &p); + if (i < 0) + break; + if (i == 0) { if (w_opt == NULL) { if (o_flag && ++v == 100) clean_order(); diff --git a/varnish-cache/bin/varnishtop/varnishtop.c b/varnish-cache/bin/varnishtop/varnishtop.c index a1886a1e..4e9c5d61 100644 --- a/varnish-cache/bin/varnishtop/varnishtop.c +++ b/varnish-cache/bin/varnishtop/varnishtop.c @@ -110,8 +110,10 @@ main(int argc, char **argv) initscr(); v = 0; while (1) { - p = VSL_NextLog(vd); - if (p == NULL) { + i = VSL_NextLog(vd, &p); + if (i < 0) + break; + if (i == 0) { upd(); usleep(50000); continue; diff --git a/varnish-cache/include/varnishapi.h b/varnish-cache/include/varnishapi.h index a8721e92..747315ce 100644 --- a/varnish-cache/include/varnishapi.h +++ b/varnish-cache/include/varnishapi.h @@ -8,11 +8,11 @@ #define V_DEAD __attribute__ ((noreturn)) /* shmlog.c */ -#define VSL_ARGS "bcr:i:x:CI:X:" +#define VSL_ARGS "bcdr:i:x:CI:X:" struct VSL_data; struct VSL_data *VSL_New(void); int VSL_OpenLog(struct VSL_data *vd); -unsigned char *VSL_NextLog(struct VSL_data *lh); +int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); struct varnish_stats *VSL_OpenStats(void); const char *VSL_tags[256]; diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index 12657f7d..a2927152 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -26,6 +26,7 @@ struct VSL_data { int b_opt; int c_opt; + int d_opt; int ix_opt; unsigned char supr[256]; @@ -44,6 +45,7 @@ struct VSL_data { static int vsl_fd; static struct shmloghead *vsl_lh; +static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp); /*--------------------------------------------------------------------*/ @@ -107,7 +109,7 @@ VSL_New(void) int VSL_OpenLog(struct VSL_data *vd) { - + unsigned char *p; if (vd->fi != NULL) return (0); @@ -119,13 +121,17 @@ VSL_OpenLog(struct VSL_data *vd) vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start; vd->logend = vd->logstart + vsl_lh->size; vd->ptr = vd->logstart; + + if (!vd->d_opt) + while (vsl_nextlog(vd, &p) == 1) + continue; return (0); } /*--------------------------------------------------------------------*/ -static unsigned char * -vsl_nextlog(struct VSL_data *vd) +static int +vsl_nextlog(struct VSL_data *vd, unsigned char **pp) { unsigned char *p; int i; @@ -133,13 +139,14 @@ vsl_nextlog(struct VSL_data *vd) if (vd->fi != NULL) { i = fread(vd->rbuf, 4, 1, vd->fi); if (i != 1) - return (NULL); + return (-1); if (vd->rbuf[1] > 0) { i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi); if (i != 1) - return (NULL); + return (-1); } - return (vd->rbuf); + *pp = vd->rbuf; + return (1); } p = vd->ptr; @@ -150,15 +157,16 @@ vsl_nextlog(struct VSL_data *vd) } if (*p == SLT_ENDMARKER) { vd->ptr = p; - return (NULL); + return (0); } vd->ptr = p + p[1] + 4; - return (p); + *pp = p; + return (1); } } -unsigned char * -VSL_NextLog(struct VSL_data *vd) +int +VSL_NextLog(struct VSL_data *vd, unsigned char **pp) { unsigned char *p; regmatch_t rm; @@ -166,9 +174,9 @@ VSL_NextLog(struct VSL_data *vd) int i; while (1) { - p = vsl_nextlog(vd); - if (p == NULL) - return (p); + i = vsl_nextlog(vd, &p); + if (i != 1) + return (i); u = (p[2] << 8) | p[3]; switch(p[0]) { case SLT_SessionOpen: @@ -200,7 +208,8 @@ VSL_NextLog(struct VSL_data *vd) if (i != REG_NOMATCH) continue; } - return (p); + *pp = p; + return (1); } } @@ -310,6 +319,7 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt) switch (arg) { case 'b': vd->b_opt = !vd->b_opt; return (1); case 'c': vd->c_opt = !vd->c_opt; return (1); + case 'd': vd->d_opt = !vd->d_opt; return (1); case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg)); case 'r': return (vsl_r_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));