int main(int argc, char **argv) { int o; struct VSM_data *vd; vd = VSM_New(); VSL_Setup(vd); while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) { switch (o) { case 'V': VCS_Message("varnishhist"); exit(0); case 'w': delay = atoi(optarg); break; default: if (VSL_Arg(vd, o, optarg) > 0) break; usage(); } } if (VSL_Open(vd, 1)) exit(1); log_ten = log(10.0); do_curses(vd); exit(0); }
static void * varnishlog_thread(void *priv) { struct varnish *v; struct VSM_data *vsl; CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC); vsl = VSM_New(); VSL_Setup(vsl); (void)VSL_Arg(vsl, 'n', v->workdir); VSL_NonBlocking(vsl, 1); while (v->pid && VSL_Open(vsl, 0) != 0) { assert(usleep(VSL_SLEEP_USEC) == 0 || errno == EINTR); } while (v->pid) { if (VSL_Dispatch(vsl, h_addlog, v) < 0) { assert(usleep(v->vsl_sleep) == 0 || errno == EINTR); v->vsl_sleep += v->vsl_sleep; if (v->vsl_sleep > VSL_SLEEP_USEC) v->vsl_sleep = VSL_SLEEP_USEC; } } VSM_Delete(vsl); return (NULL); }
ban_lurker(struct worker *wrk, void *priv) { struct vsl_log vsl; volatile double d; unsigned gen = ban_generation + 1; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); AZ(priv); VSL_Setup(&vsl, NULL, 0); while (!ban_shutdown) { d = ban_lurker_work(wrk, &vsl); ban_cleantail(); if (DO_DEBUG(DBG_LURKER)) VSLb(&vsl, SLT_Debug, "lurker: sleep = %lf", d); d += VTIM_real(); Lck_Lock(&ban_mtx); if (gen == ban_generation) { (void)Lck_CondWait(&ban_lurker_cond, &ban_mtx, d); ban_batch = 0; } gen = ban_generation; Lck_Unlock(&ban_mtx); } pthread_exit(0); NEEDLESS_RETURN(NULL); }
void SES_GetReq(struct sess *sp) { struct sesspool *pp; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); AZ(sp->req); sp->req = MPL_Get(pp->mpl_req, &sz); AN(sp->req); sp->req->magic = REQ_MAGIC; e = (char*)sp->req + sz; p = (char*)(sp->req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); sp->req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sp->req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sp->req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->workspace_thread; VSL_Setup(sp->req->vsl, p, sz); sp->req->vsl->wid = sp->vsl_id; p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(sp->req->ws, "req", p, e - p); }
exp_thread(struct worker *wrk, void *priv) { struct objcore *oc; double t = 0, tnext = 0; struct exp_priv *ep; unsigned flags = 0; CAST_OBJ_NOTNULL(ep, priv, EXP_PRIV_MAGIC); ep->wrk = wrk; VSL_Setup(&ep->vsl, NULL, 0); ep->heap = binheap_new(NULL, object_cmp, object_update); AN(ep->heap); while (1) { Lck_Lock(&ep->mtx); oc = VSTAILQ_FIRST(&ep->inbox); CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC); if (oc != NULL) { assert(oc->refcnt >= 1); VSTAILQ_REMOVE(&ep->inbox, oc, objcore, exp_list); VSC_C_main->exp_received++; tnext = 0; flags = oc->exp_flags; if (flags & OC_EF_REMOVE) oc->exp_flags = 0; else oc->exp_flags &= OC_EF_REFD; } else if (tnext > t) { VSL_Flush(&ep->vsl, 0); Pool_Sumstat(wrk); (void)Lck_CondWait(&ep->condvar, &ep->mtx, tnext); } Lck_Unlock(&ep->mtx); t = VTIM_real(); if (oc != NULL) exp_inbox(ep, oc, flags); else tnext = exp_expire(ep, t); } NEEDLESS(return NULL); }
struct busyobj * VBO_GetBusyObj(struct worker *wrk, const struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; unsigned sz; char *p; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); if (wrk->nbo != NULL) { bo = wrk->nbo; wrk->nbo = NULL; } if (bo == NULL) bo = vbo_New(); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); AZ(bo->refcount); bo->refcount = 1; p = (void*)(bo + 1); p = (void*)PRNDUP(p); assert(p < bo->end); nhttp = (uint16_t)cache_param->http_max_hdr; sz = HTTP_estimate(nhttp); bo->bereq0 = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->bereq = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->beresp = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); sz = cache_param->vsl_buffer; VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(wrk, VSL_BACKENDMARKER); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); WS_Init(bo->ws, "bo", p, bo->end - p); bo->do_stream = 1; bo->director = req->director_hint; bo->vcl = req->vcl; VCL_Ref(bo->vcl); bo->t_first = bo->t_prev = NAN; bo->content_length = -1; bo->doclose = SC_NULL; return (bo); }
struct busyobj * VBO_GetBusyObj(struct worker *wrk, struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; unsigned sz; char *p; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); if (wrk->nbo != NULL) { bo = wrk->nbo; wrk->nbo = NULL; } if (bo == NULL) bo = vbo_New(); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); AZ(bo->refcount); bo->refcount = 1; p = (void*)(bo + 1); p = (void*)PRNDUP(p); assert(p < bo->end); nhttp = (uint16_t)cache_param->http_max_hdr; sz = HTTP_estimate(nhttp); bo->bereq0 = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->bereq = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->beresp = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); sz = cache_param->vsl_buffer; VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_BACKENDMARKER; VSLb(bo->vsl, SLT_Begin, "bereq %u", req->vsl->wid & VSL_IDENTMASK); VSLb(req->vsl, SLT_Link, "bereq %u", bo->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); WS_Init(bo->ws, "bo", p, bo->end - p); bo->do_stream = 1; bo->director = req->director; bo->vcl = req->vcl; VCL_Ref(bo->vcl); bo->t_fetch = req->t_req; return (bo); }
struct req * SES_GetReq(const struct worker *wrk, struct sess *sp) { struct sesspool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->req_bodybytes = 0; req->resp_hdrbytes = 0; req->resp_bodybytes = 0; req->t_first = NAN; req->t_prev = NAN; req->t_req = NAN; return (req); }
struct req * Req_New(const struct worker *wrk, struct sess *sp) { struct pool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->pool; CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); p += sz; p = (void*)PRNDUP(p); req->vfc = (void*)p; INIT_OBJ(req->vfc, VFP_CTX_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->vfc)); req->htc = (void*)p; p = (void*)PRNDUP(p + sizeof(*req->htc)); req->vdc = (void*)p; INIT_OBJ(req->vdc, VDP_CTX_MAGIC); VTAILQ_INIT(&req->vdc->vdp); p = (void*)PRNDUP(p + sizeof(*req->vdc)); req->htc = (void*)p; INIT_OBJ(req->htc, HTTP_CONN_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->htc)); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->t_first = NAN; req->t_prev = NAN; req->t_req = NAN; req->topreq = req; return (req); }
static unsigned int vlog_reply(struct httpd_request *request, void *data) { struct vlog_priv_t *vlog; int ret; char *limit = NULL; char *p; char *tag = NULL; char *itag = NULL; struct agent_core_t *core = data; GET_PRIV(data,vlog); p = next_slash(request->url + 1); assert(vlog->tag==NULL); assert(vlog->answer == NULL); if (p) { limit = strdup(p); assert(limit); char *tmp2 = index(limit,'/'); if (tmp2 && *tmp2) *tmp2 = '\0'; if(!(atoi(limit) > 0)) { free(limit); send_response_fail(request->connection,"Not a number"); return 0; } p = next_slash(p); } if (p) { tag = strdup(p); char *tmp2 = index(tag,'/'); if (tmp2 && *tmp2) *tmp2 = '\0'; p = next_slash(p); } if (p) { itag = strdup(p); char *tmp2 = index(itag,'/'); if (tmp2 && *tmp2) *tmp2 = '\0'; p = next_slash(p); } vlog->answer = VSB_new_auto(); assert(vlog->answer != NULL); vlog->vd = VSM_New(); assert(VSL_Arg(vlog->vd, 'n', core->config->n_arg)); VSL_Setup(vlog->vd); VSL_Arg(vlog->vd, 'd', ""); if (tag) { VSL_Arg(vlog->vd, 'i', tag); if (itag) VSL_Arg(vlog->vd,'I',itag); } else { VSL_Arg(vlog->vd, 'k', limit ? limit : "10"); } if (limit) free(limit); VSB_printf(vlog->answer, "{ \"log\": ["); ret = VSL_Open(vlog->vd, 1); assert(!ret); if (tag == NULL) { do_order(vlog); } else { do_unorder(vlog); } if (tag) free(tag); if (itag) free(itag); VSB_printf(vlog->answer, "\n] }\n"); assert(VSB_finish(vlog->answer) == 0); if (VSB_len(vlog->answer) > 1) { send_response(request->connection, 200, VSB_data(vlog->answer), VSB_len(vlog->answer)); } else { send_response_fail(request->connection, "FAIL"); } VSB_clear(vlog->answer); VSM_Close(vlog->vd); vlog->answer = NULL; vlog->entries = 0; return 0; }
struct req * SES_GetReq(struct worker *wrk, struct sess *sp) { struct sesspool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER; VSLb(req->vsl, SLT_Begin, "req %u", sp->vxid & VSL_IDENTMASK); VSL(SLT_Link, req->sp->vxid, "req %u", req->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->t_req = NAN; req->t_resp = NAN; VTAILQ_INIT(&req->body); return (req); }