Commit ea1aa68f authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

param: Add a %n expansion to cc_command

parent b328f7f7
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "config.h" #include "config.h"
#include <limits.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -131,6 +132,7 @@ run_vcc(void *priv) ...@@ -131,6 +132,7 @@ run_vcc(void *priv)
static const char * static const char *
cc_expand(struct vsb *sb, const char *cc_cmd, char exp) cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
{ {
char buf[PATH_MAX];
const char *p; const char *p;
int pct; int pct;
...@@ -157,6 +159,10 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp) ...@@ -157,6 +159,10 @@ cc_expand(struct vsb *sb, const char *cc_cmd, char exp)
return ("recursive expansion"); return ("recursive expansion");
cc_expand(sb, mgt_cc_cmd_def, pct); cc_expand(sb, mgt_cc_cmd_def, pct);
break; break;
case 'n':
AN(getcwd(buf, sizeof buf));
VSB_cat(sb, buf);
break;
case '%': case '%':
VSB_putc(sb, '%'); VSB_putc(sb, '%');
break; break;
...@@ -191,8 +197,6 @@ run_cc(void *priv) ...@@ -191,8 +197,6 @@ run_cc(void *priv)
VJ_subproc(JAIL_SUBPROC_CC); VJ_subproc(JAIL_SUBPROC_CC);
CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC); CAST_OBJ_NOTNULL(vp, priv, VCC_PRIV_MAGIC);
AZ(chdir(VSB_data(vp->dir)));
sb = VSB_new_auto(); sb = VSB_new_auto();
AN(sb); AN(sb);
err = cc_expand(sb, mgt_cc_cmd, '\0'); err = cc_expand(sb, mgt_cc_cmd, '\0');
...@@ -203,6 +207,8 @@ run_cc(void *priv) ...@@ -203,6 +207,8 @@ run_cc(void *priv)
} }
AZ(VSB_finish(sb)); AZ(VSB_finish(sb));
AZ(chdir(VSB_data(vp->dir)));
(void)umask(027); (void)umask(027);
(void)execl("/bin/sh", "/bin/sh", "-c", VSB_data(sb), (char*)0); (void)execl("/bin/sh", "/bin/sh", "-c", VSB_data(sb), (char*)0);
VSB_destroy(&sb); // For flexelint VSB_destroy(&sb); // For flexelint
......
...@@ -3,9 +3,11 @@ varnishtest "cc_command and cc_warnings" ...@@ -3,9 +3,11 @@ varnishtest "cc_command and cc_warnings"
varnish v1 -cliok {param.set debug +vcl_keep} varnish v1 -cliok {param.set debug +vcl_keep}
varnish v1 -cliok {param.set cc_warnings hello} varnish v1 -cliok {param.set cc_warnings hello}
varnish v1 -cliok {param.set cc_command << EOF 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} EOF}
varnish v1 -errvcl "VCL compilation failed" "backend be none;" 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
}
...@@ -1538,6 +1538,7 @@ PARAM_STRING( ...@@ -1538,6 +1538,7 @@ PARAM_STRING(
"- %w: the cc_warnings parameter\n" "- %w: the cc_warnings parameter\n"
"- %d: the raw default cc_command\n" "- %d: the raw default cc_command\n"
"- %D: the expanded default cc_command\n" "- %D: the expanded default cc_command\n"
"- %n: the working directory (-n option)\n"
"- %%: a percent sign\n" "- %%: a percent sign\n"
"\n" "\n"
"Unknown percent expansion sequences are ignored, and to " "Unknown percent expansion sequences are ignored, and to "
......
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