From: phk Date: Wed, 23 Jul 2008 21:04:12 +0000 (+0000) Subject: Prevent loading multiple VCL's with the same name if the client is not X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab0aab6cf9c1f1305051de3bb908fc3a4f697423;p=varnish Prevent loading multiple VCL's with the same name if the client is not there to stop us. Fixes #281 git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3006 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index d9c9fcd4..11533d08 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -393,16 +393,27 @@ mgt_vcc_del(struct vclprog *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 mgt_vcc_delbyname(const char *name) { struct vclprog *vp; - VTAILQ_FOREACH(vp, &vclhead, list) { - if (!strcmp(name, vp->name)) { - mgt_vcc_del(vp); - return (0); - } + vp = mgt_vcc_byname(name); + if (vp != NULL) { + mgt_vcc_del(vp); + return (0); } return (1); } @@ -541,9 +552,17 @@ mcf_config_inline(struct cli *cli, const char * const *av, void *priv) char *vf, *p = NULL; struct vsb *sb; unsigned status; + struct vclprog *vp; (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(); XXXAN(sb); vf = mgt_VccCompile(sb, av[3], NULL, 0); @@ -575,8 +594,15 @@ mcf_config_load(struct cli *cli, const char * const *av, void *priv) struct vsb *sb; unsigned status; char *p = NULL; + struct vclprog *vp; (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(); XXXAN(sb); @@ -607,9 +633,9 @@ mcf_find_vcl(struct cli *cli, const char *name) { struct vclprog *vp; - VTAILQ_FOREACH(vp, &vclhead, list) - if (!strcmp(vp->name, name)) - return (vp); + vp = mgt_vcc_byname(name); + if (vp != NULL) + return (vp); cli_result(cli, CLIS_PARAM); cli_out(cli, "No configuration named %s known.", name); return (NULL);