Commit 6d4447ce authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add support for PRIV_TASK in CLI induced VCL events.

See also: #2061
parent 2679527a
......@@ -127,6 +127,7 @@ vcl_rel_ctx(struct vrt_ctx **ctx)
WS_Reset(&ws_cli, ws_snapshot_cli);
INIT_OBJ(*ctx, VRT_CTX_MAGIC);
*ctx = NULL;
VRTPRIV_dynamic_kill(NULL, 0);
}
/*--------------------------------------------------------------------*/
......
......@@ -48,23 +48,27 @@ struct vrt_priv {
uintptr_t vmod_id;
};
struct vmod_priv cli_task_priv;
/*--------------------------------------------------------------------
*/
void
VRTPRIV_init(struct vrt_privs *privs)
{
privs->magic = VRT_PRIVS_MAGIC;
INIT_OBJ(privs, VRT_PRIVS_MAGIC);
VTAILQ_INIT(&privs->privs);
}
static struct vmod_priv *
VRT_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
vrt_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
{
struct vrt_privs *vps;
struct vrt_priv *vp;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vmod_id);
if (ctx->req) {
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
......@@ -94,7 +98,13 @@ VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id)
{
struct vrt_priv *vp, *vp1;
if (privs == NULL && id == 0) {
ASSERT_CLI();
VRT_priv_fini(&cli_task_priv);
return;
}
CHECK_OBJ_NOTNULL(privs, VRT_PRIVS_MAGIC);
AN(id);
VTAILQ_FOREACH_SAFE(vp, &privs->privs, list, vp1) {
CHECK_OBJ_NOTNULL(vp, VRT_PRIV_MAGIC);
......@@ -118,9 +128,11 @@ VRT_priv_task(VRT_CTX, void *vmod_id)
} else if (ctx->bo) {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
id = (uintptr_t)ctx->bo;
} else
WRONG("PRIV_TASK is only accessible in client or backend VCL contexts");
return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
} else {
ASSERT_CLI();
return (&cli_task_priv);
}
return (vrt_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
}
struct vmod_priv *
......@@ -133,7 +145,7 @@ VRT_priv_top(VRT_CTX, void *vmod_id)
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->top, REQ_MAGIC);
id = (uintptr_t)&ctx->req->top->top;
return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
return (vrt_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
} else
WRONG("PRIV_TOP is only accessible in client VCL context");
NEEDLESS_RETURN(NULL);
......@@ -146,6 +158,6 @@ void
VRT_priv_fini(const struct vmod_priv *p)
{
if (p->priv != (void*)0 && p->free != (void*)0)
if (p->priv != NULL && p->free != NULL)
p->free(p->priv);
}
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