Commit 40400658 authored by Geoff Simmons's avatar Geoff Simmons

Add the path parameter to the reader constructor.

parent a585e9b0
......@@ -38,5 +38,6 @@ Makefile.in
/src/tests/*.log
/src/tests/*.trs
/src/test-suite.log
/src/tests/pathtest
/src/coverage
......@@ -40,8 +40,16 @@ XXX ...
.. _file.reader():
new xreader = file.reader(STRING name, DURATION ttl=120)
--------------------------------------------------------
new xreader = file.reader(STRING name, STRING path, DURATION ttl)
-----------------------------------------------------------------
::
new xreader = file.reader(
STRING name,
STRING path="/usr/local/etc/varnish:/usr/local/share/varnish/vcl:/usr/etc/varnish:/usr/share/varnish/vcl",
DURATION ttl=120
)
XXX ...
......
# looks like -*- vcl -*-
varnishtest "path parameter for the reader constructor"
shell {echo -n "tmpdir" > ${tmpdir}/pathtest}
shell {echo -n "testdir" > ${testdir}/pathtest}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new tmp = file.reader("pathtest", path="${tmpdir}:${testdir}");
new test = file.reader("pathtest", path="${testdir}:${tmpdir}");
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.Tmp = tmp.get();
set resp.http.Test = test.get();
return (deliver);
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Tmp == "tmpdir"
expect resp.http.Test == "testdir"
} -run
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new tmp = file.reader("pathtest",
path="${tmpdir}/:${testdir}/");
new test = file.reader("pathtest",
path="${testdir}/:${tmpdir}/");
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.Tmp = tmp.get();
set resp.http.Test = test.get();
return (deliver);
}
}
client c1 -run
shell {echo -n "tmponly" > ${tmpdir}/pathtest}
shell {echo -n "testonly" > ${testdir}/pathtest}
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new tmp = file.reader("pathtest", path="${tmpdir}");
new test = file.reader("pathtest", path="${testdir}");
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.Tmp = tmp.get();
set resp.http.Test = test.get();
return (deliver);
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Tmp == "tmponly"
expect resp.http.Test == "testonly"
} -run
varnish v1 -vcl {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new tmp1 = file.reader("pathtest", path="${tmpdir}:");
new tmp2 = file.reader("pathtest", path=":${tmpdir}");
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.Tmp1 = tmp1.get();
set resp.http.Tmp2 = tmp2.get();
return (deliver);
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Tmp1 == "tmponly"
expect resp.http.Tmp2 == "tmponly"
} -run
shell {
touch ${tmpdir}/unreadable
chmod a-r ${tmpdir}/unreadable
}
varnish v1 -errvcl {new rdr: unreadable not found or not readable on path} {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("unreadable", path="${tmpdir}");
}
}
shell {rm -f ${tmpdir}/pathtest}
shell {rm -f ${testdir}/pathtest}
varnish v1 -errvcl {new rdr: pathtest not found or not readable on path} {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("pathtest", path="${tmpdir}:${testdir}");
}
}
varnish v1 -errvcl {new rdr: path is empty} {
import ${vmod_file};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new rdr = file.reader("pathtest", path="");
}
}
......@@ -44,6 +44,7 @@
#include "cache/cache.h"
#include "vcl.h"
#include "vtim.h"
#include "vsb.h"
#include "vcc_if.h"
......@@ -191,7 +192,7 @@ check(union sigval val)
VCL_VOID
vmod_reader__init(VRT_CTX, struct VPFX(file_reader) **rdrp,
const char *vcl_name, struct vmod_priv *priv,
VCL_STRING name, VCL_DURATION ttl)
VCL_STRING name, VCL_STRING path, VCL_DURATION ttl)
{
struct VPFX(file_reader) *rdr;
struct file_info *info;
......@@ -205,11 +206,7 @@ vmod_reader__init(VRT_CTX, struct VPFX(file_reader) **rdrp,
AN(vcl_name);
AN(priv);
if (name == NULL) {
VFAIL(ctx, "new %s: name is NULL", vcl_name);
return;
}
if (*name == '\0') {
if (name == NULL || *name == '\0') {
VFAIL(ctx, "new %s: name is empty", vcl_name);
return;
}
......@@ -234,6 +231,54 @@ vmod_reader__init(VRT_CTX, struct VPFX(file_reader) **rdrp,
return;
}
rdr->info = info;
rdr->vcl_name = strdup(vcl_name);
if (*name == '/')
info->path = strdup(name);
else {
struct vsb *search;
char *end, delim = ':';
AZ(info->path);
if (path == NULL || *path == '\0') {
VFAIL(ctx, "new %s: path is empty", vcl_name);
return;
}
search = VSB_new_auto();
for (const char *start = path; delim == ':'; VSB_clear(search),
start = end + 1) {
end = strchr(start, delim);
if (end == NULL) {
delim = '\0';
end = strchr(start, delim);
}
VSB_bcat(search, start, end - start);
if (*(end - 1) != '/')
VSB_putc(search, '/');
VSB_cat(search, name);
VSB_finish(search);
if (access(VSB_data(search), R_OK) != 0)
continue;
info->path = malloc(VSB_len(search) + 1);
if (info->path == NULL) {
VSB_destroy(&search);
VFAIL(ctx, "new %s: allocating path", vcl_name);
return;
}
strcpy(info->path, VSB_data(search));
break;
}
VSB_destroy(&search);
if (info->path == NULL) {
VFAIL(ctx, "new %s: %s not found or not readable on "
"path %s", vcl_name, name, path);
return;
}
}
errno = 0;
if (pthread_rwlock_init(&rdr->lock, NULL) != 0) {
VFAIL(ctx, "new %s: initializing lock: %s", vcl_name,
......@@ -250,10 +295,6 @@ vmod_reader__init(VRT_CTX, struct VPFX(file_reader) **rdrp,
return;
}
rdr->info = info;
rdr->vcl_name = strdup(vcl_name);
info->path = strdup(name);
memset(&sigev, 0, sizeof(sigev));
sigev.sigev_notify = SIGEV_THREAD;
sigev.sigev_notify_function = check;
......
......@@ -34,7 +34,9 @@ the new contents are read and cached, and are then available in VCL.
XXX ...
$Object reader(PRIV_VCL, STRING name, DURATION ttl=120)
$Object reader(PRIV_VCL, STRING name,
STRING path="/usr/local/etc/varnish:/usr/local/share/varnish/vcl:/usr/etc/varnish:/usr/share/varnish/vcl",
DURATION ttl=120)
XXX ...
......
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