r4436 - in trunk/varnish-cache: bin/varnishd bin/varnishtest lib/libvcl

tfheen at projects.linpro.no tfheen at projects.linpro.no
Fri Jan 8 10:36:17 CET 2010


Author: tfheen
Date: 2010-01-08 10:36:17 +0100 (Fri, 08 Jan 2010)
New Revision: 4436

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
   trunk/varnish-cache/bin/varnishd/stevedore_utils.c
   trunk/varnish-cache/bin/varnishd/storage_file.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
   trunk/varnish-cache/lib/libvcl/vcc_var.c
Log:
asprintf cleanup

glibc and FreeBSD libc differ in how they handle asprintf allocation
failures.  Make sure we handle both cases properly and clean up the
includes a bit.

Fixes #334

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -46,9 +46,7 @@
 #include <unistd.h>
 #include <sys/socket.h>
 
-#ifndef HAVE_VASPRINTF
 #include "compat/vasprintf.h"
-#endif
 
 #ifndef HAVE_SRANDOMDEV
 #include "compat/srandomdev.h"
@@ -593,7 +591,7 @@
 	TCP_myname(ev->fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
 	TCP_name((void*)&addr, addrlen, abuf2, sizeof abuf2,
 	    pbuf2, sizeof pbuf2);
-	asprintf(&p, "telnet %s:%s %s:%s", abuf2, pbuf2, abuf1, pbuf1);
+	assert(asprintf(&p, "telnet %s:%s %s:%s", abuf2, pbuf2, abuf1, pbuf1) > 0);
 	XXXAN(p);
 
 	(void)telnet_new(i);

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -44,9 +44,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#ifndef HAVE_ASPRINTF
 #include "compat/asprintf.h"
-#endif
 #include "vsb.h"
 
 #include "libvcl.h"

Modified: trunk/varnish-cache/bin/varnishd/stevedore_utils.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore_utils.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishd/stevedore_utils.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -55,6 +55,7 @@
 #include <sys/vfs.h>
 #endif
 
+#include "compat/asprintf.h"
 #include "mgt.h"
 #include "stevedore.h"
 
@@ -106,7 +107,7 @@
 		    ctx, fn);
 
 	if (S_ISDIR(st.st_mode)) {
-		asprintf(&q, "%s/varnish.XXXXXX", fn);
+		xxxassert(asprintf(&q, "%s/varnish.XXXXXX", fn) > 0);
 		XXXAN(q);
 		fd = mkstemp(q);
 		if (fd < 0)

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -46,10 +46,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#ifndef HAVE_ASPRINTF
-#include "compat/asprintf.h"
-#endif
-
 #include "shmlog.h"
 #include "cache.h"
 #include "stevedore.h"

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -48,6 +48,7 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "compat/asprintf.h"
 #include "compat/daemon.h"
 
 #ifndef HAVE_STRLCPY
@@ -435,10 +436,11 @@
 	FILE *fi;
 	uintptr_t a;
 	struct symbols *s;
+	int i;
 
 	p = NULL;
-	asprintf(&p, "nm -an %s 2>/dev/null", a0);
-	if (p == NULL)
+	i = asprintf(&p, "nm -an %s 2>/dev/null", a0);
+	if (i < 0 || p == NULL)
 		return;
 	fi = popen(p, "r");
 	free(p);

Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include "compat/asprintf.h"
 
 #include "libvarnish.h"
 #include "vsb.h"
@@ -106,7 +107,7 @@
 		va_start(ap, fmt);
 		free(m->val);
 		m->val = NULL;
-		(void)vasprintf(&m->val, fmt, ap);
+		assert(vasprintf(&m->val, fmt, ap) >= 0);
 		va_end(ap);
 		AN(m->val);
 		vtc_log(vl, 4, "macro def %s=%s", name, m->val);

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -46,6 +46,7 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 
+#include "compat/asprintf.h"
 #include "vqueue.h"
 #include "miniobj.h"
 #include "libvarnish.h"
@@ -153,12 +154,13 @@
 	REPLACE(v->name, name);
 
 	if (getuid() == 0)
-		(void)asprintf(&v->workdir, "/tmp/__%s", name);
+		assert(asprintf(&v->workdir, "/tmp/__%s", name) >= 0);
 	else
-		(void)asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid());
+		assert(asprintf(&v->workdir, "/tmp/__%s.%d", name, getuid()) >= 0);
 	AN(v->workdir);
 
-	(void)asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir);
+	assert(asprintf(&c, "rm -rf %s ; mkdir -p %s", v->workdir, v->workdir) >= 0);
+	AN(c);
 	AZ(system(c));
 
 	v->vl = vtc_logopen(name);

Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -47,6 +47,7 @@
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 #include "libvarnish.h"
+#include "compat/vasprintf.h"
 
 struct acl_e {
 	VTAILQ_ENTRY(acl_e)	list;
@@ -472,8 +473,8 @@
 		VTAILQ_INIT(&tl->acl);
 		tcond = tl->t->tok;
 		vcc_NextToken(tl);
-		asprintf(&acln, "%u", tl->cnt);
-		assert(acln != NULL);
+		assert(asprintf(&acln, "%u", tl->cnt) > 0);
+		AN(acln);
 		vcc_acl_entry(tl);
 		vcc_acl_emit(tl, acln, 1);
 		Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n",
@@ -504,8 +505,8 @@
 	vcc_NextToken(tl);
 
 	vcc_AddDef(tl, an, R_ACL);
-	asprintf(&acln, "%.*s", PF(an));
-	assert(acln != NULL);
+	assert(asprintf(&acln, "%.*s", PF(an)) > 0);
+	AN(acln);
 
 	ExpectErr(tl, '{');
 	vcc_NextToken(tl);

Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-01-08 09:13:17 UTC (rev 4435)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-01-08 09:36:17 UTC (rev 4436)
@@ -40,6 +40,7 @@
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 #include "libvarnish.h"
+#include "compat/vasprintf.h"
 
 /*--------------------------------------------------------------------*/
 
@@ -64,13 +65,13 @@
 	v->fmt = STRING;
 	v->hdr = vh->hdr;
 	v->methods = vh->methods;
-	asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
-	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
+	assert(asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
+	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
 	AN(p);
 	TlFree(tl, p);
 	v->rname = p;
-	asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
-	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
+	assert(asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
+	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
 	AN(p);
 	TlFree(tl, p);
 	v->lname = p;



More information about the varnish-commit mailing list