r4582 - in trunk/varnish-cache: bin/varnishd include lib/libvarnishcompat

phk at projects.linpro.no phk at projects.linpro.no
Sun Feb 21 23:00:09 CET 2010


Author: phk
Date: 2010-02-21 23:00:09 +0100 (Sun, 21 Feb 2010)
New Revision: 4582

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_panic.c
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/flint.lnt
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/include/persistent.h
   trunk/varnish-cache/include/vev.h
   trunk/varnish-cache/lib/libvarnishcompat/execinfo.c
Log:
Various flexelint inspired cleanups



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2010-02-21 22:00:09 UTC (rev 4582)
@@ -695,10 +695,10 @@
 void SMS_Finish(struct object *obj);
 
 /* storage_persistent.c */
-void SMP_Fixup(struct sess *sp, struct objhead *oh, struct objcore *oc);
+void SMP_Fixup(struct sess *sp, const struct objhead *oh, struct objcore *oc);
 void SMP_BANchanged(const struct object *o, double t);
 void SMP_TTLchanged(const struct object *o);
-void SMP_FreeObj(struct object *o);
+void SMP_FreeObj(const struct object *o);
 void SMP_Ready(void);
 void SMP_NewBan(double t0, const char *ban);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_panic.c	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/cache_panic.c	2010-02-21 22:00:09 UTC (rev 4582)
