r5098 - in trunk/varnish-cache: bin/varnishd lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Thu Aug 12 10:40:14 CEST 2010


Author: phk
Date: 2010-08-12 10:40:13 +0200 (Thu, 12 Aug 2010)
New Revision: 5098

Modified:
   trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
   trunk/varnish-cache/bin/varnishd/flint.lnt
   trunk/varnish-cache/lib/libvcl/vcc_dir_dns.c
Log:
Some minor cleaups and additional asserts to get rid of the worst
FlexeLint spammage.



Modified: trunk/varnish-cache/bin/varnishd/cache_dir_dns.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_dns.c	2010-08-12 08:38:51 UTC (rev 5097)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_dns.c	2010-08-12 08:40:13 UTC (rev 5098)
@@ -79,14 +79,13 @@
 	pthread_rwlock_t		rwlock;
 	const char			*suffix;
 	double			ttl;
-	const unsigned			max_cache_size;
 };
 
 
 
 /* Compare an IPv4 backend to a IPv4 addr/len */
 static int
-vdi_dns_comp_addrinfo4(struct backend *bp, 
+vdi_dns_comp_addrinfo4(const struct backend *bp, 
 		       const struct sockaddr_in *addr,
 		       const socklen_t len)
 {
@@ -104,7 +103,7 @@
 
 /* Compare an IPv6 backend to a IPv6 addr/len */
 static int
-vdi_dns_comp_addrinfo6(struct backend *bp,
+vdi_dns_comp_addrinfo6(const struct backend *bp,
 		       struct sockaddr_in6 *addr,
 		       const socklen_t len)
 {
@@ -128,12 +127,14 @@
 
 /* Check if a backends socket is the same as addr */
 static int
-vdi_dns_comp_addrinfo(struct director *dir,
+vdi_dns_comp_addrinfo(const struct director *dir,
 		      struct sockaddr *addr,
 		      const socklen_t len)
 {
 	struct backend *bp;
+
 	bp = vdi_get_backend_if_simple(dir);
+	AN(bp);
 	if (addr->sa_family == PF_INET && bp->ipv4) {
 		return (vdi_dns_comp_addrinfo4(bp, (struct sockaddr_in *)
 			addr, len));
@@ -279,8 +280,9 @@
 	hint.ai_socktype = SOCK_STREAM;
 
 	ALLOC_OBJ(new, VDI_DNSDIR_MAGIC);
+	XXXAN(new);
 	new->hostname = calloc(sizeof(char), strlen(hostname)+1);
-	assert(new->hostname != NULL);
+	XXXAN(new->hostname);
 	strcpy(new->hostname, hostname);
 
 	error = getaddrinfo(hostname, "80", &hint, &res0);
@@ -292,15 +294,15 @@
 	}
 
 	for (res = res0; res; res = res->ai_next) {
-		if (res->ai_family != PF_INET &&
-				res->ai_family != PF_INET6)
+		if (res->ai_family != PF_INET && res->ai_family != PF_INET6)
 			continue;
 
 		for (i = 0; i < vs->nhosts; i++) {
 			if (vdi_dns_comp_addrinfo(vs->hosts[i],
-						res->ai_addr, res->ai_addrlen)) {
+			    res->ai_addr, res->ai_addrlen)) {
 				new->hosts[host] = vs->hosts[i];
-				CHECK_OBJ_NOTNULL(new->hosts[host], DIRECTOR_MAGIC);
+				CHECK_OBJ_NOTNULL(new->hosts[host],
+				    DIRECTOR_MAGIC);
 				host++;
 			}
 		}
@@ -327,11 +329,11 @@
 	int ret;
 	AZ(pthread_rwlock_rdlock(&vs->rwlock));
 	ret = vdi_dns_cache_has(sp, vs, hostname, &backend, 0);
-	pthread_rwlock_unlock(&vs->rwlock);
+	AZ(pthread_rwlock_unlock(&vs->rwlock));
 	if (!ret) {
 		AZ(pthread_rwlock_wrlock(&vs->rwlock));
 		ret = vdi_dns_cache_add(sp, vs, hostname, &backend);
-		pthread_rwlock_unlock(&vs->rwlock);
+		AZ(pthread_rwlock_unlock(&vs->rwlock));
 	} else
 		VSC_main->dir_dns_hit++;
 
@@ -434,17 +436,15 @@
 vdi_dns_fini(struct director *d)
 {
 	struct vdi_dns *vs;
-	struct director **vh;
 
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(vs, d->priv, VDI_DNS_MAGIC);
 
-	vh = vs->hosts;
 	free(vs->hosts);
 	free(vs->dir.vcl_name);
 	vs->dir.magic = 0;
 	/* FIXME: Free the cache */
-	pthread_rwlock_destroy(&vs->rwlock);
+	AZ(pthread_rwlock_destroy(&vs->rwlock));
 	FREE_OBJ(vs);
 }
 
@@ -482,6 +482,6 @@
 	vs->nhosts = t->nmember;
 	vs->ttl = t->ttl;
 	VTAILQ_INIT(&vs->cachelist);
-	pthread_rwlock_init(&vs->rwlock, NULL);
+	AZ(pthread_rwlock_init(&vs->rwlock, NULL));
 	bp[idx] = &vs->dir;
 }

Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt	2010-08-12 08:38:51 UTC (rev 5097)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt	2010-08-12 08:40:13 UTC (rev 5098)
@@ -100,6 +100,8 @@
 -sem(WS_Init, custodial(2))
 -sem(http_Setup, custodial(2))
 
+-sem(vdi_dns_cache_list_add, custodial(3))
+
 -e455	// thread lock
 -e458	// unprotected read
 -e763	// Redundant declaration for symbol '...' previously declared

Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_dns.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_dns.c	2010-08-12 08:38:51 UTC (rev 5097)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_dns.c	2010-08-12 08:40:13 UTC (rev 5098)
@@ -35,7 +35,6 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 
-#include <netdb.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
@@ -51,7 +50,7 @@
  * Parse directors
  */
 
-struct vcc_dir_backend_defaults {
+static struct vcc_dir_backend_defaults {
 	char *port;
 	char *hostheader;
 	double connect_timeout;
@@ -72,20 +71,21 @@
 	b_defaults.saint = UINT_MAX;
 }
 
-static struct token *dns_first;
+static const struct token *dns_first;
 
 static void
 print_backend(struct vcc *tl,
 	      int serial,
-	      uint8_t *ip)
+	      const uint8_t *ip)
 {
 	char vgcname[BUFSIZ];
 	char strip[16];
 	struct token tmptok;
 	struct vsb *vsb;
-	sprintf(strip, "%d.%d.%d.%d",ip[3],ip[2],ip[1],ip[0]);
+
+	sprintf(strip, "%u.%u.%u.%u", ip[3], ip[2], ip[1], ip[0]);
 	tmptok.dec = strip;
-	sprintf(vgcname,"%.*s_%d",PF(tl->t_dir),serial);
+	sprintf(vgcname,"%.*s_%d",PF(tl->t_dir), serial);
 	vsb = vsb_newauto();
 	AN(vsb);
 	tl->fb = vsb;
@@ -127,6 +127,7 @@
 	Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname);
 	tl->ndirector++;
 }
+
 /*
  * Output backends for all IPs in the range supplied by
  * "a[0].a[1].a[2].a[3]/inmask".
@@ -138,7 +139,7 @@
 static void
 vcc_dir_dns_makebackend(struct vcc *tl, 
 			int *serial,
-			unsigned char a[],
+			const unsigned char a[],
 			int inmask)
 {
 	uint32_t ip4=0;
@@ -258,7 +259,8 @@
 		vcc_dir_dns_parse_backend_options(tl);
 	while (tl->t->tok == CSTR) {
 		mask = 32;
-		ret = sscanf(tl->t->dec, "%hhu.%hhu.%hhu.%hhu",&a[0],&a[1],&a[2],&a[3]);
+		ret = sscanf(tl->t->dec, "%hhu.%hhu.%hhu.%hhu",
+		    &a[0], &a[1], &a[2], &a[3]);
 		assert(ret == 4);
 		vcc_NextToken(tl);
 		if (tl->t->tok == '/') {
@@ -277,7 +279,7 @@
 {
 	struct token *t_field, *t_be, *t_suffix = NULL;
 	double ttl = 60.0;
-	int nbh, nelem = 0;
+	int nelem = 0;
 	struct fld_spec *fs;
 	const char *first;
 	char *p;
@@ -294,7 +296,6 @@
 			first = "";
 			t_be = tl->t;
 			vcc_ResetFldSpec(fs);
-			nbh = -1;
 
 			ExpectErr(tl, '{');
 			vcc_NextToken(tl);




More information about the varnish-commit mailing list