From: phk Date: Wed, 28 Jun 2006 20:58:36 +0000 (+0000) Subject: Use SHMLOG api in libvarnishapi X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30cb66df2971d4876740244ec1879c630117da4c;p=varnish Use SHMLOG api in libvarnishapi git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@260 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishlog/Makefile.am b/varnish-cache/bin/varnishlog/Makefile.am index fbf4bfc6..2ba88928 100644 --- a/varnish-cache/bin/varnishlog/Makefile.am +++ b/varnish-cache/bin/varnishlog/Makefile.am @@ -6,4 +6,4 @@ bin_PROGRAMS = varnishlog varnishlog_SOURCES = varnishlog.c -# varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la +varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index a79e8577..f6079f68 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -9,10 +9,9 @@ #include #include #include -#include -#include -#include +#include "shmlog.h" +#include "varnishapi.h" /* * It would be simpler to use sparse array initialization and put it @@ -32,69 +31,34 @@ static struct tagnames { static const char *tagnames[256]; static struct shmloghead *loghead; -static unsigned char *logstart, *logend; int main(int argc, char **argv) { - int fd; int i; unsigned u; - unsigned startup; - struct shmloghead slh; - unsigned char *p; - - fd = open(SHMLOG_FILENAME, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "Cannot open %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); - exit (1); - } - i = read(fd, &slh, sizeof slh); - if (i != sizeof slh) { - fprintf(stderr, "Cannot read %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); - exit (1); - } - if (slh.magic != SHMLOGHEAD_MAGIC) { - fprintf(stderr, "Wrong magic number in file %s\n", - SHMLOG_FILENAME); - exit (1); - } - - loghead = mmap(NULL, slh.size + sizeof slh, - PROT_READ, MAP_HASSEMAPHORE, fd, 0); - if (loghead == MAP_FAILED) { - fprintf(stderr, "Cannot mmap %s: %s\n", - SHMLOG_FILENAME, strerror(errno)); - exit (1); - } - logstart = (unsigned char *)loghead + loghead->start; - logend = logstart + loghead->size; + unsigned char *p, *q; + loghead = VSL_OpenLog(); + for (i = 0; stagnames[i].tag != SLT_ENDMARKER; i++) tagnames[stagnames[i].tag] = stagnames[i].name; - startup = 1; + q = NULL; + while (VSL_NextLog(loghead, &q) != NULL) + ; while (1) { - p = logstart; - while (1) { - if (*p == SLT_WRAPMARKER) - break; - while (*p == SLT_ENDMARKER) { - fflush(stdout); - sleep(1); - startup = 0; - } - u = (p[2] << 8) | p[3]; - if (!startup) { - printf("%02x %3d %4d %-12s <", - p[0], p[1], u, tagnames[p[0]]); - if (p[1] > 0) - fwrite(p + 4, p[1], 1, stdout); - printf(">\n"); - } - p += p[1] + 4; + p = VSL_NextLog(loghead, &q); + if (p == NULL) { + fflush(stdout); + sleep(1); + continue; } + u = (p[2] << 8) | p[3]; + printf("%02x %3d %4d %-12s <", + p[0], p[1], u, tagnames[p[0]]); + if (p[1] > 0) + fwrite(p + 4, p[1], 1, stdout); + printf(">\n"); } }