Commit 444e642f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

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

argument to a printflike function.
parent 09dedf3c
......@@ -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);
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment