[master] dd1b997 Give the CLI command vcl.show a -v flag which outputs all the source files involved in a given VCL.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jul 24 09:04:42 CEST 2014


commit dd1b9971fd95e9eb4927bc35e186b7c1b02b06ce
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jul 24 07:00:26 2014 +0000

    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

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 7e73cfb..1678ea3 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -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.
  *
@@ -452,6 +486,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 }
 };
 
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 3d71a14..e7d7aa2 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -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 },
diff --git a/bin/varnishd/mgt/mgt_cli.h b/bin/varnishd/mgt/mgt_cli.h
index 5d3ce8b..4d04535 100644
--- a/bin/varnishd/mgt/mgt_cli.h
+++ b/bin/varnishd/mgt/mgt_cli.h
@@ -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[];
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 2c2ffd9..4d97de6 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -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));
-		}
-	}
-}
diff --git a/bin/varnishtest/tests/c00015.vtc b/bin/varnishtest/tests/c00015.vtc
index 5b09c8d..63edd3c 100644
--- a/bin/varnishtest/tests/c00015.vtc
+++ b/bin/varnishtest/tests/c00015.vtc
@@ -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"
diff --git a/include/vcli.h b/include/vcli.h
index 3294dd7..f6b75da 100644
--- a/include/vcli.h
+++ b/include/vcli.h
@@ -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",							\



More information about the varnish-commit mailing list