r539 - in trunk/varnish-cache: bin/varnishlog bin/varnishtop include lib/libvarnishapi

phk at projects.linpro.no phk at projects.linpro.no
Fri Jul 21 17:25:10 CEST 2006


Author: phk
Date: 2006-07-21 17:25:09 +0200 (Fri, 21 Jul 2006)
New Revision: 539

Modified:
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/bin/varnishtop/varnishtop.c
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Work on logtailer api a bit:

By default, start at the last entry in shared memory.  To dump the
entire segment from the start, specify '-d' option.

Terminate programs when '-r $file' reaches EOF



Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-21 12:18:01 UTC (rev 538)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-07-21 15:25:09 UTC (rev 539)
@@ -240,8 +240,10 @@
 	v = 0;
 
 	while (1) {
-		p = VSL_NextLog(vd);
-		if (p == NULL) {
+		i = VSL_NextLog(vd, &p);
+		if (i < 0)
+			break;
+		if (i == 0) {
 			if (w_opt == NULL) {
 				if (o_flag && ++v == 100)
 					clean_order();

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c	2006-07-21 12:18:01 UTC (rev 538)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c	2006-07-21 15:25:09 UTC (rev 539)
@@ -110,8 +110,10 @@
 	initscr();
 	v = 0;
 	while (1) {
-		p = VSL_NextLog(vd);
-		if (p == NULL) {
+		i = VSL_NextLog(vd, &p);
+		if (i < 0)
+			break;
+		if (i == 0) {
 			upd();
 			usleep(50000);
 			continue;

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2006-07-21 12:18:01 UTC (rev 538)
+++ trunk/varnish-cache/include/varnishapi.h	2006-07-21 15:25:09 UTC (rev 539)
@@ -8,11 +8,11 @@
 #define V_DEAD __attribute__ ((noreturn))
 
 /* shmlog.c */
-#define VSL_ARGS	"bcr:i:x:CI:X:"
+#define VSL_ARGS	"bcdr:i:x:CI:X:"
 struct VSL_data;
 struct VSL_data *VSL_New(void);
 int VSL_OpenLog(struct VSL_data *vd);
-unsigned char *VSL_NextLog(struct VSL_data *lh);
+int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
 int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
 struct varnish_stats *VSL_OpenStats(void);
 const char *VSL_tags[256];

Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2006-07-21 12:18:01 UTC (rev 538)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2006-07-21 15:25:09 UTC (rev 539)
@@ -26,6 +26,7 @@
 
 	int			b_opt;
 	int			c_opt;
+	int			d_opt;
 
 	int			ix_opt;
 	unsigned char 		supr[256];
@@ -44,6 +45,7 @@
 static int vsl_fd;
 static struct shmloghead *vsl_lh;
 
+static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp);
 
 /*--------------------------------------------------------------------*/
 
@@ -107,8 +109,8 @@
 int
 VSL_OpenLog(struct VSL_data *vd)
 {
+	unsigned char *p;
 
-
 	if (vd->fi != NULL)
 		return (0);
 
@@ -119,13 +121,17 @@
 	vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start;
 	vd->logend = vd->logstart + vsl_lh->size;
 	vd->ptr = vd->logstart;
+
+	if (!vd->d_opt)
+		while (vsl_nextlog(vd, &p) == 1)
+			continue;
 	return (0);
 }
 
 /*--------------------------------------------------------------------*/
 
-static unsigned char *
-vsl_nextlog(struct VSL_data *vd)
+static int
+vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
 {
 	unsigned char *p;
 	int i;
@@ -133,13 +139,14 @@
 	if (vd->fi != NULL) {
 		i = fread(vd->rbuf, 4, 1, vd->fi);
 		if (i != 1)
-			return (NULL);
+			return (-1);
 		if (vd->rbuf[1] > 0) {
 			i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi);
 			if (i != 1)
-				return (NULL);
+				return (-1);
 		}
-		return (vd->rbuf);
+		*pp = vd->rbuf;
+		return (1);
 	}
 
 	p = vd->ptr;
@@ -150,15 +157,16 @@
 		}
 		if (*p == SLT_ENDMARKER) {
 			vd->ptr = p;
-			return (NULL);
+			return (0);
 		}
 		vd->ptr = p + p[1] + 4;
-		return (p);
+		*pp = p;
+		return (1);
 	}
 }
 
-unsigned char *
-VSL_NextLog(struct VSL_data *vd)
+int
+VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
 {
 	unsigned char *p;
 	regmatch_t rm;
@@ -166,9 +174,9 @@
 	int i;
 
 	while (1) {
-		p = vsl_nextlog(vd);
-		if (p == NULL)
-			return (p);
+		i = vsl_nextlog(vd, &p);
+		if (i != 1)
+			return (i);
 		u = (p[2] << 8) | p[3];
 		switch(p[0]) {
 		case SLT_SessionOpen:
@@ -200,7 +208,8 @@
 			if (i != REG_NOMATCH)
 				continue;
 		}
-		return (p);
+		*pp = p;
+		return (1);
 	}
 }
 
@@ -310,6 +319,7 @@
 	switch (arg) {
 	case 'b': vd->b_opt = !vd->b_opt; return (1);
 	case 'c': vd->c_opt = !vd->c_opt; return (1);
+	case 'd': vd->d_opt = !vd->d_opt; return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
 	case 'r': return (vsl_r_arg(vd, opt));
 	case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));




More information about the varnish-commit mailing list