Commit 7dfca207 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Prevent loading multiple VCL's with the same name if the client is not

there to stop us.

Fixes #281



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3006 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 5171381d
...@@ -393,17 +393,28 @@ mgt_vcc_del(struct vclprog *vp) ...@@ -393,17 +393,28 @@ mgt_vcc_del(struct vclprog *vp)
free(vp); free(vp);
} }
static struct vclprog *
mgt_vcc_byname(const char *name)
{
struct vclprog *vp;
VTAILQ_FOREACH(vp, &vclhead, list)
if (!strcmp(name, vp->name))
return (vp);
return (NULL);
}
static int static int
mgt_vcc_delbyname(const char *name) mgt_vcc_delbyname(const char *name)
{ {
struct vclprog *vp; struct vclprog *vp;
VTAILQ_FOREACH(vp, &vclhead, list) { vp = mgt_vcc_byname(name);
if (!strcmp(name, vp->name)) { if (vp != NULL) {
mgt_vcc_del(vp); mgt_vcc_del(vp);
return (0); return (0);
} }
}
return (1); return (1);
} }
...@@ -541,9 +552,17 @@ mcf_config_inline(struct cli *cli, const char * const *av, void *priv) ...@@ -541,9 +552,17 @@ mcf_config_inline(struct cli *cli, const char * const *av, void *priv)
char *vf, *p = NULL; char *vf, *p = NULL;
struct vsb *sb; struct vsb *sb;
unsigned status; unsigned status;
struct vclprog *vp;
(void)priv; (void)priv;
vp = mgt_vcc_byname(av[2]);
if (vp != NULL) {
cli_out(cli, "Already a VCL program named %s", av[2]);
cli_result(cli, CLIS_PARAM);
return;
}
sb = vsb_newauto(); sb = vsb_newauto();
XXXAN(sb); XXXAN(sb);
vf = mgt_VccCompile(sb, av[3], NULL, 0); vf = mgt_VccCompile(sb, av[3], NULL, 0);
...@@ -575,8 +594,15 @@ mcf_config_load(struct cli *cli, const char * const *av, void *priv) ...@@ -575,8 +594,15 @@ mcf_config_load(struct cli *cli, const char * const *av, void *priv)
struct vsb *sb; struct vsb *sb;
unsigned status; unsigned status;
char *p = NULL; char *p = NULL;
struct vclprog *vp;
(void)priv; (void)priv;
vp = mgt_vcc_byname(av[2]);
if (vp != NULL) {
cli_out(cli, "Already a VCL program named %s", av[2]);
cli_result(cli, CLIS_PARAM);
return;
}
sb = vsb_newauto(); sb = vsb_newauto();
XXXAN(sb); XXXAN(sb);
...@@ -607,8 +633,8 @@ mcf_find_vcl(struct cli *cli, const char *name) ...@@ -607,8 +633,8 @@ mcf_find_vcl(struct cli *cli, const char *name)
{ {
struct vclprog *vp; struct vclprog *vp;
VTAILQ_FOREACH(vp, &vclhead, list) vp = mgt_vcc_byname(name);
if (!strcmp(vp->name, name)) if (vp != NULL)
return (vp); return (vp);
cli_result(cli, CLIS_PARAM); cli_result(cli, CLIS_PARAM);
cli_out(cli, "No configuration named %s known.", name); cli_out(cli, "No configuration named %s known.", name);
......
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