[PATCH] fileread for the std VMOD

Sanjoy Das sanjoy at playingwithpointers.com
Wed Nov 10 07:55:54 CET 2010


Hi All!

I've been toying around with Varnish's source for some time and have
been looking for small tasks to get me started with the same. With
PHK's suggestion, I've implemented a small addition to the std VMOD
which reads (and caches) a file. I've attached the patch
(fileread-std-vmod.diff) for review. Once applied, it should allow VCL
to do things like

set resp.http.Some-Header = std.fileread("/tmp/foo");

It loads and caches the contents of "/tmp/foo" in memory and returns
the same; refreshing it whenever the file changes on disk.

While working on the above I ran into a small problem with the import
statement - VCC does not seem to like `import std':

'''
Message from VCC-compiler:
Could not load module std
        XXX: XXX: no default path
        XXX: XXX: no default path: cannot open shared object file: No
such file or directory
('input' Line 1 Pos 8)
import std;
-------###-

Running VCC-compiler failed, exit 1
'''

I fixed this by having VCC (I know that I may be way off on this one):

  i. Load libvmod_std.so automagically for `import std;'
 ii. Requiring something like `import foo
"mysuperdupersharedobject.so";' for other VMODs.
iii. Allow the same convention (ii) for std as well.

This is done by the other patch I've attached (vmod-load-so.diff).
Once applied, it makes VCC accept any of the following:

import std; /* dlopen libvmod_std.so as std automatically */
import std "some_other_std.so"; /* dlopen some_other_std.so as std */
import foo "foo.so"; /* dlopen foo.so and use it as VMOD foo */

Both patches are diffs against SVN revision 5531.

-- 
Regards,

Sanjoy Das.

http://playingwithpointers.com

Public Key at http://playingwithpointers.com/custom/public_key.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vmod-load-so.diff
Type: text/x-patch
Size: 965 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20101110/95e12d97/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fileread-std-vmod.diff
Type: text/x-patch
Size: 3215 bytes
Desc: not available
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20101110/95e12d97/attachment-0007.bin>


More information about the varnish-dev mailing list