[master] ea1aa68f9 param: Add a %n expansion to cc_command

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jan 3 14:13:06 UTC 2022


commit ea1aa68f9dd4cb4dbd850abb51ef75de749c95ee
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Dec 14 10:46:36 2021 +0100

    param: Add a %n expansion to cc_command

diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index d32894b64..ec9b997b7 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -33,6 +33,7 @@
 
 #include "config.h"
 
+#include <limits.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -131,6 +132,7 @@ run_vcc(void *priv)
 static const char *
 cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 {
+	char buf[PATH_MAX];
 	const char *p;
 	int pct;
 
@@ -157,6 +159,10 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
 					return ("recursive expansion");
 				cc_expand(sb, mgt_cc_cmd_def, pct);
 				break;
+			case 'n':
+				AN(getcwd(buf, sizeof buf));
+				VSB_cat(sb, buf);
+				break;
 			case '%':
 				VSB_putc(sb, '%');
 				break;
@@ -191,8 +197,6 @@ run_cc(void *priv)
 	VJ_subproc(JAIL_SUBPROC_CC);
 	CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC);
 
-	AZ(chdir(VSB_data(vp->dir)));
-
 	sb = VSB_new_auto();
 	AN(sb);
 	err = cc_expand(sb, mgt_cc_cmd, '\0');
@@ -203,6 +207,8 @@ run_cc(void *priv)
 	}
 	AZ(VSB_finish(sb));
 
+	AZ(chdir(VSB_data(vp->dir)));
+
 	(void)umask(027);
 	(void)execl("/bin/sh", "/bin/sh", "-c", VSB_data(sb), (char*)0);
 	VSB_destroy(&sb);				// For flexelint
diff --git a/bin/varnishtest/tests/c00109.vtc b/bin/varnishtest/tests/c00109.vtc
index 5321aa43f..7c4a7463d 100644
--- a/bin/varnishtest/tests/c00109.vtc
+++ b/bin/varnishtest/tests/c00109.vtc
@@ -3,9 +3,11 @@ varnishtest "cc_command and cc_warnings"
 varnish v1 -cliok {param.set debug +vcl_keep}
 varnish v1 -cliok {param.set cc_warnings hello}
 varnish v1 -cliok {param.set cc_command << EOF
-! printf 'd="%%s" D="%%s" w="%%s"' '%d' '%D' '%w' >world
+! printf 'd="%%s" D="%%s" w="%%s" n="%%s"' '%d' '%D' '%w' '%n' >world
 EOF}
 
 varnish v1 -errvcl "VCL compilation failed" "backend be none;"
 
-shell -match {d=".+" D=".+hello.+" w="hello"} "cat v1/vcl_*/world"
+shell -match {d=".+" D=".+hello.+" w="hello" n="${v1_name}"} {
+	exec cat v1/vcl_*/world
+}
diff --git a/include/tbl/params.h b/include/tbl/params.h
index 6ad2cbe4d..a96b5225f 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1538,6 +1538,7 @@ PARAM_STRING(
 	"- %w: the cc_warnings parameter\n"
 	"- %d: the raw default cc_command\n"
 	"- %D: the expanded default cc_command\n"
+	"- %n: the working directory (-n option)\n"
 	"- %%: a percent sign\n"
 	"\n"
 	"Unknown percent expansion sequences are ignored, and to "


More information about the varnish-commit mailing list