r260 - trunk/varnish-cache/bin/varnishlog

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 28 22:58:36 CEST 2006


Author: phk
Date: 2006-06-28 22:58:36 +0200 (Wed, 28 Jun 2006)
New Revision: 260

Modified:
   trunk/varnish-cache/bin/varnishlog/Makefile.am
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
Log:
Use SHMLOG api in libvarnishapi


Modified: trunk/varnish-cache/bin/varnishlog/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishlog/Makefile.am	2006-06-28 20:58:03 UTC (rev 259)
+++ trunk/varnish-cache/bin/varnishlog/Makefile.am	2006-06-28 20:58:36 UTC (rev 260)
@@ -6,4 +6,4 @@
 
 varnishlog_SOURCES = varnishlog.c
 
-# varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la 
+varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la 

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-06-28 20:58:03 UTC (rev 259)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-06-28 20:58:36 UTC (rev 260)
@@ -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 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;
+	unsigned char *p, *q;
 
-	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;
-
+	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");
 	}
 }




More information about the varnish-commit mailing list