r261 - trunk/varnish-cache/bin/varnishstat

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 28 23:03:47 CEST 2006


Author: phk
Date: 2006-06-28 23:03:47 +0200 (Wed, 28 Jun 2006)
New Revision: 261

Modified:
   trunk/varnish-cache/bin/varnishstat/Makefile.am
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
Log:
Use shmlog api from libvarnishapi


Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishstat/Makefile.am	2006-06-28 20:58:36 UTC (rev 260)
+++ trunk/varnish-cache/bin/varnishstat/Makefile.am	2006-06-28 21:03:47 UTC (rev 261)
@@ -6,5 +6,6 @@
 
 varnishstat_SOURCES = varnishstat.c
 
-varnishstat_LDADD = -lcurses
-# varnishlog_LDADD = $(top_builddir)/lib/libvarnishapi/libvarnishapi.la 
+varnishstat_LDADD = \
+	-lcurses \
+	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la 

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-06-28 20:58:36 UTC (rev 260)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2006-06-28 21:03:47 UTC (rev 261)
@@ -9,51 +9,23 @@
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <curses.h>
-#include <sys/mman.h>
 
-#include <shmlog.h>
+#include "shmlog.h"
+#include "varnishapi.h"
 
-static struct shmloghead *loghead;
-
 int
 main(int argc, char **argv)
 {
-	int fd;
-	int i, c;
-	struct shmloghead slh;
+	int c;
+	struct shmloghead *lh;
 	struct varnish_stats *VSL_stats;
 	int c_flag = 0;
 
-	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);
-	}
+	lh = VSL_OpenLog();
 
-	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);
-	}
+	VSL_stats = &lh->stats;
 
-	VSL_stats = &loghead->stats;
-
 	while ((c = getopt(argc, argv, "c")) != -1) {
 		switch (c) {
 		case 'c':




More information about the varnish-commit mailing list