Permalink
Browse files

Add an explicit macro_undef() function so we don't pass a NULL

argument to a printflike function.
  • Loading branch information...
1 parent 09dedf3 commit 444e642f78ddc3bccea79d7c7707c6f0517bdb69 @bsdphk bsdphk committed with Tollef Fog Heen Apr 23, 2012
Showing with 38 additions and 18 deletions.
  1. +31 −12 bin/varnishtest/vtc.c
  2. +1 −0 bin/varnishtest/vtc.h
  3. +3 −3 bin/varnishtest/vtc_server.c
  4. +3 −3 bin/varnishtest/vtc_varnish.c
View
@@ -90,6 +90,8 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
struct macro *m;
va_list ap;
+ AN(fmt);
+
if (instance != NULL) {
bprintf(buf1, "%s_%s", instance, name);
name = buf1;
@@ -99,23 +101,40 @@ macro_def(struct vtclog *vl, const char *instance, const char *name,
VTAILQ_FOREACH(m, &macro_list, list)
if (!strcmp(name, m->name))
break;
- if (m == NULL && fmt != NULL) {
+ if (m == NULL) {
m = calloc(sizeof *m, 1);
AN(m);
REPLACE(m->name, name);
VTAILQ_INSERT_TAIL(&macro_list, m, list);
}
- if (fmt != NULL) {
- AN(m);
- va_start(ap, fmt);
- free(m->val);
- m->val = NULL;
- vbprintf(buf2, fmt, ap);
- va_end(ap);
- m->val = strdup(buf2);
- AN(m->val);
- vtc_log(vl, 4, "macro def %s=%s", name, m->val);
- } else if (m != NULL) {
+ AN(m);
+ va_start(ap, fmt);
+ free(m->val);
+ m->val = NULL;
+ vbprintf(buf2, fmt, ap);
+ va_end(ap);
+ m->val = strdup(buf2);
+ AN(m->val);
+ vtc_log(vl, 4, "macro def %s=%s", name, m->val);
+ AZ(pthread_mutex_unlock(&macro_mtx));
+}
+
+void
+macro_undef(struct vtclog *vl, const char *instance, const char *name)
+{
+ char buf1[256];
+ struct macro *m;
+
+ if (instance != NULL) {
+ bprintf(buf1, "%s_%s", instance, name);
+ name = buf1;
+ }
+
+ AZ(pthread_mutex_lock(&macro_mtx));
+ VTAILQ_FOREACH(m, &macro_list, list)
+ if (!strcmp(name, m->name))
+ break;
+ if (m != NULL) {
vtc_log(vl, 4, "macro undef %s", name);
VTAILQ_REMOVE(&macro_list, m, list);
free(m->name);
View
@@ -80,6 +80,7 @@ void vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx,
int exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen);
+void macro_undef(struct vtclog *vl, const char *instance, const char *name);
void macro_def(struct vtclog *vl, const char *instance, const char *name,
const char *fmt, ...);
struct vsb *macro_expand(struct vtclog *vl, const char *text);
@@ -147,9 +147,9 @@ server_delete(struct server *s)
{
CHECK_OBJ_NOTNULL(s, SERVER_MAGIC);
- macro_def(s->vl, s->name, "addr", NULL);
- macro_def(s->vl, s->name, "port", NULL);
- macro_def(s->vl, s->name, "sock", NULL);
+ macro_undef(s->vl, s->name, "addr");
+ macro_undef(s->vl, s->name, "port");
+ macro_undef(s->vl, s->name, "sock");
vtc_logclose(s->vl);
free(s->name);
/* XXX: MEMLEAK (?) (VSS ??) */
@@ -527,9 +527,9 @@ varnish_stop(struct varnish *v)
varnish_launch(v);
if (vtc_error)
return;
- macro_def(v->vl, v->name, "addr", NULL);
- macro_def(v->vl, v->name, "port", NULL);
- macro_def(v->vl, v->name, "sock", NULL);
+ macro_undef(v->vl, v->name, "addr");
+ macro_undef(v->vl, v->name, "port");
+ macro_undef(v->vl, v->name, "sock");
vtc_log(v->vl, 2, "Stop");
(void)varnish_ask_cli(v, "stop", NULL);
while (1) {

0 comments on commit 444e642

Please sign in to comment.