Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-file
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-file
Commits
40400658
Commit
40400658
authored
Sep 21, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the path parameter to the reader constructor.
parent
a585e9b0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
217 additions
and
13 deletions
+217
-13
.gitignore
.gitignore
+1
-0
README.rst
README.rst
+10
-2
path.vtc
src/tests/path.vtc
+152
-0
vmod_file.c
src/vmod_file.c
+51
-10
vmod_file.vcc
src/vmod_file.vcc
+3
-1
No files found.
.gitignore
View file @
40400658
...
...
@@ -38,5 +38,6 @@ Makefile.in
/src/tests/*.log
/src/tests/*.trs
/src/test-suite.log
/src/tests/pathtest
/src/coverage
README.rst
View file @
40400658
...
...
@@ -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 ...
...
...
src/tests/path.vtc
0 → 100644
View file @
40400658
# 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="");
}
}
src/vmod_file.c
View file @
40400658
...
...
@@ -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
;
...
...
src/vmod_file.vcc
View file @
40400658
...
...
@@ -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 ...
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment