Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCC: Fix +glob with relative path #4250

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/varnishtest/tests/c00053.vtc
Original file line number Diff line number Diff line change
@@ -67,3 +67,35 @@ client c1 {
expect resp.http.foo == foo
expect resp.http.bar == bar
} -run

shell {
rm ${tmpdir}/top.vcl
mkdir -p ${tmpdir}/vclpath/vcl1
mkdir -p ${tmpdir}/vclpath/vcl2
echo 'sub vcl_synth { set resp.http.foo = "vcl1"; }' > ${tmpdir}/vclpath/vcl1/sub_foo.vcl
echo 'sub vcl_synth { set resp.http.bar = "vcl2"; }' > ${tmpdir}/vclpath/vcl2/sub_bar.vcl
cat > ${tmpdir}/vclpath/top.vcl <<-EOF
vcl 4.1;

backend default {
.host = "0:0";
}

include +glob "vcl*/sub_*.vcl";

sub vcl_recv {
return (synth(200));
}
EOF
}

varnish v1 -cliok "param.set vcl_path ${tmpdir}/vclpath"
varnish v1 -cliok "vcl.load globtest top.vcl"
varnish v1 -cliok "vcl.use globtest"

client c1 {
txreq
rxresp
expect resp.http.foo == vcl1
expect resp.http.bar == vcl2
} -run
1 change: 1 addition & 0 deletions include/vfil.h
Original file line number Diff line number Diff line change
@@ -45,4 +45,5 @@ void VFIL_setpath(struct vfil_path**, const char *path);
typedef int vfil_path_func_f(void *priv, const char *fn);
int VFIL_searchpath(const struct vfil_path *, vfil_path_func_f *func,
void *priv, const char *fni, char **fno);
char **VFIL_concat(const struct vfil_path *vp, const char *name);

28 changes: 28 additions & 0 deletions lib/libvarnish/vfil.c
Original file line number Diff line number Diff line change
@@ -387,3 +387,31 @@ VFIL_searchpath(const struct vfil_path *vp, vfil_path_func_f *func, void *priv,
VSB_destroy(&vsb);
return (-1);
}

char **
VFIL_concat(const struct vfil_path *vp, const char *name)
{
struct vsb *vsb;
struct vfil_dir *vd;
char **arr;
int len = 0;

CHECK_OBJ_NOTNULL(vp, VFIL_PATH_MAGIC);
AN(name);

vsb = VSB_new_auto();
AN(vsb);
VTAILQ_FOREACH(vd, &vp->paths, list)
len++;
arr = calloc(len + 1, sizeof(char*));
len = 0;
VTAILQ_FOREACH(vd, &vp->paths, list) {
VSB_clear(vsb);
VSB_printf(vsb, "%s/%s", vd->dir, name);
AZ(VSB_finish(vsb));
arr[len++] = strdup(VSB_data(vsb));
}
arr[len] = NULL;
VSB_destroy(&vsb);
return (arr);
}
15 changes: 15 additions & 0 deletions lib/libvcc/vcc_source.c
Original file line number Diff line number Diff line change
@@ -107,9 +107,24 @@ vcc_include_glob_file(struct vcc *tl, const struct source *src_sp,
const char *filename, const struct token *parent_token)
{
glob_t g[1];
char **paths, **p;
unsigned u;
int i;

if (filename[0] != '/') {
paths = VFIL_concat(tl->vcl_path, filename);
p = paths;
while (*p != NULL) {
assert(*p[0] == '/');
vcc_include_glob_file(tl, src_sp, *p, parent_token);
free(*p);
*p = NULL;
p++;
}
free(paths);
return;
}

memset(g, 0, sizeof g);
i = glob(filename, 0, NULL, g);
switch (i) {
Loading