@@ -279,7 +279,10 @@
 		if (Symbol_Lookup(vsp, array[i]) < 0) {
 			char **strings;
 			strings = backtrace_symbols(&array[i], 1);
-			vsb_printf(vsp, "%p: %s", array[i], strings[0]);
+			if (strings != NULL && strings[0] != NULL)
+				vsb_printf(vsp, "%p: %s", array[i], strings[0]);
+			else
+				vsb_printf(vsp, "%p: (?)", array[i]);
 		}
 		vsb_printf (vsp, "\n");
 	}

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2010-02-21 22:00:09 UTC (rev 4582)
@@ -212,13 +212,13 @@
 wrk_thread(void *priv)
 {
 	struct wq *qp;
-	volatile unsigned nhttp;
+	unsigned nhttp;
 	unsigned siov;
 
 	CAST_OBJ_NOTNULL(qp, priv, WQ_MAGIC);
 	/* We need to snapshot these two for consistency */
 	nhttp = params->http_headers;
-	siov = nhttp * 2;		/* XXX param ? */
+	siov = nhttp * 2;
 	if (siov > IOV_MAX)
 		siov = IOV_MAX;
 	return (wrk_thread_real(qp,

Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt	2010-02-21 22:00:09 UTC (rev 4582)
@@ -201,6 +201,9 @@
 -efunc(539, http_FilterFields)	// Positive indentation from line
 -efunc(539, http_EstimateWS)	// Positive indentation from line
 
+-esym(525, __builtin_frame_address)	// Not defined
+-esym(525, __builtin_return_address)	// Not defined
+
 // cache_vcl.c
 -efunc(525, vcl_handlingname)	// Negative indentation from line
 -esym(528, vcl_handlingname)	// Not referenced

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2010-02-21 22:00:09 UTC (rev 4582)
@@ -199,6 +199,10 @@
 	unsigned		syslog_cli_traffic;
 };
 
+/*
+ * We declare this a volatile pointer, so that reads of parameters
+ * become atomic, leaving the CLI thread lattitude to change the values
+ */
 extern volatile struct params *params;
 extern struct heritage heritage;
 

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-02-21 22:00:09 UTC (rev 4582)
@@ -648,7 +648,7 @@
  */
 
 void
-SMP_Fixup(struct sess *sp, struct objhead *oh, struct objcore *oc)
+SMP_Fixup(struct sess *sp, const struct objhead *oh, struct objcore *oc)
 {
 	struct smp_seg *sg;
 	struct smp_object *so;
@@ -785,7 +785,7 @@
  */
 
 void
-SMP_FreeObj(struct object *o)
+SMP_FreeObj(const struct object *o)
 {
 	struct smp_seg *sg;
 

Modified: trunk/varnish-cache/include/persistent.h
===================================================================
--- trunk/varnish-cache/include/persistent.h	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/include/persistent.h	2010-02-21 22:00:09 UTC (rev 4582)
@@ -137,5 +137,4 @@
 	double			ttl;
 	double			ban;
 	struct object		*ptr;
-	uint64_t		len;	/* XXX: madvise */
 };

Modified: trunk/varnish-cache/include/vev.h
===================================================================
--- trunk/varnish-cache/include/vev.h	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/include/vev.h	2010-02-21 22:00:09 UTC (rev 4582)
@@ -50,7 +50,6 @@
 #define		EV_WR		POLLOUT
 #define		EV_ERR		POLLERR
 #define		EV_HUP		POLLHUP
-#define		EV_GONE		POLLNVAL
 #define		EV_SIG		-1
 	int			sig;
 	unsigned		sig_flags;

Modified: trunk/varnish-cache/lib/libvarnishcompat/execinfo.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishcompat/execinfo.c	2010-02-21 20:36:31 UTC (rev 4581)
+++ trunk/varnish-cache/lib/libvarnishcompat/execinfo.c	2010-02-21 22:00:09 UTC (rev 4582)
@@ -45,97 +45,88 @@
 #include <string.h>
 #include <unistd.h>
 
-
 static void *getreturnaddr(int);
 static void *getframeaddr(int);
 
-#define D10(x) ceil(log10(((x) == 0) ? 2 : ((x) + 1)))
-
-inline static void *
-realloc_safe(void *ptr, size_t size)
-{
-    void *nptr;
-
-    nptr = realloc(ptr, size);
-    if (nptr == NULL)
-        free(ptr);
-    return nptr;
-}
-
 int
 backtrace(void **buffer, int size)
 {
-    int i;
+	int i;
 
-    for (i = 1; getframeaddr(i + 1) != NULL && i != size + 1; i++) {
-        buffer[i - 1] = getreturnaddr(i);
-        if (buffer[i - 1] == NULL)
-            break;
-    }
-
-    return i - 1;
+	for (i = 1; getframeaddr(i + 1) != NULL && i != size + 1; i++) {
+		buffer[i - 1] = getreturnaddr(i);
+		if (buffer[i - 1] == NULL)
+			break;
+	}
+	return (i - 1);
 }
 
+/*
+ * XXX: This implementation should be changed to a much more conservative
+ * XXX: memory strategy:  Allocate 4k up front, realloc 4K more as needed.
+ */
+
 char **
 backtrace_symbols(void *const *buffer, int size)
 {
-    size_t clen, alen;
-    int i;
-    char **rval;
+	size_t clen, alen;
+	int i;
+	char **rval;
 
-    clen = size * sizeof(char *);
-    rval = malloc(clen);
-    if (rval == NULL)
-        return NULL;
-    for (i = 0; i < size; i++) {
+	clen = size * sizeof(char *);
+	rval = malloc(clen);
+	if (rval == NULL)
+		return (NULL);
+	for (i = 0; i < size; i++) {
 
 #ifdef HAVE_DLADDR
-    {
-        Dl_info info;
-	int offset;
+		{
+		Dl_info info;
+		int offset;
 
-        if (dladdr(buffer[i], &info) != 0) {
-            if (info.dli_sname == NULL)
-                info.dli_sname = "???";
-            if (info.dli_saddr == NULL)
-                info.dli_saddr = buffer[i];
-            offset = (const char*)buffer[i] - (const char*)info.dli_saddr;
-            /* "0x01234567 <function+offset> at filename" */
-            alen = 2 +                      /* "0x" */
-                   (sizeof(void *) * 2) +   /* "01234567" */
-                   2 +                      /* " <" */
-                   strlen(info.dli_sname) + /* "function" */
-                   1 +                      /* "+" */
-                   10 +                     /* "offset */
-                   5 +                      /* "> at " */
-                   strlen(info.dli_fname) + /* "filename" */
-                   1;                       /* "\0" */
-            rval = realloc_safe(rval, clen + alen);
-            if (rval == NULL)
-                return NULL;
-            snprintf((char *) rval + clen, alen, "%p <%s+%d> at %s",
-              buffer[i], info.dli_sname, offset, info.dli_fname);
-            rval[i] = (char *) clen;
-            clen += alen;
-	    continue;
-        }
-    }
+		if (dladdr(buffer[i], &info) != 0) {
+			if (info.dli_sname == NULL)
+				info.dli_sname = "?";
+			if (info.dli_saddr == NULL)
+				info.dli_saddr = buffer[i];
+			offset = (const char*)buffer[i] -
+			    (const char*)info.dli_saddr;
+			/* "0x01234567 <function+offset> at filename" */
+			alen = 2 +                      /* "0x" */
+			    (sizeof(void *) * 2) +   /* "01234567" */
+			    2 +                      /* " <" */
+			    strlen(info.dli_sname) + /* "function" */
+			    1 +                      /* "+" */
+			    10 +                     /* "offset */
+			    5 +                      /* "> at " */
+			    strlen(info.dli_fname) + /* "filename" */
+			    1;                       /* "\0" */
+			rval = realloc(rval, clen + alen);
+			if (rval == NULL)
+				return NULL;
+			(void)snprintf((char *) rval + clen, alen,
+			    "%p <%s+%d> at %s", buffer[i], info.dli_sname,
+			    offset, info.dli_fname);
+			rval[i] = (char *) clen;
+			clen += alen;
+			continue;
+		}
+		}
 #endif
-	alen = 2 +                      /* "0x" */
-	       (sizeof(void *) * 2) +   /* "01234567" */
-	       1;                       /* "\0" */
-	rval = realloc_safe(rval, clen + alen);
-	if (rval == NULL)
-	    return NULL;
-	snprintf((char *) rval + clen, alen, "%p", buffer[i]);
-        rval[i] = (char *) clen;
-        clen += alen;
-    }
+		alen = 2 +                      /* "0x" */
+		    (sizeof(void *) * 2) +   /* "01234567" */
+		    1;                       /* "\0" */
+		rval = realloc(rval, clen + alen);
+		if (rval == NULL)
+			return NULL;
+		(void)snprintf((char *) rval + clen, alen, "%p", buffer[i]);
+		rval[i] = (char *) clen;
+		clen += alen;
+	}
 
-    for (i = 0; i < size; i++)
-        rval[i] += (long) rval;
-
-    return rval;
+	for (i = 0; i < size; i++)
+		rval[i] += (long) rval;
+	return (rval);
 }
 
 static void *



More information about the varnish-commit mailing list