Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 381 lines (333 sloc) 8.754 kb
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
1 /*-
2 * Copyright (c) 2006 Verdens Gang AS
c117268 @bsdphk Update copyright notices to reflect development and copyright assignment
bsdphk authored
3 * Copyright (c) 2006-2011 Varnish Software AS
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
4 * All rights reserved.
5 *
6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include "config.h"
31
49ef6b7 cleanups
Poul-Henning Kamp authored
32 #include <sys/stat.h>
8aa1d8b @bsdphk Eliminate nested <*.h> includes from include/*
bsdphk authored
33 #include <sys/types.h>
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
34
8aa1d8b @bsdphk Eliminate nested <*.h> includes from include/*
bsdphk authored
35 #include <errno.h>
36 #include <stdint.h>
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
41
42 #include "miniobj.h"
8aa1d8b @bsdphk Eliminate nested <*.h> includes from include/*
bsdphk authored
43 #include "vas.h"
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
44
8aa1d8b @bsdphk Eliminate nested <*.h> includes from include/*
bsdphk authored
45 #include "vapi/vsl.h"
46 #include "vapi/vsm.h"
47 #include "vapi/vsm_int.h"
48 #include "vbm.h"
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
49 #include "vmb.h"
8aa1d8b @bsdphk Eliminate nested <*.h> includes from include/*
bsdphk authored
50 #include "vre.h"
51 #include "vsl_api.h"
52 #include "vsm_api.h"
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
53
54 /*--------------------------------------------------------------------*/
55
56 const char *VSL_tags[256] = {
57 #define SLTM(foo) [SLT_##foo] = #foo,
7a24aa3 @bsdphk Start #include reorg. The table-building #includes will all go into
bsdphk authored
58 #include "tbl/vsl_tags.h"
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
59 #undef SLTM
60 };
61
62 /*--------------------------------------------------------------------*/
63
64 void
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
65 VSL_Setup(struct VSM_data *vd)
66 {
67 struct vsl *vsl;
1e555c3 white-space anal-retentive fixup
Poul-Henning Kamp authored
68
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
69 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
70 AZ(vd->vsl);
5cbd8ca @bsdphk Make Varnish API aware of the new structure and make everything compile
bsdphk authored
71 ALLOC_OBJ(vd->vsl, VSL_MAGIC);
72 AN(vd->vsl);
73 vsl = vd->vsl;
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
74 vsl->regflags = 0;
75 vsl->vbm_supress = vbit_init(256);
76 vsl->vbm_select = vbit_init(256);
77 vsl->r_fd = -1;
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
78 vsl->num_matchers = 0;
79 VTAILQ_INIT(&vsl->matchers);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
80 }
81
82 /*--------------------------------------------------------------------*/
83
84 void
9c86e0b @bsdphk Namespace cleanup of the VSM related varnishapi functions
bsdphk authored
85 VSL_Delete(struct VSM_data *vd)
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
86 {
87 struct vsl *vsl;
88
89 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
90 vsl = vd->vsl;
91 vd->vsl = NULL;
92 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
93
94 vbit_destroy(vsl->vbm_supress);
95 vbit_destroy(vsl->vbm_select);
96 free(vsl->rbuf);
97
98 FREE_OBJ(vsl);
99 }
100
101 /*--------------------------------------------------------------------*/
102
103 void
6a57ea1 Wanton renaming in libvarnishapi
Poul-Henning Kamp authored
104 VSL_Select(const struct VSM_data *vd, unsigned tag)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
105 {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
106 struct vsl *vsl;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
107
6a57ea1 Wanton renaming in libvarnishapi
Poul-Henning Kamp authored
108 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
109 vsl = vd->vsl;
110 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
111 vbit_set(vsl->vbm_select, tag);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
112 }
113
114
115 /*--------------------------------------------------------------------*/
116
117 void
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
118 VSL_NonBlocking(const struct VSM_data *vd, int nb)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
119 {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
120 struct vsl *vsl;
121
122 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
123 vsl = vd->vsl;
124 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
125 if (nb)
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
126 vsl->flags |= F_NON_BLOCKING;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
127 else
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
128 vsl->flags &= ~F_NON_BLOCKING;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
129 }
130
131 /*--------------------------------------------------------------------*/
132
133 static int
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
134 vsl_nextlog(struct vsl *vsl, uint32_t **pp)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
135 {
136 unsigned w, l;
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
137 uint32_t t;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
138 int i;
139
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
140 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
141
142 if (vsl->r_fd != -1) {
143 assert(vsl->rbuflen >= 8);
144 i = read(vsl->r_fd, vsl->rbuf, 8);
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
145 if (i != 8)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
146 return (-1);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
147 l = 2 + VSL_WORDS(VSL_LEN(vsl->rbuf));
148 if (vsl->rbuflen < l) {
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
149 l += 256;
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
150 vsl->rbuf = realloc(vsl->rbuf, l * 4L);
151 assert(vsl->rbuf != NULL);
152 vsl->rbuflen = l;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
153 }
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
154 i = read(vsl->r_fd, vsl->rbuf + 2, l * 4L - 8L);
66101b9 Fix up reading of saved log files
Tollef Fog Heen authored
155 if (i != (l * 4L - 8L))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
156 return (-1);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
157 *pp = vsl->rbuf;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
158 return (1);
159 }
160 for (w = 0; w < TIMEOUT_USEC;) {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
161 t = *vsl->log_ptr;
a0308b8 Clean up and unify shmlog writing in the worker process.
Poul-Henning Kamp authored
162
8510961 @bsdphk Fix the boundary detection code in vsl.c, slightly more paranoid than
bsdphk authored
163 if (t == VSL_WRAPMARKER) {
164 /* Wrap around not possible at front */
165 assert(vsl->log_ptr != vsl->log_start + 1);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
166 vsl->log_ptr = vsl->log_start + 1;
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
167 VRMB();
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
168 continue;
af353a6 @bsdphk Administrative fixes:
bsdphk authored
169 }
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
170 if (t == VSL_ENDMARKER) {
8510961 @bsdphk Fix the boundary detection code in vsl.c, slightly more paranoid than
bsdphk authored
171 if (vsl->log_ptr != vsl->log_start + 1 &&
af353a6 @bsdphk Administrative fixes:
bsdphk authored
172 vsl->last_seq != vsl->log_start[0]) {
8510961 @bsdphk Fix the boundary detection code in vsl.c, slightly more paranoid than
bsdphk authored
173 /* ENDMARKER not at front and seq wrapped */
174 vsl->log_ptr = vsl->log_start + 1;
175 VRMB();
176 continue;
177 }
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
178 if (vsl->flags & F_NON_BLOCKING)
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
179 return (-1);
180 w += SLEEP_USEC;
3a0d628 @mbgrydeland Don't assert on sleep failure due to signals in VSL library (some
mbgrydeland authored
181 assert(usleep(SLEEP_USEC) == 0 || errno == EINTR);
2da6772 @bsdphk Remember to sleep and terminate, rather than loop for ever on a zero
bsdphk authored
182 VRMB();
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
183 continue;
184 }
223ff71 @bsdphk Do the zero check last, so a varnishd restart has a chance to recover it...
bsdphk authored
185 if (t == 0) {
186 /* Zero-initialized VSL */
187 w += SLEEP_USEC;
188 assert(usleep(SLEEP_USEC) == 0 || errno == EINTR);
189 VRMB();
190 continue;
191 }
8510961 @bsdphk Fix the boundary detection code in vsl.c, slightly more paranoid than
bsdphk authored
192 if (vsl->log_ptr == vsl->log_start + 1)
193 vsl->last_seq = vsl->log_start[0];
194
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
195 *pp = (void*)(uintptr_t)vsl->log_ptr; /* Loose volatile */
196 vsl->log_ptr = VSL_NEXT(vsl->log_ptr);
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
197 return (1);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
198 }
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
199 *pp = NULL;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
200 return (0);
201 }
202
203 int
cb07c41 @bsdphk A bit of spit and polish inspired by DocWilcos varnishtest patch.
bsdphk authored
204 VSL_NextLog(const struct VSM_data *vd, uint32_t **pp, uint64_t *bits)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
205 {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
206 struct vsl *vsl;
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
207 uint32_t *p;
208 unsigned char t;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
209 int i;
210
6a57ea1 Wanton renaming in libvarnishapi
Poul-Henning Kamp authored
211 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
212 vsl = vd->vsl;
213 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
214
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
215 while (1) {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
216 i = vsl_nextlog(vsl, &p);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
217 if (i != 1)
218 return (i);
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
219 t = VSL_TAG(p);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
220 if (vsl->skip) {
221 --vsl->skip;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
222 continue;
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
223 } else if (vsl->keep) {
224 if (--vsl->keep == 0)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
225 return (-1);
226 }
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
227
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
228 if (vbit_test(vsl->vbm_select, t)) {
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
229 *pp = p;
230 return (1);
231 }
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
232 if (vbit_test(vsl->vbm_supress, t))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
233 continue;
009eb1c @bsdphk Give VSL records a backend and client tag (2^30 fd's is enough for
bsdphk authored
234 if (vsl->b_opt && !VSL_BACKEND(p))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
235 continue;
009eb1c @bsdphk Give VSL records a backend and client tag (2^30 fd's is enough for
bsdphk authored
236 if (vsl->c_opt && !VSL_CLIENT(p))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
237 continue;
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
238 if (vsl->regincl != NULL) {
239 i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p),
8a385bf @bsdphk Make it possible to set limits for VRE matching.
bsdphk authored
240 0, 0, NULL, 0, NULL);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
241 if (i == VRE_ERROR_NOMATCH)
242 continue;
243 }
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
244 if (vsl->regexcl != NULL) {
0252cae Typo in -X matching in varnishapi
Poul-Henning Kamp authored
245 i = VRE_exec(vsl->regexcl, VSL_DATA(p), VSL_LEN(p),
8a385bf @bsdphk Make it possible to set limits for VRE matching.
bsdphk authored
246 0, 0, NULL, 0, NULL);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
247 if (i != VRE_ERROR_NOMATCH)
248 continue;
249 }
cb07c41 @bsdphk A bit of spit and polish inspired by DocWilcos varnishtest patch.
bsdphk authored
250 if (bits != NULL) {
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
251 struct vsl_re_match *vrm;
252 int j = 0;
253 VTAILQ_FOREACH(vrm, &vsl->matchers, next) {
254 if (vrm->tag == t) {
255 i = VRE_exec(vrm->re, VSL_DATA(p),
8a385bf @bsdphk Make it possible to set limits for VRE matching.
bsdphk authored
256 VSL_LEN(p), 0, 0, NULL, 0, NULL);
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
257 if (i >= 0)
cb07c41 @bsdphk A bit of spit and polish inspired by DocWilcos varnishtest patch.
bsdphk authored
258 *bits |= (uintmax_t)1 << j;
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
259 }
260 j++;
261 }
262 }
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
263 *pp = p;
264 return (1);
265 }
266 }
267
268 /*--------------------------------------------------------------------*/
269
270 int
9c86e0b @bsdphk Namespace cleanup of the VSM related varnishapi functions
bsdphk authored
271 VSL_Dispatch(struct VSM_data *vd, VSL_handler_f *func, void *priv)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
272 {
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
273 struct vsl *vsl;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
274 int i;
275 unsigned u, l, s;
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
276 uint32_t *p;
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
277 uint64_t bitmap;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
278
6a57ea1 Wanton renaming in libvarnishapi
Poul-Henning Kamp authored
279 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
3339706 Delaminate the VSL api from the VSM api
Poul-Henning Kamp authored
280 vsl = vd->vsl;
281 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
282
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
283 while (1) {
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
284 bitmap = 0;
285 i = VSL_NextLog(vd, &p, &bitmap);
23bd12c Make VSL_Dispatch reopen the vsm when idle-timeout kicks in.
Poul-Henning Kamp authored
286 if (i == 0 && VSM_ReOpen(vd, 0) == 1)
287 continue;
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
288 if (i != 1)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
289 return (i);
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
290 u = VSL_ID(p);
291 l = VSL_LEN(p);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
292 s = 0;
009eb1c @bsdphk Give VSL records a backend and client tag (2^30 fd's is enough for
bsdphk authored
293 if (VSL_CLIENT(p))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
294 s |= VSL_S_CLIENT;
009eb1c @bsdphk Give VSL records a backend and client tag (2^30 fd's is enough for
bsdphk authored
295 if (VSL_BACKEND(p))
296 s |= VSL_S_BACKEND;
635bc5f @bsdphk Give libvarnishapi a good flexelinting
bsdphk authored
297 if (func(priv, (enum VSL_tag_e)VSL_TAG(p), u, l, s, VSL_DATA(p), bitmap))
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
298 return (1);
299 }
300 }
301
302 /*--------------------------------------------------------------------*/
303
304 int
9c86e0b @bsdphk Namespace cleanup of the VSM related varnishapi functions
bsdphk authored
305 VSL_H_Print(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
306 unsigned spec, const char *ptr, uint64_t bitmap)
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
307 {
308 FILE *fo = priv;
309 int type;
310
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
311 (void) bitmap;
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
312 assert(fo != NULL);
313
314 type = (spec & VSL_S_CLIENT) ? 'c' :
315 (spec & VSL_S_BACKEND) ? 'b' : '-';
316
317 if (tag == SLT_Debug) {
59c7da1 Tighten on the relative accesses to wrap-sequence and special marker
Poul-Henning Kamp authored
318 fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
319 while (len-- > 0) {
320 if (*ptr >= ' ' && *ptr <= '~')
321 fprintf(fo, "%c", *ptr);
322 else
323 fprintf(fo, "%%%02x", (unsigned char)*ptr);
324 ptr++;
325 }
326 fprintf(fo, "\"\n");
327 return (0);
328 }
635bc5f @bsdphk Give libvarnishapi a good flexelinting
bsdphk authored
329 fprintf(fo, "%5u %-12s %c %.*s\n",
330 fd, VSL_tags[tag], type, (int)len, ptr);
16b7701 Split shmlog.c into more appropriately named vsl*[.ch] files
Poul-Henning Kamp authored
331 return (0);
332 }
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
333
334 /*--------------------------------------------------------------------*/
335
23bd12c Make VSL_Dispatch reopen the vsm when idle-timeout kicks in.
Poul-Henning Kamp authored
336 int
337 VSL_Open(struct VSM_data *vd, int diag)
338 {
339 struct vsl *vsl;
340 int i;
341
342 CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
343 vsl = vd->vsl;
344 CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
345
8888447 Make VSL_Open not open the shmlog if run with -r
Tollef Fog Heen authored
346 if (vsl->r_fd == -1) {
347 i = VSM_Open(vd, diag);
348 if (i)
349 return (i);
5cbd8ca @bsdphk Make Varnish API aware of the new structure and make everything compile
bsdphk authored
350 if (!VSM_Get(vd, &vsl->vf, VSL_CLASS, NULL, NULL)) {
351 VSM_Close(vd);
352 if (diag)
353 vd->diag(vd->priv,
354 "No VSL chunk found "
355 " (child not started ?)\n");
356 return (1);
357 }
358 vsl->log_start = vsl->vf.b;
359 vsl->log_end = vsl->vf.e;
360 vsl->log_ptr = vsl->log_start + 1;
361 if (!vsl->d_opt) {
362 while (*vsl->log_ptr != VSL_ENDMARKER)
363 vsl->log_ptr = VSL_NEXT(vsl->log_ptr);
364 }
77e7172 First part of shmlog rewrite:
Poul-Henning Kamp authored
365 }
366 return (0);
367 }
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
368
369 /*--------------------------------------------------------------------*/
370
e4d1d36 @bsdphk Polish round over varnishd part of VSM
bsdphk authored
371 int
372 VSL_Matched(const struct VSM_data *vd, uint64_t bitmap)
a69a488 Implement support for multiple matches in varnish tools
Tollef Fog Heen authored
373 {
374 if (vd->vsl->num_matchers > 0) {
375 uint64_t t;
376 t = vd->vsl->num_matchers | (vd->vsl->num_matchers - 1);
377 return (bitmap == t);
378 }
379 return (1);
380 }
Something went wrong with that request. Please try again.