vcl_init, VMODs & workspaces

Dridi Boukelmoune dridi at varni.sh
Wed May 4 09:13:27 CEST 2016


> This would be trivial stuff outside of vcl_init (i.e. return WS_Copy(ctx->ws, "whatever", -1)), but ctx->ws is not available during vcl_init. Is there any friendly alternative not requiring the VMOD doing explicit mallocs when returning strings, keeping track of returned pointers, and releasing them when execution of vcl_init is completed?

Hi Carlos,

There's no escape to explicit (m)allocs, but Varnish can help you
keeping track of your allocations.

If you decilare an $Event [1] function in your VCC file you will
receive at LOAD-time a PRIV_VCL private pointer [2] to track per-VCL
data. This can be used by your module for functions that need to
allocate during vcl_init{} but there's no END-OF-INIT event you could
catch to free this state early, so unless you provide a specific
function to do the cleaning, your free callback will be called later
when the VCL is discarded.

Cheers,
Dridi

[1] https://www.varnish-cache.org/docs/4.1/reference/vmod.html#event-functions
[2] https://www.varnish-cache.org/docs/4.1/reference/vmod.html#private-pointers



More information about the varnish-dev mailing list