| | varnish-cache/bin/varnishd/cache/cache_panic.c |
0 |
|
/*- |
1 |
|
* Copyright (c) 2006 Verdens Gang AS |
2 |
|
* Copyright (c) 2006-2015 Varnish Software AS |
3 |
|
* All rights reserved. |
4 |
|
* |
5 |
|
* Author: Dag-Erling Smørgrav <des@des.no> |
6 |
|
* |
7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
8 |
|
* |
9 |
|
* Redistribution and use in source and binary forms, with or without |
10 |
|
* modification, are permitted provided that the following conditions |
11 |
|
* are met: |
12 |
|
* 1. Redistributions of source code must retain the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer. |
14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
15 |
|
* notice, this list of conditions and the following disclaimer in the |
16 |
|
* documentation and/or other materials provided with the distribution. |
17 |
|
* |
18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 |
|
* SUCH DAMAGE. |
29 |
|
*/ |
30 |
|
|
31 |
|
#include "config.h" |
32 |
6 |
|
33 |
6 |
#include <stdio.h> |
34 |
20 |
#include <stdlib.h> |
35 |
20 |
#include <signal.h> |
36 |
19 |
|
37 |
13 |
#include "cache_varnishd.h" |
38 |
10 |
#include "cache_transport.h" |
39 |
7 |
|
40 |
7 |
#include "cache_filter.h" |
41 |
7 |
#include "common/heritage.h" |
42 |
6 |
#include "waiter/waiter.h" |
43 |
6 |
|
44 |
6 |
#include "storage/storage.h" |
45 |
|
#include "vcli_serve.h" |
46 |
|
#include "vtim.h" |
47 |
|
#include "vbt.h" |
48 |
|
#include "vcs.h" |
49 |
|
#include "vtcp.h" |
50 |
|
#include "vsa.h" |
51 |
|
|
52 |
|
/* |
53 |
|
* The panic string is constructed in a VSB, then copied to the |
54 |
|
* shared memory. |
55 |
|
* |
56 |
|
* It can be extracted post-mortem from a core dump using gdb: |
57 |
|
* |
58 |
|
* (gdb) p *(char **)((char *)pan_vsb+8) |
59 |
|
* |
60 |
|
*/ |
61 |
|
|
62 |
|
static struct vsb pan_vsb_storage, *pan_vsb; |
63 |
|
static pthread_mutex_t panicstr_mtx; |
64 |
|
|
65 |
|
static void pan_sess(struct vsb *, const struct sess *); |
66 |
|
static void pan_req(struct vsb *, const struct req *); |
67 |
|
|
68 |
|
/*--------------------------------------------------------------------*/ |
69 |
|
|
70 |
|
static const char * |
71 |
2 |
boc_state_2str(enum boc_state_e e) |
72 |
|
{ |
73 |
2 |
switch (e) { |
74 |
|
#define BOC_STATE(U,l) case BOS_##U: return(#l); |
75 |
|
#include "tbl/boc_state.h" |
76 |
|
default: |
77 |
|
return ("?"); |
78 |
|
} |
79 |
2 |
} |
80 |
|
|
81 |
|
/*--------------------------------------------------------------------*/ |
82 |
|
|
83 |
|
static void |
84 |
7 |
pan_stream_close(struct vsb *vsb, stream_close_t sc) |
85 |
|
{ |
86 |
|
|
87 |
7 |
if (sc != NULL && sc->magic == STREAM_CLOSE_MAGIC) |
88 |
7 |
VSB_printf(vsb, "%s(%s)", sc->name, sc->desc); |
89 |
|
else |
90 |
0 |
VSB_printf(vsb, "%p", sc); |
91 |
7 |
} |
92 |
|
|
93 |
|
/*--------------------------------------------------------------------*/ |
94 |
|
|
95 |
|
static void |
96 |
7 |
pan_storage(struct vsb *vsb, const char *n, const struct stevedore *stv) |
97 |
|
{ |
98 |
|
|
99 |
7 |
if (stv != NULL && stv->magic == STEVEDORE_MAGIC) |
100 |
2 |
VSB_printf(vsb, "%s = %s(%s,%s),\n", |
101 |
1 |
n, stv->name, stv->ident, stv->vclname); |
102 |
|
else |
103 |
6 |
VSB_printf(vsb, "%s = %p,\n", n, stv); |
104 |
7 |
} |
105 |
|
|
106 |
|
/*--------------------------------------------------------------------*/ |
107 |
|
|
108 |
|
#define N_ALREADY 256 |
109 |
|
static const void *already_list[N_ALREADY]; |
110 |
|
static int already_idx; |
111 |
|
|
112 |
|
int |
113 |
212 |
PAN__DumpStruct(struct vsb *vsb, int block, int track, const void *ptr, |
114 |
|
const char *smagic, unsigned magic, const char *fmt, ...) |
115 |
|
{ |
116 |
|
va_list ap; |
117 |
|
const unsigned *uptr; |
118 |
|
int i; |
119 |
|
|
120 |
212 |
AN(vsb); |
121 |
212 |
va_start(ap, fmt); |
122 |
212 |
VSB_vprintf(vsb, fmt, ap); |
123 |
212 |
va_end(ap); |
124 |
212 |
if (ptr == NULL) { |
125 |
34 |
VSB_cat(vsb, " = NULL\n"); |
126 |
34 |
return (-1); |
127 |
|
} |
128 |
178 |
VSB_printf(vsb, " = %p {", ptr); |
129 |
178 |
if (block) |
130 |
175 |
VSB_putc(vsb, '\n'); |
131 |
178 |
if (track) { |
132 |
1618 |
for (i = 0; i < already_idx; i++) { |
133 |
1469 |
if (already_list[i] == ptr) { |
134 |
29 |
VSB_cat(vsb, " [Already dumped, see above]"); |
135 |
29 |
if (block) |
136 |
29 |
VSB_putc(vsb, '\n'); |
137 |
29 |
VSB_cat(vsb, "},\n"); |
138 |
29 |
return (-2); |
139 |
|
} |
140 |
1440 |
} |
141 |
149 |
if (already_idx < N_ALREADY) |
142 |
149 |
already_list[already_idx++] = ptr; |
143 |
149 |
} |
144 |
149 |
uptr = ptr; |
145 |
149 |
if (*uptr != magic) { |
146 |
4 |
VSB_printf(vsb, " .magic = 0x%08x", *uptr); |
147 |
4 |
VSB_printf(vsb, " EXPECTED: %s=0x%08x", smagic, magic); |
148 |
4 |
if (block) |
149 |
4 |
VSB_putc(vsb, '\n'); |
150 |
4 |
VSB_cat(vsb, "}\n"); |
151 |
4 |
return (-3); |
152 |
|
} |
153 |
145 |
if (block) |
154 |
142 |
VSB_indent(vsb, 2); |
155 |
145 |
return (0); |
156 |
212 |
} |
157 |
|
|
158 |
|
/*--------------------------------------------------------------------*/ |
159 |
|
|
160 |
|
static void |
161 |
7 |
pan_htc(struct vsb *vsb, const struct http_conn *htc) |
162 |
|
{ |
163 |
|
|
164 |
7 |
if (PAN_dump_struct(vsb, htc, HTTP_CONN_MAGIC, "http_conn")) |
165 |
0 |
return; |
166 |
7 |
if (htc->rfd != NULL) |
167 |
6 |
VSB_printf(vsb, "fd = %d (@%p),\n", *htc->rfd, htc->rfd); |
168 |
7 |
VSB_cat(vsb, "doclose = "); |
169 |
7 |
pan_stream_close(vsb, htc->doclose); |
170 |
7 |
VSB_cat(vsb, "\n"); |
171 |
7 |
WS_Panic(vsb, htc->ws); |
172 |
14 |
VSB_printf(vsb, "{rxbuf_b, rxbuf_e} = {%p, %p},\n", |
173 |
7 |
htc->rxbuf_b, htc->rxbuf_e); |
174 |
14 |
VSB_printf(vsb, "{pipeline_b, pipeline_e} = {%p, %p},\n", |
175 |
7 |
htc->pipeline_b, htc->pipeline_e); |
176 |
14 |
VSB_printf(vsb, "content_length = %jd,\n", |
177 |
7 |
(intmax_t)htc->content_length); |
178 |
14 |
VSB_printf(vsb, "body_status = %s,\n", |
179 |
7 |
htc->body_status ? htc->body_status->name : "NULL"); |
180 |
14 |
VSB_printf(vsb, "first_byte_timeout = %f,\n", |
181 |
7 |
htc->first_byte_timeout); |
182 |
14 |
VSB_printf(vsb, "between_bytes_timeout = %f,\n", |
183 |
7 |
htc->between_bytes_timeout); |
184 |
7 |
VSB_indent(vsb, -2); |
185 |
7 |
VSB_cat(vsb, "},\n"); |
186 |
7 |
} |
187 |
|
|
188 |
|
/*--------------------------------------------------------------------*/ |
189 |
|
|
190 |
|
static void |
191 |
10 |
pan_http(struct vsb *vsb, const char *id, const struct http *h) |
192 |
|
{ |
193 |
|
int i; |
194 |
|
|
195 |
10 |
if (PAN_dump_struct(vsb, h, HTTP_MAGIC, "http[%s]", id)) |
196 |
0 |
return; |
197 |
10 |
WS_Panic(vsb, h->ws); |
198 |
10 |
VSB_cat(vsb, "hdrs {\n"); |
199 |
10 |
VSB_indent(vsb, 2); |
200 |
114 |
for (i = 0; i < h->nhd; ++i) { |
201 |
104 |
if (h->hd[i].b == NULL && h->hd[i].e == NULL) |
202 |
20 |
continue; |
203 |
168 |
VSB_printf(vsb, "\"%.*s\",\n", |
204 |
84 |
(int)(h->hd[i].e - h->hd[i].b), h->hd[i].b); |
205 |
84 |
} |
206 |
10 |
VSB_indent(vsb, -2); |
207 |
10 |
VSB_cat(vsb, "},\n"); |
208 |
10 |
VSB_indent(vsb, -2); |
209 |
10 |
VSB_cat(vsb, "},\n"); |
210 |
10 |
} |
211 |
|
|
212 |
|
/*--------------------------------------------------------------------*/ |
213 |
|
|
214 |
|
static void |
215 |
2 |
pan_boc(struct vsb *vsb, const struct boc *boc) |
216 |
|
{ |
217 |
2 |
if (PAN_dump_struct(vsb, boc, BOC_MAGIC, "boc")) |
218 |
0 |
return; |
219 |
2 |
VSB_printf(vsb, "refcnt = %u,\n", boc->refcount); |
220 |
2 |
VSB_printf(vsb, "stevedore_priv = %p,\n", boc->stevedore_priv); |
221 |
2 |
VSB_printf(vsb, "state = %s,\n", boc_state_2str(boc->state)); |
222 |
2 |
VSB_printf(vsb, "vary = %p,\n", boc->vary); |
223 |
2 |
VSB_printf(vsb, "fetched_so_far = %ju,\n", (uintmax_t)boc->fetched_so_far); |
224 |
2 |
VSB_printf(vsb, "delivered_so_far = %ju,\n", (uintmax_t)boc->delivered_so_far); |
225 |
2 |
VSB_printf(vsb, "transit_buffer = %ju,\n", (uintmax_t)boc->transit_buffer); |
226 |
2 |
VSB_printf(vsb, "VSLIST_FIRST(vai_q_head) = %p,\n", VSLIST_FIRST(&boc->vai_q_head)); |
227 |
2 |
VSB_indent(vsb, -2); |
228 |
2 |
VSB_cat(vsb, "},\n"); |
229 |
2 |
} |
230 |
|
|
231 |
|
/*--------------------------------------------------------------------*/ |
232 |
|
|
233 |
|
static void |
234 |
3 |
pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc) |
235 |
|
{ |
236 |
|
const char *p; |
237 |
|
|
238 |
3 |
if (PAN_dump_struct(vsb, oc, OBJCORE_MAGIC, "objcore[%s]", typ)) |
239 |
0 |
return; |
240 |
3 |
VSB_printf(vsb, "refcnt = %d,\n", oc->refcnt); |
241 |
3 |
VSB_cat(vsb, "flags = {"); |
242 |
|
|
243 |
|
/*lint -save -esym(438,p) -esym(838,p) -e539 */ |
244 |
3 |
p = ""; |
245 |
|
#define OC_FLAG(U, l, v) \ |
246 |
|
if (oc->flags & v) { VSB_printf(vsb, "%s" #l, p); p = ", "; } |
247 |
|
#include "tbl/oc_flags.h" |
248 |
|
VSB_cat(vsb, "},\n"); |
249 |
|
VSB_cat(vsb, "exp_flags = {"); |
250 |
|
p = ""; |
251 |
|
#define OC_EXP_FLAG(U, l, v) \ |
252 |
|
if (oc->exp_flags & v) { VSB_printf(vsb, "%s" #l, p); p = ", "; } |
253 |
|
#include "tbl/oc_exp_flags.h" |
254 |
|
/*lint -restore */ |
255 |
|
VSB_cat(vsb, "},\n"); |
256 |
|
|
257 |
3 |
if (oc->boc != NULL) |
258 |
2 |
pan_boc(vsb, oc->boc); |
259 |
|
VSB_printf(vsb, "exp = {%f, %f, %f, %f},\n", |
260 |
|
oc->t_origin, oc->ttl, oc->grace, oc->keep); |
261 |
|
VSB_printf(vsb, "objhead = %p,\n", oc->objhead); |
262 |
|
VSB_printf(vsb, "stevedore = %p", oc->stobj->stevedore); |
263 |
3 |
if (oc->stobj->stevedore != NULL) { |
264 |
2 |
VSB_printf(vsb, " (%s", oc->stobj->stevedore->name); |
265 |
2 |
if (strlen(oc->stobj->stevedore->ident)) |
266 |
2 |
VSB_printf(vsb, " %s", oc->stobj->stevedore->ident); |
267 |
2 |
VSB_cat(vsb, ")"); |
268 |
2 |
if (oc->stobj->stevedore->panic) { |
269 |
2 |
VSB_cat(vsb, " {\n"); |
270 |
2 |
VSB_indent(vsb, 2); |
271 |
2 |
oc->stobj->stevedore->panic(vsb, oc); |
272 |
2 |
VSB_indent(vsb, -2); |
273 |
2 |
VSB_cat(vsb, "}"); |
274 |
2 |
} |
275 |
2 |
} |
276 |
|
VSB_cat(vsb, ",\n"); |
277 |
|
VSB_indent(vsb, -2); |
278 |
|
VSB_cat(vsb, "},\n"); |
279 |
|
} |
280 |
|
|
281 |
|
/*--------------------------------------------------------------------*/ |
282 |
|
|
283 |
|
static void |
284 |
20 |
pan_wrk(struct vsb *vsb, const struct worker *wrk) |
285 |
|
{ |
286 |
|
const char *hand; |
287 |
|
unsigned m, u; |
288 |
|
const char *p; |
289 |
|
|
290 |
20 |
if (PAN_dump_struct(vsb, wrk, WORKER_MAGIC, "worker")) |
291 |
13 |
return; |
292 |
7 |
WS_Panic(vsb, wrk->aws); |
293 |
|
|
294 |
7 |
m = wrk->cur_method; |
295 |
7 |
VSB_cat(vsb, "VCL::method = "); |
296 |
7 |
if (m == 0) { |
297 |
0 |
VSB_cat(vsb, "none,\n"); |
298 |
0 |
return; |
299 |
|
} |
300 |
7 |
if (!(m & 1)) |
301 |
6 |
VSB_cat(vsb, "inside "); |
302 |
7 |
m &= ~1; |
303 |
7 |
hand = VCL_Method_Name(m); |
304 |
7 |
if (hand != NULL) |
305 |
7 |
VSB_printf(vsb, "%s,\n", hand); |
306 |
|
else |
307 |
0 |
VSB_printf(vsb, "0x%x,\n", m); |
308 |
|
|
309 |
7 |
VSB_cat(vsb, "VCL::methods = {"); |
310 |
7 |
m = wrk->seen_methods; |
311 |
7 |
p = ""; |
312 |
45 |
for (u = 1; m ; u <<= 1) { |
313 |
38 |
if (m & u) { |
314 |
14 |
VSB_printf(vsb, "%s%s", p, VCL_Method_Name(u)); |
315 |
14 |
m &= ~u; |
316 |
14 |
p = ", "; |
317 |
14 |
} |
318 |
38 |
} |
319 |
7 |
VSB_cat(vsb, "},\n"); |
320 |
7 |
VSB_indent(vsb, -2); |
321 |
7 |
VSB_cat(vsb, "},\n"); |
322 |
20 |
} |
323 |
|
|
324 |
|
static void |
325 |
1 |
pan_vfp(struct vsb *vsb, const struct vfp_ctx *vfc) |
326 |
|
{ |
327 |
|
struct vfp_entry *vfe; |
328 |
|
|
329 |
1 |
if (PAN_dump_struct(vsb, vfc, VFP_CTX_MAGIC, "vfc")) |
330 |
0 |
return; |
331 |
1 |
VSB_printf(vsb, "failed = %d,\n", vfc->failed); |
332 |
1 |
VSB_printf(vsb, "req = %p,\n", vfc->req); |
333 |
1 |
VSB_printf(vsb, "resp = %p,\n", vfc->resp); |
334 |
1 |
VSB_printf(vsb, "wrk = %p,\n", vfc->wrk); |
335 |
1 |
VSB_printf(vsb, "oc = %p,\n", vfc->oc); |
336 |
|
|
337 |
1 |
if (!VTAILQ_EMPTY(&vfc->vfp)) { |
338 |
1 |
VSB_cat(vsb, "filters = {\n"); |
339 |
1 |
VSB_indent(vsb, 2); |
340 |
2 |
VTAILQ_FOREACH(vfe, &vfc->vfp, list) { |
341 |
1 |
VSB_printf(vsb, "%s = %p {\n", vfe->vfp->name, vfe); |
342 |
1 |
VSB_indent(vsb, 2); |
343 |
1 |
VSB_printf(vsb, "priv1 = %p,\n", vfe->priv1); |
344 |
1 |
VSB_printf(vsb, "priv2 = %zd,\n", vfe->priv2); |
345 |
1 |
VSB_printf(vsb, "closed = %d\n", vfe->closed); |
346 |
1 |
VSB_indent(vsb, -2); |
347 |
1 |
VSB_cat(vsb, "},\n"); |
348 |
1 |
} |
349 |
1 |
VSB_indent(vsb, -2); |
350 |
1 |
VSB_cat(vsb, "},\n"); |
351 |
1 |
} |
352 |
|
|
353 |
1 |
VSB_printf(vsb, "obj_flags = 0x%x,\n", vfc->obj_flags); |
354 |
1 |
VSB_indent(vsb, -2); |
355 |
1 |
VSB_cat(vsb, "},\n"); |
356 |
1 |
} |
357 |
|
|
358 |
|
static void |
359 |
13 |
pan_busyobj(struct vsb *vsb, const struct busyobj *bo) |
360 |
|
{ |
361 |
|
const char *p; |
362 |
|
const struct worker *wrk; |
363 |
|
|
364 |
13 |
if (PAN_dump_struct(vsb, bo, BUSYOBJ_MAGIC, "busyobj")) |
365 |
12 |
return; |
366 |
1 |
VSB_printf(vsb, "end = %p,\n", bo->end); |
367 |
1 |
VSB_printf(vsb, "retries = %u,\n", bo->retries); |
368 |
|
|
369 |
1 |
if (bo->req != NULL) |
370 |
0 |
pan_req(vsb, bo->req); |
371 |
1 |
if (bo->sp != NULL) |
372 |
1 |
pan_sess(vsb, bo->sp); |
373 |
1 |
wrk = bo->wrk; |
374 |
1 |
if (wrk != NULL) |
375 |
1 |
pan_wrk(vsb, wrk); |
376 |
|
|
377 |
1 |
if (bo->vfc != NULL) |
378 |
1 |
pan_vfp(vsb, bo->vfc); |
379 |
1 |
if (bo->vfp_filter_list != NULL) { |
380 |
0 |
VSB_printf(vsb, "vfp_filter_list = \"%s\",\n", |
381 |
0 |
bo->vfp_filter_list); |
382 |
0 |
} |
383 |
1 |
if (bo->vdp_filter_list != NULL) { |
384 |
0 |
VSB_printf(vsb, "vdp_filter_list = \"%s\",\n", |
385 |
0 |
bo->vdp_filter_list); |
386 |
0 |
} |
387 |
|
|
388 |
1 |
WS_Panic(vsb, bo->ws); |
389 |
1 |
VSB_printf(vsb, "ws_bo = %p,\n", (void *)bo->ws_bo); |
390 |
|
|
391 |
|
// bereq0 left out |
392 |
1 |
if (bo->bereq != NULL && bo->bereq->ws != NULL) |
393 |
1 |
pan_http(vsb, "bereq", bo->bereq); |
394 |
1 |
if (bo->beresp != NULL && bo->beresp->ws != NULL) |
395 |
1 |
pan_http(vsb, "beresp", bo->beresp); |
396 |
1 |
if (bo->stale_oc) |
397 |
0 |
pan_objcore(vsb, "stale_oc", bo->stale_oc); |
398 |
1 |
if (bo->fetch_objcore) |
399 |
1 |
pan_objcore(vsb, "fetch", bo->fetch_objcore); |
400 |
|
|
401 |
1 |
if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC)) |
402 |
1 |
pan_htc(vsb, bo->htc); |
403 |
|
|
404 |
|
// fetch_task left out |
405 |
|
|
406 |
1 |
VSB_cat(vsb, "flags = {"); |
407 |
1 |
p = ""; |
408 |
|
/*lint -save -esym(438,p) -e539 */ |
409 |
|
#define BERESP_FLAG(l, r, w, f, d) \ |
410 |
|
if (bo->l) { VSB_printf(vsb, "%s" #l, p); p = ", "; } |
411 |
|
#define BEREQ_FLAG(l, r, w, d) BERESP_FLAG(l, r, w, 0, d) |
412 |
|
#include "tbl/bereq_flags.h" |
413 |
|
#include "tbl/beresp_flags.h" |
414 |
|
/*lint -restore */ |
415 |
|
VSB_cat(vsb, "},\n"); |
416 |
|
|
417 |
|
// timeouts/timers/acct/storage left out |
418 |
|
|
419 |
|
pan_storage(vsb, "storage", bo->storage); |
420 |
|
VDI_Panic(bo->director_req, vsb, "director_req"); |
421 |
1 |
if (bo->director_resp == bo->director_req) |
422 |
1 |
VSB_cat(vsb, "director_resp = director_req,\n"); |
423 |
|
else |
424 |
0 |
VDI_Panic(bo->director_resp, vsb, "director_resp"); |
425 |
|
VCL_Panic(vsb, "vcl", bo->vcl); |
426 |
1 |
if (wrk != NULL) |
427 |
1 |
VPI_Panic(vsb, wrk->vpi, bo->vcl); |
428 |
|
|
429 |
|
VSB_indent(vsb, -2); |
430 |
|
VSB_cat(vsb, "},\n"); |
431 |
|
} |
432 |
|
|
433 |
|
/*--------------------------------------------------------------------*/ |
434 |
|
|
435 |
|
static void |
436 |
6 |
pan_top(struct vsb *vsb, const struct reqtop *top) |
437 |
|
{ |
438 |
6 |
if (PAN_dump_struct(vsb, top, REQTOP_MAGIC, "top")) |
439 |
0 |
return; |
440 |
6 |
pan_req(vsb, top->topreq); |
441 |
6 |
pan_privs(vsb, top->privs); |
442 |
6 |
VCL_Panic(vsb, "vcl0", top->vcl0); |
443 |
6 |
VSB_indent(vsb, -2); |
444 |
6 |
VSB_cat(vsb, "},\n"); |
445 |
6 |
} |
446 |
|
|
447 |
|
/*--------------------------------------------------------------------*/ |
448 |
|
|
449 |
|
static void |
450 |
19 |
pan_req(struct vsb *vsb, const struct req *req) |
451 |
|
{ |
452 |
|
const struct transport *xp; |
453 |
|
const struct worker *wrk; |
454 |
|
|
455 |
19 |
if (PAN_dump_struct(vsb, req, REQ_MAGIC, "req")) |
456 |
13 |
return; |
457 |
6 |
xp = req->transport; |
458 |
12 |
VSB_printf(vsb, "vxid = %ju, transport = %s", VXID(req->vsl->wid), |
459 |
6 |
xp == NULL ? "NULL" : xp->name); |
460 |
|
|
461 |
6 |
if (xp != NULL && xp->req_panic != NULL) { |
462 |
5 |
VSB_cat(vsb, " {\n"); |
463 |
5 |
VSB_indent(vsb, 2); |
464 |
5 |
xp->req_panic(vsb, req); |
465 |
5 |
VSB_indent(vsb, -2); |
466 |
5 |
VSB_cat(vsb, "}"); |
467 |
5 |
} |
468 |
6 |
VSB_cat(vsb, "\n"); |
469 |
6 |
if (req->req_step == NULL) |
470 |
0 |
VSB_cat(vsb, "step = R_STP_TRANSPORT\n"); |
471 |
|
else |
472 |
6 |
VSB_printf(vsb, "step = %s\n", req->req_step->name); |
473 |
|
|
474 |
6 |
if (req->vfp_filter_list != NULL) { |
475 |
0 |
VSB_printf(vsb, "vfp_filter_list = \"%s\",\n", |
476 |
0 |
req->vfp_filter_list); |
477 |
0 |
} |
478 |
6 |
if (req->vdp_filter_list != NULL) { |
479 |
2 |
VSB_printf(vsb, "vdp_filter_list = \"%s\",\n", |
480 |
1 |
req->vdp_filter_list); |
481 |
1 |
} |
482 |
|
|
483 |
12 |
VSB_printf(vsb, "req_body = %s,\n", |
484 |
6 |
req->req_body_status ? req->req_body_status->name : "NULL"); |
485 |
|
|
486 |
6 |
if (req->err_code) |
487 |
0 |
VSB_printf(vsb, |
488 |
0 |
"err_code = %d, err_reason = %s,\n", req->err_code, |
489 |
0 |
req->err_reason ? req->err_reason : "(null)"); |
490 |
|
|
491 |
12 |
VSB_printf(vsb, "restarts = %u, esi_level = %u,\n", |
492 |
6 |
req->restarts, req->esi_level); |
493 |
|
|
494 |
12 |
VSB_printf(vsb, "vary_b = %p, vary_e = %p,\n", |
495 |
6 |
req->vary_b, req->vary_e); |
496 |
|
|
497 |
12 |
VSB_printf(vsb, "d_ttl = %f, d_grace = %f,\n", |
498 |
6 |
req->d_ttl, req->d_grace); |
499 |
|
|
500 |
6 |
pan_storage(vsb, "storage", req->storage); |
501 |
|
|
502 |
6 |
VDI_Panic(req->director_hint, vsb, "director_hint"); |
503 |
|
|
504 |
6 |
if (req->sp != NULL) |
505 |
6 |
pan_sess(vsb, req->sp); |
506 |
|
|
507 |
6 |
wrk = req->wrk; |
508 |
6 |
if (wrk != NULL) |
509 |
6 |
pan_wrk(vsb, wrk); |
510 |
|
|
511 |
6 |
WS_Panic(vsb, req->ws); |
512 |
6 |
if (VALID_OBJ(req->htc, HTTP_CONN_MAGIC)) |
513 |
6 |
pan_htc(vsb, req->htc); |
514 |
6 |
pan_http(vsb, "req", req->http); |
515 |
6 |
if (req->resp != NULL && req->resp->ws != NULL) |
516 |
2 |
pan_http(vsb, "resp", req->resp); |
517 |
6 |
if (req->vdc != NULL) |
518 |
6 |
VDP_Panic(vsb, req->vdc); |
519 |
|
|
520 |
6 |
VCL_Panic(vsb, "vcl", req->vcl); |
521 |
6 |
if (wrk != NULL) |
522 |
6 |
VPI_Panic(vsb, wrk->vpi, req->vcl); |
523 |
|
|
524 |
6 |
if (req->body_oc != NULL) |
525 |
0 |
pan_objcore(vsb, "BODY", req->body_oc); |
526 |
6 |
if (req->objcore != NULL) |
527 |
2 |
pan_objcore(vsb, "REQ", req->objcore); |
528 |
|
|
529 |
6 |
VSB_cat(vsb, "flags = {\n"); |
530 |
6 |
VSB_indent(vsb, 2); |
531 |
|
#define REQ_FLAG(l, r, w, d) if (req->l) VSB_printf(vsb, #l ",\n"); |
532 |
|
#include "tbl/req_flags.h" |
533 |
|
VSB_indent(vsb, -2); |
534 |
|
VSB_cat(vsb, "},\n"); |
535 |
|
|
536 |
|
pan_privs(vsb, req->privs); |
537 |
|
|
538 |
6 |
if (req->top != NULL) |
539 |
6 |
pan_top(vsb, req->top); |
540 |
|
|
541 |
|
VSB_indent(vsb, -2); |
542 |
|
VSB_cat(vsb, "},\n"); |
543 |
|
} |
544 |
|
|
545 |
|
/*--------------------------------------------------------------------*/ |
546 |
|
|
547 |
|
#define pan_addr(vsb, sp, field) do { \ |
548 |
|
struct suckaddr *sa; \ |
549 |
|
char h[VTCP_ADDRBUFSIZE]; \ |
550 |
|
char p[VTCP_PORTBUFSIZE]; \ |
551 |
|
\ |
552 |
|
(void) SES_Get_##field##_addr((sp), &sa); \ |
553 |
|
if (! VSA_Sane(sa)) \ |
554 |
|
break; \ |
555 |
|
VTCP_name(sa, h, sizeof h, p, sizeof p); \ |
556 |
|
VSB_printf((vsb), "%s.ip = %s:%s,\n", #field, h, p); \ |
557 |
|
} while (0) |
558 |
|
|
559 |
|
static void |
560 |
7 |
pan_sess(struct vsb *vsb, const struct sess *sp) |
561 |
|
{ |
562 |
|
const char *ci; |
563 |
|
const char *cp; |
564 |
|
const struct transport *xp; |
565 |
|
|
566 |
7 |
if (PAN_dump_struct(vsb, sp, SESS_MAGIC, "sess")) |
567 |
0 |
return; |
568 |
14 |
VSB_printf(vsb, "fd = %d, vxid = %ju,\n", |
569 |
7 |
sp->fd, VXID(sp->vxid)); |
570 |
7 |
VSB_printf(vsb, "t_open = %f,\n", sp->t_open); |
571 |
7 |
VSB_printf(vsb, "t_idle = %f,\n", sp->t_idle); |
572 |
|
|
573 |
7 |
if (! VALID_OBJ(sp, SESS_MAGIC)) { |
574 |
0 |
VSB_indent(vsb, -2); |
575 |
0 |
VSB_cat(vsb, "},\n"); |
576 |
0 |
return; |
577 |
|
} |
578 |
|
|
579 |
7 |
WS_Panic(vsb, sp->ws); |
580 |
7 |
xp = XPORT_ByNumber(sp->sattr[SA_TRANSPORT]); |
581 |
14 |
VSB_printf(vsb, "transport = %s", |
582 |
7 |
xp == NULL ? "<none>" : xp->name); |
583 |
7 |
if (xp != NULL && xp->sess_panic != NULL) { |
584 |
7 |
VSB_cat(vsb, " {\n"); |
585 |
7 |
VSB_indent(vsb, 2); |
586 |
7 |
xp->sess_panic(vsb, sp); |
587 |
7 |
VSB_indent(vsb, -2); |
588 |
7 |
VSB_cat(vsb, "}"); |
589 |
7 |
} |
590 |
7 |
VSB_cat(vsb, "\n"); |
591 |
|
|
592 |
|
// duplicated below, remove ? |
593 |
7 |
ci = SES_Get_String_Attr(sp, SA_CLIENT_IP); |
594 |
7 |
cp = SES_Get_String_Attr(sp, SA_CLIENT_PORT); |
595 |
7 |
if (VALID_OBJ(sp->listen_sock, LISTEN_SOCK_MAGIC)) |
596 |
14 |
VSB_printf(vsb, "client = %s %s %s,\n", ci, cp, |
597 |
7 |
sp->listen_sock->endpoint); |
598 |
|
else |
599 |
0 |
VSB_printf(vsb, "client = %s %s <unknown>\n", ci, cp); |
600 |
|
|
601 |
7 |
if (VALID_OBJ(sp->listen_sock, LISTEN_SOCK_MAGIC)) { |
602 |
14 |
VSB_printf(vsb, "local.endpoint = %s,\n", |
603 |
7 |
sp->listen_sock->endpoint); |
604 |
14 |
VSB_printf(vsb, "local.socket = %s,\n", |
605 |
7 |
sp->listen_sock->name); |
606 |
7 |
} |
607 |
7 |
pan_addr(vsb, sp, local); |
608 |
7 |
pan_addr(vsb, sp, remote); |
609 |
7 |
pan_addr(vsb, sp, server); |
610 |
7 |
pan_addr(vsb, sp, client); |
611 |
|
|
612 |
7 |
VSB_indent(vsb, -2); |
613 |
7 |
VSB_cat(vsb, "},\n"); |
614 |
7 |
} |
615 |
|
|
616 |
|
/*--------------------------------------------------------------------*/ |
617 |
|
|
618 |
|
static void |
619 |
13 |
pan_backtrace(struct vsb *vsb) |
620 |
|
{ |
621 |
|
|
622 |
13 |
VSB_cat(vsb, "Backtrace:\n"); |
623 |
13 |
VSB_indent(vsb, 2); |
624 |
13 |
VBT_format(vsb); |
625 |
13 |
VSB_indent(vsb, -2); |
626 |
13 |
} |
627 |
|
|
628 |
|
#ifdef HAVE_PTHREAD_GETATTR_NP |
629 |
|
static void |
630 |
|
pan_threadattr(struct vsb *vsb) |
631 |
|
{ |
632 |
|
pthread_attr_t attr[1]; |
633 |
|
size_t sz; |
634 |
|
void *addr; |
635 |
|
|
636 |
|
if (pthread_getattr_np(pthread_self(), attr) != 0) |
637 |
|
return; |
638 |
|
|
639 |
|
VSB_cat(vsb, "pthread.attr = {\n"); |
640 |
|
VSB_indent(vsb, 2); |
641 |
|
|
642 |
|
if (pthread_attr_getguardsize(attr, &sz) == 0) |
643 |
|
VSB_printf(vsb, "guard = %zu,\n", sz); |
644 |
|
if (pthread_attr_getstack(attr, &addr, &sz) == 0) { |
645 |
|
VSB_printf(vsb, "stack_bottom = %p,\n", addr); |
646 |
|
VSB_printf(vsb, "stack_top = %p,\n", (char *)addr + sz); |
647 |
|
VSB_printf(vsb, "stack_size = %zu,\n", sz); |
648 |
|
} |
649 |
|
VSB_indent(vsb, -2); |
650 |
|
VSB_cat(vsb, "}\n"); |
651 |
|
(void) pthread_attr_destroy(attr); |
652 |
|
} |
653 |
|
#endif |
654 |
|
|
655 |
|
static void |
656 |
13 |
pan_argv(struct vsb *vsb) |
657 |
|
{ |
658 |
|
int i; |
659 |
|
|
660 |
13 |
VSB_cat(pan_vsb, "argv = {\n"); |
661 |
13 |
VSB_indent(vsb, 2); |
662 |
392 |
for (i = 0; i < heritage.argc; i++) { |
663 |
379 |
VSB_printf(vsb, "[%d] = ", i); |
664 |
379 |
VSB_quote(vsb, heritage.argv[i], -1, VSB_QUOTE_CSTR); |
665 |
379 |
VSB_cat(vsb, ",\n"); |
666 |
379 |
} |
667 |
13 |
VSB_indent(vsb, -2); |
668 |
13 |
VSB_cat(vsb, "}\n"); |
669 |
|
|
670 |
13 |
} |
671 |
|
/*--------------------------------------------------------------------*/ |
672 |
|
|
673 |
|
static void __attribute__((__noreturn__)) |
674 |
13 |
pan_ic(const char *func, const char *file, int line, const char *cond, |
675 |
|
enum vas_e kind) |
676 |
|
{ |
677 |
|
const char *q; |
678 |
|
struct req *req; |
679 |
|
struct busyobj *bo; |
680 |
|
struct worker *wrk; |
681 |
|
struct sigaction sa; |
682 |
13 |
int i, err = errno; |
683 |
|
|
684 |
13 |
if (pthread_getspecific(panic_key) != NULL) { |
685 |
0 |
VSB_cat(pan_vsb, "\n\nPANIC REENTRANCY\n\n"); |
686 |
0 |
abort(); |
687 |
|
} |
688 |
|
|
689 |
|
/* If we already panicking in another thread, do nothing */ |
690 |
13 |
do { |
691 |
13 |
i = pthread_mutex_trylock(&panicstr_mtx); |
692 |
13 |
if (i != 0) |
693 |
0 |
sleep (1); |
694 |
13 |
} while (i != 0); |
695 |
|
|
696 |
13 |
assert (VSB_len(pan_vsb) == 0); |
697 |
|
|
698 |
13 |
AZ(pthread_setspecific(panic_key, pan_vsb)); |
699 |
|
|
700 |
|
/* |
701 |
|
* should we trigger a SIGSEGV while handling a panic, our sigsegv |
702 |
|
* handler would hide the panic, so we need to reset the handler to |
703 |
|
* default |
704 |
|
*/ |
705 |
13 |
memset(&sa, 0, sizeof sa); |
706 |
13 |
sa.sa_handler = SIG_DFL; |
707 |
13 |
(void)sigaction(SIGSEGV, &sa, NULL); |
708 |
|
/* Set SIGABRT back to default so the final abort() has the |
709 |
|
desired effect */ |
710 |
13 |
(void)sigaction(SIGABRT, &sa, NULL); |
711 |
|
|
712 |
13 |
switch (kind) { |
713 |
|
case VAS_WRONG: |
714 |
14 |
VSB_printf(pan_vsb, |
715 |
7 |
"Wrong turn at %s:%d:\n%s\n", file, line, cond); |
716 |
7 |
break; |
717 |
|
case VAS_VCL: |
718 |
6 |
VSB_printf(pan_vsb, |
719 |
3 |
"Panic from VCL:\n %s\n", cond); |
720 |
3 |
break; |
721 |
|
case VAS_MISSING: |
722 |
0 |
VSB_printf(pan_vsb, |
723 |
|
"Missing error handling code in %s(), %s line %d:\n" |
724 |
|
" Condition(%s) not true.\n", |
725 |
0 |
func, file, line, cond); |
726 |
0 |
break; |
727 |
|
case VAS_INCOMPLETE: |
728 |
0 |
VSB_printf(pan_vsb, |
729 |
|
"Incomplete code in %s(), %s line %d:\n", |
730 |
0 |
func, file, line); |
731 |
0 |
break; |
732 |
3 |
case VAS_ASSERT: |
733 |
|
default: |
734 |
6 |
VSB_printf(pan_vsb, |
735 |
|
"Assert error in %s(), %s line %d:\n" |
736 |
|
" Condition(%s) not true.\n", |
737 |
3 |
func, file, line, cond); |
738 |
3 |
break; |
739 |
|
} |
740 |
26 |
VSB_printf(pan_vsb, "version = %s, vrt api = %u.%u\n", |
741 |
13 |
VCS_String("V"), VRT_MAJOR_VERSION, VRT_MINOR_VERSION); |
742 |
26 |
VSB_printf(pan_vsb, "ident = %s,%s\n", |
743 |
13 |
heritage.ident, Waiter_GetName()); |
744 |
26 |
VSB_printf(pan_vsb, "now = %f (mono), %f (real)\n", |
745 |
13 |
VTIM_mono(), VTIM_real()); |
746 |
|
|
747 |
13 |
pan_backtrace(pan_vsb); |
748 |
|
|
749 |
13 |
if (err) |
750 |
1 |
VSB_printf(pan_vsb, "errno = %d (%s)\n", err, VAS_errtxt(err)); |
751 |
|
|
752 |
13 |
pan_argv(pan_vsb); |
753 |
|
|
754 |
13 |
VSB_printf(pan_vsb, "pthread.self = %p\n", TRUST_ME(pthread_self())); |
755 |
|
|
756 |
13 |
q = THR_GetName(); |
757 |
13 |
if (q != NULL) |
758 |
13 |
VSB_printf(pan_vsb, "pthread.name = (%s)\n", q); |
759 |
|
|
760 |
|
#ifdef HAVE_PTHREAD_GETATTR_NP |
761 |
|
pan_threadattr(pan_vsb); |
762 |
|
#endif |
763 |
|
|
764 |
13 |
if (!FEATURE(FEATURE_SHORT_PANIC)) { |
765 |
13 |
req = THR_GetRequest(); |
766 |
13 |
VSB_cat(pan_vsb, "thr."); |
767 |
13 |
pan_req(pan_vsb, req); |
768 |
13 |
if (req != NULL) |
769 |
6 |
VSL_Flush(req->vsl, 0); |
770 |
13 |
bo = THR_GetBusyobj(); |
771 |
13 |
VSB_cat(pan_vsb, "thr."); |
772 |
13 |
pan_busyobj(pan_vsb, bo); |
773 |
13 |
if (bo != NULL) |
774 |
1 |
VSL_Flush(bo->vsl, 0); |
775 |
13 |
wrk = THR_GetWorker(); |
776 |
13 |
VSB_cat(pan_vsb, "thr."); |
777 |
13 |
pan_wrk(pan_vsb, wrk); |
778 |
13 |
VMOD_Panic(pan_vsb); |
779 |
13 |
pan_pool(pan_vsb); |
780 |
13 |
} else { |
781 |
0 |
VSB_cat(pan_vsb, "Feature short panic suppressed details.\n"); |
782 |
|
} |
783 |
13 |
VSB_cat(pan_vsb, "\n"); |
784 |
13 |
VSB_putc(pan_vsb, '\0'); /* NUL termination */ |
785 |
|
|
786 |
13 |
v_gcov_flush(); |
787 |
|
|
788 |
|
/* |
789 |
|
* Do a little song and dance for static checkers which |
790 |
|
* are not smart enough to figure out that calling abort() |
791 |
|
* with a mutex held is OK and probably very intentional. |
792 |
|
*/ |
793 |
13 |
if (pthread_getspecific(panic_key)) /* ie: always */ |
794 |
13 |
abort(); |
795 |
0 |
PTOK(pthread_mutex_unlock(&panicstr_mtx)); |
796 |
0 |
abort(); |
797 |
|
} |
798 |
|
|
799 |
|
/*--------------------------------------------------------------------*/ |
800 |
|
|
801 |
|
static void v_noreturn_ v_matchproto_(cli_func_t) |
802 |
1 |
ccf_panic(struct cli *cli, const char * const *av, void *priv) |
803 |
|
{ |
804 |
|
|
805 |
1 |
(void)cli; |
806 |
1 |
(void)av; |
807 |
1 |
AZ(priv); |
808 |
1 |
AZ(strcmp("", "You asked for it")); |
809 |
|
/* NOTREACHED */ |
810 |
0 |
abort(); |
811 |
|
} |
812 |
|
|
813 |
|
/*--------------------------------------------------------------------*/ |
814 |
|
|
815 |
|
static struct cli_proto debug_cmds[] = { |
816 |
|
{ CLICMD_DEBUG_PANIC_WORKER, "d", ccf_panic }, |
817 |
|
{ NULL } |
818 |
|
}; |
819 |
|
|
820 |
|
/*--------------------------------------------------------------------*/ |
821 |
|
|
822 |
|
void |
823 |
939 |
PAN_Init(void) |
824 |
|
{ |
825 |
|
|
826 |
939 |
PTOK(pthread_mutex_init(&panicstr_mtx, &mtxattr_errorcheck)); |
827 |
939 |
VAS_Fail_Func = pan_ic; |
828 |
939 |
pan_vsb = &pan_vsb_storage; |
829 |
939 |
AN(heritage.panic_str); |
830 |
939 |
AN(heritage.panic_str_len); |
831 |
939 |
AN(VSB_init(pan_vsb, heritage.panic_str, heritage.panic_str_len)); |
832 |
939 |
VSB_cat(pan_vsb, "This is a test\n"); |
833 |
939 |
AZ(VSB_finish(pan_vsb)); |
834 |
939 |
VSB_clear(pan_vsb); |
835 |
939 |
heritage.panic_str[0] = '\0'; |
836 |
939 |
CLI_AddFuncs(debug_cmds); |
837 |
939 |
} |