r4807 - in trunk/varnish-cache: include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Mon May 17 22:10:29 CEST 2010


Author: phk
Date: 2010-05-17 22:10:28 +0200 (Mon, 17 May 2010)
New Revision: 4807

Modified:
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/vsl.c
   trunk/varnish-cache/lib/libvarnishapi/vsl.h
Log:
Expose VSL_Find_Alloc()

Properly handle the case where the looked for allocation is not found.



Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-05-17 20:09:45 UTC (rev 4806)
+++ trunk/varnish-cache/include/varnishapi.h	2010-05-17 20:10:28 UTC (rev 4807)
@@ -62,5 +62,8 @@
 struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
 const char *VSL_Name(struct VSL_data *vd);
 extern const char *VSL_tags[256];
+void *VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
+    unsigned *lenp);
 
+
 #endif

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-05-17 20:09:45 UTC (rev 4806)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-05-17 20:10:28 UTC (rev 4807)
@@ -144,6 +144,7 @@
 		    logname, strerror(errno));
 		return (1);
 	}
+	vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
 	return (0);
 }
 
@@ -169,7 +170,7 @@
 	struct shmalloc *sha;
 
 	assert (vd->vsl_lh != NULL);
-	for(sha = &vd->vsl_lh->head; ; sha = SHA_NEXT(sha)) {
+	for(sha = &vd->vsl_lh->head; (void*)sha < vd->vsl_end; sha = SHA_NEXT(sha)) {
 		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
 		if (strcmp(sha->type, type)) 
 			continue;
@@ -182,6 +183,25 @@
 
 /*--------------------------------------------------------------------*/
 
+void *
+VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
+    unsigned *lenp)
+{
+	struct shmalloc *sha;
+
+	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	if (VSL_Open(vd))
+		return (NULL);
+	sha = vsl_find_alloc(vd, type, ident);
+	if (sha == NULL)
+		return (NULL);
+	if (lenp != NULL)
+		*lenp = sha->len - sizeof *sha;
+	return (SHA_PTR(sha));
+}
+
+/*--------------------------------------------------------------------*/
+
 struct varnish_stats *
 VSL_OpenStats(struct VSL_data *vd)
 {

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.h	2010-05-17 20:09:45 UTC (rev 4806)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.h	2010-05-17 20:10:28 UTC (rev 4807)
@@ -40,6 +40,7 @@
 
 	int			vsl_fd;
 	struct shmloghead 	*vsl_lh;
+	void			*vsl_end;
 
 	unsigned char		*log_start;
 	unsigned char		*log_end;




More information about the varnish-commit mailing list