From 792e2ab53020ade1a346ec5dfa4c3c0b8a772e46 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 11 Jul 2006 11:36:14 +0000 Subject: [PATCH] Add -b[ackend] and -c[lient] generic options to logtailers git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@422 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/varnishapi.h | 2 +- varnish-cache/lib/libvarnishapi/shmlog.c | 27 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/varnish-cache/include/varnishapi.h b/varnish-cache/include/varnishapi.h index b57bb78a..a8721e92 100644 --- a/varnish-cache/include/varnishapi.h +++ b/varnish-cache/include/varnishapi.h @@ -8,7 +8,7 @@ #define V_DEAD __attribute__ ((noreturn)) /* shmlog.c */ -#define VSL_ARGS "r:i:x:CI:X:" +#define VSL_ARGS "bcr:i:x:CI:X:" struct VSL_data; struct VSL_data *VSL_New(void); int VSL_OpenLog(struct VSL_data *vd); diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index ef519284..28531ee7 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -24,9 +24,14 @@ struct VSL_data { FILE *fi; unsigned char rbuf[4 + 255 + 1]; + int b_opt; + int c_opt; + int ix_opt; unsigned char supr[256]; + unsigned char dir[65536]; + int regflags; regex_t *regincl; regex_t *regexcl; @@ -39,6 +44,7 @@ struct VSL_data { static int vsl_fd; static struct shmloghead *vsl_lh; + /*--------------------------------------------------------------------*/ const char *VSL_tags[256] = { @@ -102,6 +108,9 @@ int VSL_OpenLog(struct VSL_data *vd) { + if (!vd->b_opt && !vd->c_opt) + vd->b_opt = vd->c_opt = 1; + if (vd->fi != NULL) return (0); @@ -155,14 +164,30 @@ VSL_NextLog(struct VSL_data *vd) { unsigned char *p; regmatch_t rm; + unsigned u; int i; while (1) { p = vsl_nextlog(vd); if (p == NULL) return (p); + u = (p[2] << 8) | p[3]; + switch(p[0]) { + case SLT_SessionOpen: + vd->dir[u] = 1; + break; + case SLT_BackendOpen: + vd->dir[u] = 2; + break; + default: + break; + } if (vd->supr[p[0]]) continue; + if (vd->b_opt && vd->dir[u] == 1) + continue; + if (vd->c_opt && vd->dir[u] == 2) + continue; if (vd->regincl != NULL) { rm.rm_so = 0; rm.rm_eo = p[1]; @@ -285,6 +310,8 @@ int 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 '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)); -- 2.39.5