Mailing List Archive

[master] 624745ccf param: Expand %d to the default cc_command
commit 624745ccf2940f339e9ccc3bbeadd83d2e551f21
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Tue Dec 7 08:33:18 2021 +0100

param: Expand %d to the default cc_command

This is useful for shell script wrappers that can take the original
command as an argument as well as the %{o,s,w} expansions as additional
parameters.

diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 93a9989de..9065d9eaa 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -233,6 +233,7 @@ void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin,
int mgt_push_vcls(struct cli *, unsigned *status, char **p);
const char *mgt_has_vcl(void);
extern char *mgt_cc_cmd;
+extern char *mgt_cc_cmd_def;
extern char *mgt_cc_warn;
extern const char *mgt_vcl_path;
extern const char *mgt_vmod_path;
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 2b4c293ca..fd77e2942 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -765,6 +765,9 @@ MCF_InitParams(struct cli *cli)
mcf_wash_param(cli, pp, MCF_DEFAULT, "default", vsb);
}
VSB_destroy(&vsb);
+
+ AN(mgt_cc_cmd);
+ REPLACE(mgt_cc_cmd_def, mgt_cc_cmd);
}

/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index 0229e0cbc..97a884ba2 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -63,6 +63,7 @@ struct vcc_priv {
};

char *mgt_cc_cmd;
+char *mgt_cc_cmd_def;
char *mgt_cc_warn;
const char *mgt_vcl_path;
const char *mgt_vmod_path;
@@ -154,6 +155,9 @@ run_cc(void *priv)
case 'w':
VSB_cat(sb, mgt_cc_warn);
break;
+ case 'd':
+ VSB_cat(sb, mgt_cc_cmd_def);
+ break;
case '%':
VSB_putc(sb, '%');
break;
diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc
index 9574d151d..40d451296 100644
--- a/bin/varnishtest/tests/c00109.vtc
+++ b/bin/varnishtest/tests/c00109.vtc
@@ -1,9 +1,11 @@
varnishtest "cc_command and cc_warnings"

varnish v1 -cliok {param.set debug +vcl_keep}
-varnish v1 -cliok {param.set cc_command "! printf '%w' >world"}
varnish v1 -cliok {param.set cc_warnings hello}
+varnish v1 -cliok {param.set cc_command << EOF
+! printf 'd="%%s" w="%%s"' '%d' '%w' >world
+EOF}

varnish v1 -errvcl "VCL compilation failed" "backend be none;"

-shell -expect hello "cat v1/vcl_*/world"
+shell -match {d=".+" w="hello"} "cat v1/vcl_*/world"
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 20929d823..1fb9c9423 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1534,7 +1534,8 @@ PARAM_STRING(
"dlopen(3) loadable object. Any occurrence of %s in "
"the string will be replaced with the source file name, "
"%o will be replaced with the output file name, and %w "
- "will be replaced by the cc_warnings parameter.",
+ "will be replaced by the cc_warnings parameter. The %d "
+ "sequence expands to the default value for cc_command.",
/* flags */ MUST_RELOAD | BUILD_OPTIONS,
/* dyn_min_reason */ NULL,
/* dyn_max_reason */ NULL,
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit