PRIV_CALL issue in vmod

AD straightflush at gmail.com
Mon Sep 12 17:07:16 CEST 2011


hello,

 I am trying to use the PRIV_CALL capability of the vmods in order to cache
an expensive operation used later in the vcl itself.  I am running into an
issue where a PRIV_CALL is being re-used for each request acting more like
PRIV_VCL.  Not sure if i am missing a "free" call somewhere but the below
snippet reproduces the issue from my vmod.  When hitting varnish with
multiple different URLs the very first call logs "str is NULL" but every
other request logs "str is VALID" so priv->priv never gets unset for future
calls.

vcc file:
Init init_function
Function STRING get_str1(PRIV_CALL)
Function STRING get_str2(PRIV_CALL)

source file:
int init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
{

}

char * str_init(struct sess *sp, struct vmod_priv *priv) {

  char * str ;

  str = priv->priv;

  if (str == NULL) {
    syslog(LOG_INFO, "str is NULL, setting value\n");
    priv->priv = str = malloc(256);
    priv->priv = strdup("MY VALUE");
    priv->free = free ;
  }
  else {
    syslog(LOG_INFO, "str is VALID, returning value\n");
    return str;
  }

}

const char * vmod_get_str1(struct sess *sp, struct vmod_priv *priv) {
  return str_init(sp,priv);
}

const char * vmod_get_str2(struct sess *sp, struct vmod_priv *priv) {
  return str_init(sp,priv);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20110912/e5986a11/attachment-0003.html>


More information about the varnish-misc mailing list