From 58e5acf8f4c27e46e3371f9584fb7583cb4ace12 Mon Sep 17 00:00:00 2001 From: des Date: Sat, 8 Mar 2008 16:55:22 +0000 Subject: [PATCH] Add a -s option which specifies a number of entries to skip. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2572 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishlog/varnishlog.1 | 7 +++++- varnish-cache/include/varnishapi.h | 4 ++-- varnish-cache/lib/libvarnishapi/shmlog.c | 27 +++++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/varnish-cache/bin/varnishlog/varnishlog.1 b/varnish-cache/bin/varnishlog/varnishlog.1 index 58c38cea..1fd2db2c 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.1 +++ b/varnish-cache/bin/varnishlog/varnishlog.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd November 8, 2007 +.Dd March 8, 2008 .Dt VARNISHLOG 1 .Os .Sh NAME @@ -48,6 +48,7 @@ .Op Fl o .Op Fl P Ar file .Op Fl r Ar file +.Op Fl s Ar num .Op Fl V .Op Fl w Ar file .Op Fl X Ar regex @@ -126,6 +127,10 @@ Write the process's PID to the specified Read log entries from .Ar file instead of shared memory. +.It Fl s Ar num +Skip the first +.Ar num +log records. .It Fl V Display the version number and exit. .It Fl w Ar file diff --git a/varnish-cache/include/varnishapi.h b/varnish-cache/include/varnishapi.h index 6249fba6..8edf72d9 100644 --- a/varnish-cache/include/varnishapi.h +++ b/varnish-cache/include/varnishapi.h @@ -44,8 +44,8 @@ int base64_decode(char *d, unsigned dlen, const char *s); typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) #define VSL_S_BACKEND (1 << 1) -#define VSL_ARGS "bCcdI:i:r:X:x:" -#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-r file] [-X regexp] [-x tag]" +#define VSL_ARGS "bCcdI:i:r:s:X:x:" +#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-r file] [-s skip] [-X regexp] [-x tag]" vsl_handler VSL_H_Print; struct VSL_data; struct VSL_data *VSL_New(void); diff --git a/varnish-cache/lib/libvarnishapi/shmlog.c b/varnish-cache/lib/libvarnishapi/shmlog.c index 7311aa9b..d18e79eb 100644 --- a/varnish-cache/lib/libvarnishapi/shmlog.c +++ b/varnish-cache/lib/libvarnishapi/shmlog.c @@ -85,6 +85,8 @@ struct VSL_data { int regflags; regex_t *regincl; regex_t *regexcl; + + unsigned long skip; }; #ifndef MAP_HASSEMAPHORE @@ -292,6 +294,10 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp) default: break; } + if (vd->skip) { + --vd->skip; + continue; + } if (vd->map[p[SHMLOG_TAG]] & M_SELECT) { *pp = p; return (1); @@ -478,6 +484,26 @@ vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg) /*--------------------------------------------------------------------*/ +static int +vsl_s_arg(struct VSL_data *vd, const char *opt) +{ + char *end; + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + if (*opt == '\0') { + fprintf(stderr, "number required for -s\n"); + return (-1); + } + vd->skip = strtoul(opt, &end, 10); + if (*end != '\0') { + fprintf(stderr, "invalid number for -s\n"); + return (-1); + } + return (1); +} + +/*--------------------------------------------------------------------*/ + int VSL_Arg(struct VSL_data *vd, int arg, const char *opt) { @@ -491,6 +517,7 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt) case 'r': return (vsl_r_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); case 'C': vd->regflags = REG_ICASE; return (1); + case 's': return (vsl_s_arg(vd, opt)); default: return (0); } -- 2.39.5