Commit ea1aa68f authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

param: Add a %n expansion to cc_command

parent b328f7f7
......@@ -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
......
......@@ -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
}
......@@ -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 "
......
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