Commit a68f58ab authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Give the CLI command vcl.show a -v flag which outputs all the source

files involved in a given VCL.

When using -v, the individual source files are output like this:

	// VCL.SHOW %d %d %s\n%s\n

First field is the source file index [0...].
Second field is the number of bytes in the source file.
Third field is the name of the source file.
Fourth field is the source file content.

Inspired by a patch from daghf
parent 40b8066d
......@@ -372,6 +372,40 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv)
VBE_UseHealth(vcl->conf->director[i]);
}
static void
ccf_config_show(struct cli *cli, const char * const *av, void *priv)
{
struct vcls *vcl;
int verbose = 0;
int i;
(void)priv;
if (!strcmp(av[2], "-v")) {
verbose = 1;
vcl = vcl_find(av[3]);
} else if (av[3] != NULL) {
VCLI_Out(cli, "Unknown options '%s'", av[2]);
VCLI_SetResult(cli, CLIS_PARAM);
return;
} else
vcl = vcl_find(av[2]);
if (vcl == NULL) {
VCLI_Out(cli, "No VCL named '%s'", av[2]);
VCLI_SetResult(cli, CLIS_PARAM);
return;
}
if (verbose) {
for (i = 0; i < vcl->conf->nsrc; i++)
VCLI_Out(cli, "// VCL.SHOW %d %zd %s\n%s\n",
i, strlen(vcl->conf->srcbody[i]),
vcl->conf->srcname[i],
vcl->conf->srcbody[i]);
} else {
VCLI_Out(cli, "%s", vcl->conf->srcbody[0]);
}
}
/*--------------------------------------------------------------------
* Method functions to call into VCL programs.
*
......@@ -451,6 +485,7 @@ static struct cli_proto vcl_cmds[] = {
{ CLI_VCL_LIST, "i", ccf_config_list },
{ CLI_VCL_DISCARD, "i", ccf_config_discard },
{ CLI_VCL_USE, "i", ccf_config_use },
{ CLI_VCL_SHOW, "i", ccf_config_show },
{ NULL }
};
......
......@@ -99,7 +99,6 @@ static struct cli_proto cli_proto[] = {
{ CLI_VCL_USE, "", mcf_config_use, NULL },
{ CLI_VCL_DISCARD, "", mcf_config_discard, NULL },
{ CLI_VCL_LIST, "", mcf_config_list, NULL },
{ CLI_VCL_SHOW, "", mcf_config_show, NULL },
{ CLI_PARAM_SHOW, "", mcf_param_show, NULL },
{ CLI_PARAM_SET, "", mcf_param_set, NULL },
{ CLI_PANIC_SHOW, "", mcf_panic_show, NULL },
......
......@@ -44,7 +44,6 @@ cli_func_t mcf_config_inline;
cli_func_t mcf_config_use;
cli_func_t mcf_config_discard;
cli_func_t mcf_config_list;
cli_func_t mcf_config_show;
/* stevedore.c */
extern struct cli_proto cli_stv[];
......@@ -672,35 +672,3 @@ mcf_config_list(struct cli *cli, const char * const *av, void *priv)
}
}
}
/*
* XXX: This should take an option argument to show all (include) files
* XXX: This violates the principle of not loading VCL's in the master
* XXX: process.
*/
void
mcf_config_show(struct cli *cli, const char * const *av, void *priv)
{
struct vclprog *vp;
void *dlh, *sym;
const char **src;
(void)priv;
if ((vp = mcf_find_vcl(cli, av[2])) != NULL) {
if ((dlh = dlopen(vp->fname, RTLD_NOW | RTLD_LOCAL)) == NULL) {
VCLI_Out(cli, "failed to load %s: %s\n",
vp->name, dlerror());
VCLI_SetResult(cli, CLIS_CANT);
} else if ((sym = dlsym(dlh, "srcbody")) == NULL) {
VCLI_Out(cli, "failed to locate source for %s: %s\n",
vp->name, dlerror());
VCLI_SetResult(cli, CLIS_CANT);
AZ(dlclose(dlh));
} else {
src = sym;
VCLI_Out(cli, "%s", src[0]);
/* VCLI_Out(cli, src[1]); */
AZ(dlclose(dlh));
}
}
}
......@@ -50,5 +50,6 @@ client c3 {
} -run
varnish v1 -cli "vcl.show vcl2"
varnish v1 -cli "vcl.show -v vcl2"
varnish v1 -cli "vcl.discard vcl2"
varnish v1 -cli "vcl.list"
......@@ -99,7 +99,7 @@
"vcl.show", \
"vcl.show <configname>", \
"\tDisplay the source code for the specified configuration.", \
1, 1
1, 2
#define CLI_VCL_USE \
"vcl.use", \
......
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