]> err.no Git - varnish/commitdiff
Use SHMLOG api in libvarnishapi
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 20:58:36 +0000 (20:58 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 28 Jun 2006 20:58:36 +0000 (20:58 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@260 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishlog/Makefile.am
varnish-cache/bin/varnishlog/varnishlog.c

index fbf4bfc66b9898fe77588c22ddea9cff4b9e38d6..2ba88928d0dda3f08e292ade400ad371bc34f59b 100644 (file)
@@ -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 
index a79e85771c5b20978ebc87edeee0613b378288dd..f6079f68281f23dd421b80fde1fb3b56546e5529 100644 (file)
@@ -9,10 +9,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <sys/mman.h>
 
-#include <shmlog.h>
+#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");
        }
 }