[master] 19b20a88f vcl: Add support for vcl.discard glob patterns
Nils Goroll
nils.goroll at uplex.de
Tue Jan 12 15:34:07 UTC 2021
commit 19b20a88f8d6f59c676ee922d53a10c398785d82
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Dec 8 12:19:06 2020 +0100
vcl: Add support for vcl.discard glob patterns
diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c
index 84ac7fada..705de26ce 100644
--- a/bin/varnishd/mgt/mgt_vcl.c
+++ b/bin/varnishd/mgt/mgt_vcl.c
@@ -33,6 +33,7 @@
#include "config.h"
+#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -686,13 +687,13 @@ mgt_vcl_discard(struct cli *cli, struct vclproghead *vh, struct vclprog *vp)
}
static int
-mgt_vcl_discard_mark(struct cli *cli, struct vclproghead *vh, const char *name)
+mgt_vcl_discard_mark(struct cli *cli, struct vclproghead *vh, const char *glob)
{
struct vclprog *vp;
unsigned marked = 0;
VTAILQ_FOREACH(vp, &vclhead, list) {
- if (strcmp(name, vp->name))
+ if (fnmatch(glob, vp->name, 0))
continue;
if (vp == active_vcl) {
VCLI_SetResult(cli, CLIS_CANT);
@@ -708,7 +709,7 @@ mgt_vcl_discard_mark(struct cli *cli, struct vclproghead *vh, const char *name)
if (marked == 0) {
VCLI_SetResult(cli, CLIS_PARAM);
- VCLI_Out(cli, "No VCL named %s known\n", name);
+ VCLI_Out(cli, "No VCL name matches %s\n", glob);
}
return (marked);
diff --git a/bin/varnishtest/tests/c00077.vtc b/bin/varnishtest/tests/c00077.vtc
index f176bc948..e056dd986 100644
--- a/bin/varnishtest/tests/c00077.vtc
+++ b/bin/varnishtest/tests/c00077.vtc
@@ -64,5 +64,6 @@ varnish v1 -clierr 106 "vcl.label vclA vcl3"
varnish v1 -cliok "vcl.symtab"
-varnish v1 -clierr 300 "vcl.discard vcl1 vcl2 vcl3 vcl4 vcl5 vcl6 vcl7"
-varnish v1 -cliok "vcl.discard vcl1 vcl2 vcl3 vcl4 vcl5 vcl6 vcl7 vclA vclB"
+varnish v1 -clierr 300 "vcl.discard vcl*"
+varnish v1 -clierr 300 "vcl.discard vcl[1-7]"
+varnish v1 -cliok "vcl.discard vcl[1-7A-B]"
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 02d853b68..7249f8dd7 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -99,11 +99,13 @@ CLI_CMD(VCL_STATE,
CLI_CMD(VCL_DISCARD,
"vcl.discard",
- "vcl.discard <configname|label>...", /* XXX: allow globs */
+ "vcl.discard <configname|label>...",
"Unload the named configurations (if possible).",
- " If more than one named configuration is specified the command"
+ "The configname or label arguments are matched as glob patterns."
+ " If more than one configuration matches patterns the command"
" is equivalent to individual commands in the right order with"
- " respect to configurations dependencies.",
+ " respect to configurations dependencies."
+ " All individual patterns must match at least one configuration.",
1, -1
)
More information about the varnish-commit
mailing list