Mailing List Archive

[7.0] a2c70c5e9 Change mgt_new_vcl() to return the newly compiled vclprog
commit a2c70c5e9ee20b7474bf982ee30a20e5985a5b9f
Author: Martin Blix Grydeland <martin@varnish-software.com>
Date: Thu Nov 11 14:19:18 2021 +0100

Change mgt_new_vcl() to return the newly compiled vclprog

mgt_new_vcl() now returns a pointer to the newly compiled VCL program, or
NULL on failure.

This also fixes a wrong return value used previously which would cause a
"VCL compiled.\n" to be output to CLI when the child is not running even
when the VCL compilation step failed.

diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index d14c9d95c..a45645e5d 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -426,7 +426,7 @@ mgt_vcl_setstate(struct cli *cli, struct vclprog *vp, const struct vclstate *vs)

/*--------------------------------------------------------------------*/

-static int
+static struct vclprog *
mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
const char *vclsrcfile, const char *state, int C_flag)
{
@@ -442,7 +442,7 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
VCLI_Out(cli, "Too many (%d) VCLs already loaded\n", vcl_count);
VCLI_Out(cli, "(See max_vcl and max_vcl_handling parameters)");
VCLI_SetResult(cli, CLIS_CANT);
- return (0);
+ return (NULL);
}

if (state == NULL)
@@ -451,13 +451,13 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
vs = mcf_vcl_parse_state(cli, state);

if (vs == NULL)
- return (0);
+ return (NULL);

vp = mgt_vcl_add(vclname, vs);
lib = mgt_VccCompile(cli, vp, vclname, vclsrc, vclsrcfile, C_flag);
if (lib == NULL) {
mgt_vcl_del(vp);
- return (0);
+ return (NULL);
}

AZ(C_flag);
@@ -475,7 +475,7 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
}

if (!MCH_Running())
- return (0);
+ return (vp);

if (mgt_cli_askchild(&status, &p, "vcl.load %s %s %d%s\n",
vp->name, vp->fname, vp->warm, vp->state->name)) {
@@ -483,12 +483,12 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc,
VCLI_Out(cli, "%s", p);
VCLI_SetResult(cli, status);
free(p);
- return (0);
+ return (NULL);
}
free(p);

mgt_vcl_set_cooldown(vp, VTIM_mono());
- return (1);
+ return (vp);
}

/*--------------------------------------------------------------------*/
@@ -573,25 +573,29 @@ mgt_push_vcls(struct cli *cli, unsigned *status, char **p)
static void v_matchproto_(cli_func_t)
mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv)
{
+ struct vclprog *vp;

(void)priv;

if (!mcf_find_no_vcl(cli, av[2]))
return;

- if (!mgt_new_vcl(cli, av[2], av[3], "<vcl.inline>", av[4], 0))
+ vp = mgt_new_vcl(cli, av[2], av[3], "<vcl.inline>", av[4], 0);
+ if (vp != NULL && !MCH_Running())
VCLI_Out(cli, "VCL compiled.\n");
}

static void v_matchproto_(cli_func_t)
mcf_vcl_load(struct cli *cli, const char * const *av, void *priv)
{
+ struct vclprog *vp;

(void)priv;
if (!mcf_find_no_vcl(cli, av[2]))
return;

- if (!mgt_new_vcl(cli, av[2], NULL, av[3], av[4], 0))
+ vp = mgt_new_vcl(cli, av[2], NULL, av[3], av[4], 0);
+ if (vp != NULL && !MCH_Running())
VCLI_Out(cli, "VCL compiled.\n");
}

_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit