Commit 0e4174c0 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Fail name checks early in varnishtest

It closes a race for barriers because the list could be updated by the
top thread while walked by another thread. It also saves useless lookups
by rejecting names earlier.

This is not the case for servers because a) they have proper locking of
the servers list and b) there is the dispatch special case. It would
otherwise be harmless to do it for the server too because dispatched
servers don't depend on user input.
parent 37de1a0d
......@@ -74,7 +74,6 @@ barrier_new(const char *name, struct vtclog *vl)
{
struct barrier *b;
VTC_CHECK_NAME(vl, name, "Barrier", 'b');
ALLOC_OBJ(b, BARRIER_MAGIC);
AN(b);
if (pthread_self() != vtc_thread)
......@@ -436,6 +435,7 @@ cmd_barrier(CMD_ARGS)
AZ(strcmp(av[0], "barrier"));
av++;
VTC_CHECK_NAME(vl, av[0], "Barrier", 'b');
VTAILQ_FOREACH(b, &barriers, list)
if (!strcmp(b->name, av[0]))
break;
......
......@@ -165,11 +165,10 @@ client_thread(void *priv)
*/
static struct client *
client_new(const char *name, struct vtclog *vl)
client_new(const char *name)
{
struct client *c;
VTC_CHECK_NAME(vl, name, "Client", 'c');
ALLOC_OBJ(c, CLIENT_MAGIC);
AN(c);
REPLACE(c->name, name);
......@@ -269,11 +268,12 @@ cmd_client(CMD_ARGS)
AZ(strcmp(av[0], "client"));
av++;
VTC_CHECK_NAME(vl, av[0], "Client", 'c');
VTAILQ_FOREACH(c, &clients, list)
if (!strcmp(c->name, av[0]))
break;
if (c == NULL)
c = client_new(av[0], vl);
c = client_new(av[0]);
av++;
for (; *av != NULL; av++) {
......
......@@ -199,11 +199,10 @@ logexp_delete(struct logexp *le)
}
static struct logexp *
logexp_new(const char *name, struct vtclog *vl)
logexp_new(const char *name)
{
struct logexp *le;
VTC_CHECK_NAME(vl, name, "Logexpect", 'l');
ALLOC_OBJ(le, LOGEXP_MAGIC);
AN(le);
REPLACE(le->name, name);
......@@ -528,12 +527,13 @@ cmd_logexpect(CMD_ARGS)
AZ(strcmp(av[0], "logexpect"));
av++;
VTC_CHECK_NAME(vl, av[0], "Logexpect", 'l');
VTAILQ_FOREACH(le, &logexps, list) {
if (!strcmp(le->name, av[0]))
break;
}
if (le == NULL)
le = logexp_new(av[0], vl);
le = logexp_new(av[0]);
av++;
for (; *av != NULL; av++) {
......
......@@ -85,13 +85,12 @@ static VTAILQ_HEAD(, process) processes =
} while (0)
static struct process *
process_new(const char *name, struct vtclog *vl)
process_new(const char *name)
{
struct process *p;
struct vsb *vsb;
char buf[1024];
VTC_CHECK_NAME(vl, name, "Process", 'p');
ALLOC_OBJ(p, PROCESS_MAGIC);
AN(p);
REPLACE(p->name, name);
......@@ -455,11 +454,12 @@ cmd_process(CMD_ARGS)
AZ(strcmp(av[0], "process"));
av++;
VTC_CHECK_NAME(vl, av[0], "Process", 'p');
VTAILQ_FOREACH(p, &processes, list)
if (!strcmp(p->name, av[0]))
break;
if (p == NULL)
p = process_new(av[0], vl);
p = process_new(av[0]);
av++;
for (; *av != NULL; av++) {
......
......@@ -268,13 +268,12 @@ varnishlog_thread(void *priv)
*/
static struct varnish *
varnish_new(const char *name, struct vtclog *vl)
varnish_new(const char *name)
{
struct varnish *v;
struct vsb *vsb;
char buf[1024];
VTC_CHECK_NAME(vl, name, "Varnish", 'v');
ALLOC_OBJ(v, VARNISH_MAGIC);
AN(v);
REPLACE(v->name, name);
......@@ -1075,11 +1074,12 @@ cmd_varnish(CMD_ARGS)
AZ(strcmp(av[0], "varnish"));
av++;
VTC_CHECK_NAME(vl, av[0], "Varnish", 'v');
VTAILQ_FOREACH(v, &varnishes, list)
if (!strcmp(v->name, av[0]))
break;
if (v == NULL)
v = varnish_new(av[0], vl);
v = varnish_new(av[0]);
av++;
for (; *av != NULL; av++) {
......
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