Commit 8e58c809 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add vcl_init() and vcl_fini() methods which are called when a VCL

after a vcl file is loaded and before it is discarded.

The major use will probably be to tell VMODs things like filenames.

Requested by:	geoff & DocWilco
parent 4e00e65c
......@@ -172,12 +172,13 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
}
REPLACE(vcl->name, name);
VTAILQ_INSERT_TAIL(&vcl_head, vcl, list);
cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
vcl->conf->init_vcl(cli);
(void)vcl->conf->init_func(NULL);
Lck_Lock(&vcl_mtx);
if (vcl_active == NULL)
vcl_active = vcl;
Lck_Unlock(&vcl_mtx);
cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
vcl->conf->init_func(cli);
VSC_main->n_vcl++;
VSC_main->n_vcl_avail++;
return (0);
......@@ -197,7 +198,8 @@ VCL_Nuke(struct vcls *vcl)
assert(vcl->conf->discard);
assert(vcl->conf->busy == 0);
VTAILQ_REMOVE(&vcl_head, vcl, list);
vcl->conf->fini_func(NULL);
(void)vcl->conf->fini_func(NULL);
vcl->conf->fini_vcl(NULL);
free(vcl->name);
(void)dlclose(vcl->dlh);
FREE_OBJ(vcl);
......
......@@ -71,6 +71,8 @@ void
VRT_count(const struct sess *sp, unsigned u)
{
if (sp == NULL)
return;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (params->vcl_trace)
WSP(sp, SLT_VCL_trace, "%u %d.%d", u,
......@@ -240,6 +242,10 @@ void
VRT_handling(struct sess *sp, unsigned hand)
{
if (sp == NULL) {
assert(hand == VCL_RET_OK);
return;
}
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
assert(hand < VCL_RET_MAX);
sp->handling = hand;
......
......@@ -139,3 +139,11 @@ sub vcl_error {
"};
return (deliver);
}
sub vcl_init {
return (ok);
}
sub vcl_fini {
return (ok);
}
......@@ -166,17 +166,22 @@ vsb_newbuf(struct vsb *s, char *buf, int length, int flags)
{
memset(s, 0, sizeof(*s));
s->s_flags = flags;
s->s_magic = VSB_MAGIC;
s->s_flags = flags;
s->s_size = length;
s->s_buf = buf;
if (buf != NULL) {
s->s_size = length;
s->s_buf = buf;
return (s);
if ((s->s_flags & VSB_AUTOEXTEND) == 0) {
KASSERT(s->s_size > 1,
("attempt to create a too small vsb"));
}
s->s_size = length;
if (s->s_buf != NULL)
return (s);
if ((flags & VSB_AUTOEXTEND) != 0)
s->s_size = vsb_extendsize(s->s_size);
s->s_buf = SBMALLOC(s->s_size);
if (s->s_buf == NULL)
return (NULL);
......@@ -243,7 +248,7 @@ vsb_setpos(struct vsb *s, ssize_t pos)
("attempt to seek to a negative position (%jd)", (intmax_t)pos));
KASSERT(pos < s->s_size,
("attempt to seek past end of vsb (%jd >= %jd)",
(intmax_t)pos, (intmax_t)->s_size));
(intmax_t)pos, (intmax_t)s->s_size));
if (pos < 0 || pos > s->s_len)
return (-1);
......
......@@ -92,6 +92,8 @@ returns =(
('fetch', ('error', 'restart', 'hit_for_pass', 'deliver',)),
('deliver', ('restart', 'deliver',)),
('error', ('restart', 'deliver',)),
('init', ('ok',)),
('fini', ('ok',)),
)
#######################################################################
......@@ -750,8 +752,8 @@ struct VCL_conf {
const char **srcname;
const char **srcbody;
vcl_init_f *init_func;
vcl_fini_f *fini_func;
vcl_init_f *init_vcl;
vcl_fini_f *fini_vcl;
""")
for i in returns:
......
......@@ -366,8 +366,8 @@ EmitStruct(const struct vcc *tl)
Fc(tl, 0, "\nconst struct VCL_conf VCL_conf = {\n");
Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n");
Fc(tl, 0, "\t.init_func = VGC_Init,\n");
Fc(tl, 0, "\t.fini_func = VGC_Fini,\n");
Fc(tl, 0, "\t.init_vcl = VGC_Init,\n");
Fc(tl, 0, "\t.fini_vcl = VGC_Fini,\n");
Fc(tl, 0, "\t.ndirector = %d,\n", tl->ndirector);
Fc(tl, 0, "\t.director = directors,\n");
Fc(tl, 0, "\t.ref = VGC_ref,\n");
......
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