r4964 - trunk/varnish-cache/lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Wed Jun 16 14:25:47 CEST 2010


Author: phk
Date: 2010-06-16 14:25:46 +0200 (Wed, 16 Jun 2010)
New Revision: 4964

Modified:
   trunk/varnish-cache/lib/libvarnishapi/vsm.c
Log:
Better error handling, limit how long time we wait for initialization
to complete.



Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsm.c	2010-06-16 11:16:09 UTC (rev 4963)
+++ trunk/varnish-cache/lib/libvarnishapi/vsm.c	2010-06-16 12:25:46 UTC (rev 4964)
@@ -142,7 +142,7 @@
 static int
 vsm_open(struct VSM_data *vd, int diag)
 {
-	int i;
+	int i, j;
 	struct vsm_head slh;
 
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
@@ -161,6 +161,8 @@
 		if (diag)
 			vd->diag(vd->priv, "%s is not a regular file\n",
 			    vd->fname);
+		AZ(close(vd->vsm_fd));
+		vd->vsm_fd = -1;
 		return (1);
 	}
 
@@ -169,12 +171,16 @@
 		if (diag)
 			vd->diag(vd->priv, "Cannot read %s: %s\n",
 			    vd->fname, strerror(errno));
+		AZ(close(vd->vsm_fd));
+		vd->vsm_fd = -1;
 		return (1);
 	}
 	if (slh.magic != VSM_HEAD_MAGIC) {
 		if (diag)
 			vd->diag(vd->priv, "Wrong magic number in file %s\n",
 			    vd->fname);
+		AZ(close(vd->vsm_fd));
+		vd->vsm_fd = -1;
 		return (1);
 	}
 
@@ -188,8 +194,17 @@
 	}
 	vd->vsm_end = (uint8_t *)vd->vsm_head + slh.shm_size;
 
-	while(slh.alloc_seq == 0)
-		(void)usleep(50000);		/* XXX limit total sleep */
+	for (j = 0; j < 20 && slh.alloc_seq == 0; j++)
+		(void)usleep(50000);
+	if (slh.alloc_seq == 0) {
+		if (diag)
+			vd->diag(vd->priv, "File not initialized %s\n",
+			    vd->fname);
+		assert(0 == munmap((void*)vd->vsm_head, slh.shm_size));
+		AZ(close(vd->vsm_fd));
+		vd->vsm_fd = -1;
+		return (1);
+	}
 	vd->alloc_seq = slh.alloc_seq;
 
 	if (vd->vsl != NULL)




More information about the varnish-commit mailing list