| | varnish-cache/bin/varnishd/mgt/mgt_param.c |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2006 Verdens Gang AS |
| 2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
| 3 |
|
* All rights reserved. |
| 4 |
|
* |
| 5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 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 |
|
|
| 33 |
|
#include <ctype.h> |
| 34 |
|
#include <stdarg.h> |
| 35 |
|
#include <stdio.h> |
| 36 |
|
#include <stdlib.h> |
| 37 |
|
#include <string.h> |
| 38 |
|
#include <unistd.h> |
| 39 |
|
|
| 40 |
|
#include "mgt/mgt.h" |
| 41 |
|
#include "common/heritage.h" |
| 42 |
|
|
| 43 |
|
#include "mgt/mgt_param.h" |
| 44 |
|
#include "vav.h" |
| 45 |
|
#include "vcli_serve.h" |
| 46 |
|
|
| 47 |
|
struct plist { |
| 48 |
|
unsigned magic; |
| 49 |
|
#define PLIST_MAGIC 0xbfc3ea16 |
| 50 |
|
VTAILQ_ENTRY(plist) list; |
| 51 |
|
struct parspec *spec; |
| 52 |
|
}; |
| 53 |
|
|
| 54 |
|
static VTAILQ_HEAD(, plist) phead = VTAILQ_HEAD_INITIALIZER(phead); |
| 55 |
|
|
| 56 |
|
struct params mgt_param; |
| 57 |
|
static const int margin1 = 8; |
| 58 |
|
static int margin2 = 0; |
| 59 |
|
static const int wrap_at = 72; |
| 60 |
|
static const int tab0 = 3; |
| 61 |
|
|
| 62 |
|
/*--------------------------------------------------------------------*/ |
| 63 |
|
|
| 64 |
|
static const char TYPE_TIMEOUT_TEXT[] = |
| 65 |
|
"\n\n" |
| 66 |
|
"NB: This parameter can be disabled with the value \"never\"."; |
| 67 |
|
|
| 68 |
|
static const char OBJ_STICKY_TEXT[] = |
| 69 |
|
"\n\n" |
| 70 |
|
"NB: This parameter is evaluated only when objects are created. " |
| 71 |
|
"To change it for all objects, restart or ban everything."; |
| 72 |
|
|
| 73 |
|
static const char DELAYED_EFFECT_TEXT[] = |
| 74 |
|
"\n\n" |
| 75 |
|
"NB: This parameter may take quite some time to take (full) effect."; |
| 76 |
|
|
| 77 |
|
static const char MUST_RESTART_TEXT[] = |
| 78 |
|
"\n\n" |
| 79 |
|
"NB: This parameter will not take any effect until the " |
| 80 |
|
"child process has been restarted."; |
| 81 |
|
|
| 82 |
|
static const char MUST_RELOAD_TEXT[] = |
| 83 |
|
"\n\n" |
| 84 |
|
"NB: This parameter will not take any effect until the " |
| 85 |
|
"VCL programs have been reloaded."; |
| 86 |
|
|
| 87 |
|
static const char EXPERIMENTAL_TEXT[] = |
| 88 |
|
"\n\n" |
| 89 |
|
"NB: We do not know yet if it is a good idea to change " |
| 90 |
|
"this parameter, or if the default value is even sensible. " |
| 91 |
|
"Caution is advised, and feedback is most welcome."; |
| 92 |
|
|
| 93 |
|
static const char WIZARD_TEXT[] = |
| 94 |
|
"\n\n" |
| 95 |
|
"NB: Do not change this parameter, unless a developer tell " |
| 96 |
|
"you to do so."; |
| 97 |
|
|
| 98 |
|
static const char PROTECTED_TEXT[] = |
| 99 |
|
"\n\n" |
| 100 |
|
"NB: This parameter is protected and cannot be changed."; |
| 101 |
|
|
| 102 |
|
static const char ONLY_ROOT_TEXT[] = |
| 103 |
|
"\n\n" |
| 104 |
|
"NB: This parameter only works if varnishd is run as root."; |
| 105 |
|
|
| 106 |
|
static const char NOT_IMPLEMENTED_TEXT[] = |
| 107 |
|
"\n\n" |
| 108 |
|
"NB: This parameter depends on a feature which is not available" |
| 109 |
|
" on this platform."; |
| 110 |
|
|
| 111 |
|
static const char PLATFORM_DEPENDENT_TEXT[] = |
| 112 |
|
"\n\n" |
| 113 |
|
"NB: This parameter depends on a feature which is not available" |
| 114 |
|
" on all platforms."; |
| 115 |
|
|
| 116 |
|
static const char BUILD_OPTIONS_TEXT[] = |
| 117 |
|
"\n\n" |
| 118 |
|
"NB: The actual default value for this parameter depends on the" |
| 119 |
|
" Varnish build environment and options."; |
| 120 |
|
|
| 121 |
|
/*--------------------------------------------------------------------*/ |
| 122 |
|
|
| 123 |
|
static struct parspec * |
| 124 |
1894840 |
mcf_findpar(const char *name) |
| 125 |
|
{ |
| 126 |
|
struct plist *pl; |
| 127 |
|
|
| 128 |
1894840 |
AN(name); |
| 129 |
180185200 |
VTAILQ_FOREACH(pl, &phead, list) |
| 130 |
180185040 |
if (!strcmp(pl->spec->name, name)) |
| 131 |
1894680 |
return (pl->spec); |
| 132 |
160 |
return (NULL); |
| 133 |
1894840 |
} |
| 134 |
|
|
| 135 |
|
static void |
| 136 |
5232800 |
mcf_addpar(struct parspec *ps) |
| 137 |
|
{ |
| 138 |
|
struct plist *pl, *pl2; |
| 139 |
|
int i; |
| 140 |
|
|
| 141 |
5232800 |
ALLOC_OBJ(pl, PLIST_MAGIC); |
| 142 |
5232800 |
AN(pl); |
| 143 |
5232800 |
pl->spec = ps; |
| 144 |
249781800 |
VTAILQ_FOREACH(pl2, &phead, list) { |
| 145 |
248980000 |
i = strcmp(pl2->spec->name, pl->spec->name); |
| 146 |
248980000 |
if (i == 0) { |
| 147 |
0 |
fprintf(stderr, "Duplicate param: %s\n", ps->name); |
| 148 |
0 |
exit(4); |
| 149 |
248980000 |
} else if (i > 0) { |
| 150 |
4431000 |
VTAILQ_INSERT_BEFORE(pl2, pl, list); |
| 151 |
4431000 |
return; |
| 152 |
|
} |
| 153 |
244549000 |
} |
| 154 |
801800 |
VTAILQ_INSERT_TAIL(&phead, pl, list); |
| 155 |
5232800 |
} |
| 156 |
|
|
| 157 |
|
static const struct parspec * |
| 158 |
240 |
mcf_alias(struct parspec *alias, const struct parspec *pp) |
| 159 |
|
{ |
| 160 |
|
const struct parspec *orig; |
| 161 |
|
|
| 162 |
240 |
orig = TRUST_ME(pp->priv); |
| 163 |
240 |
AN(orig); |
| 164 |
240 |
memcpy(alias, orig, sizeof *alias); |
| 165 |
240 |
alias->priv = TRUST_ME(orig); |
| 166 |
240 |
return (alias); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
/*-------------------------------------------------------------------- |
| 170 |
|
* Wrap the text nicely. |
| 171 |
|
* Lines are allowed to contain two TABS and we render that as a table |
| 172 |
|
* taking the width of the first column into account. |
| 173 |
|
*/ |
| 174 |
|
|
| 175 |
|
static void |
| 176 |
105080 |
mcf_wrap_line(struct cli *cli, const char *b, const char *e, int tabs, int m0) |
| 177 |
|
{ |
| 178 |
105080 |
int n, hadtabs = 0; |
| 179 |
|
const char *w; |
| 180 |
|
|
| 181 |
105080 |
n = m0; |
| 182 |
105080 |
VCLI_Out(cli, "%*s", n, ""); |
| 183 |
|
|
| 184 |
1553200 |
while (b < e) { |
| 185 |
1500560 |
if (!isspace(*b)) { |
| 186 |
728000 |
VCLI_Out(cli, "%c", *b); |
| 187 |
728000 |
b++; |
| 188 |
728000 |
n++; |
| 189 |
1500560 |
} else if (*b == '\t') { |
| 190 |
22560 |
assert(tabs); |
| 191 |
22560 |
assert(hadtabs < 2); |
| 192 |
22560 |
do { |
| 193 |
176280 |
VCLI_Out(cli, " "); |
| 194 |
176280 |
n++; |
| 195 |
176280 |
} while ((n % tabs) != (m0 + tab0) % tabs); |
| 196 |
22560 |
b++; |
| 197 |
22560 |
hadtabs++; |
| 198 |
22560 |
} else { |
| 199 |
750000 |
assert (*b == ' '); |
| 200 |
4496160 |
for (w = b + 1; w < e; w++) |
| 201 |
4443520 |
if (isspace(*w)) |
| 202 |
697360 |
break; |
| 203 |
750000 |
if (n + (w - b) < wrap_at) { |
| 204 |
697560 |
VCLI_Out(cli, "%.*s", (int)(w - b), b); |
| 205 |
697560 |
n += (w - b); |
| 206 |
697560 |
b = w; |
| 207 |
697560 |
} else { |
| 208 |
52440 |
assert(hadtabs == 0 || hadtabs == 2); |
| 209 |
52440 |
VCLI_Out(cli, "\n"); |
| 210 |
104880 |
mcf_wrap_line(cli, b + 1, e, 0, |
| 211 |
52440 |
hadtabs ? m0 + tab0 + tabs : m0); |
| 212 |
52440 |
return; |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
|
} |
| 216 |
52640 |
assert(b == e); |
| 217 |
105080 |
} |
| 218 |
|
|
| 219 |
|
static void |
| 220 |
25640 |
mcf_wrap(struct cli *cli, const char *text) |
| 221 |
|
{ |
| 222 |
|
const char *p, *q, *r; |
| 223 |
25640 |
int tw = 0; |
| 224 |
|
|
| 225 |
25640 |
if (strchr(text, '\t') != NULL) { |
| 226 |
12720 |
for (p = text; *p != '\0'; ) { |
| 227 |
12720 |
q = strstr(p, "\n\t"); |
| 228 |
12720 |
if (q == NULL) |
| 229 |
1440 |
break; |
| 230 |
11280 |
q += 2; |
| 231 |
11280 |
r = strchr(q, '\t'); |
| 232 |
11280 |
if (r == NULL) { |
| 233 |
0 |
fprintf(stderr, |
| 234 |
0 |
"LINE with just one TAB: <%s>\n", text); |
| 235 |
0 |
exit(4); |
| 236 |
|
} |
| 237 |
11280 |
if (r - q > tw) |
| 238 |
4040 |
tw = r - q; |
| 239 |
11280 |
p = q; |
| 240 |
|
} |
| 241 |
1440 |
tw += 2; |
| 242 |
1440 |
if (tw < 20) |
| 243 |
1240 |
tw = 20; |
| 244 |
1440 |
} |
| 245 |
|
|
| 246 |
134360 |
for (p = text; *p != '\0'; ) { |
| 247 |
108720 |
if (*p == '\n') { |
| 248 |
56080 |
VCLI_Out(cli, "\n"); |
| 249 |
56080 |
p++; |
| 250 |
56080 |
continue; |
| 251 |
|
} |
| 252 |
52640 |
q = strchr(p, '\n'); |
| 253 |
52640 |
if (q == NULL) |
| 254 |
25640 |
q = strchr(p, '\0'); |
| 255 |
52640 |
mcf_wrap_line(cli, p, q, tw, margin1); |
| 256 |
52640 |
p = q; |
| 257 |
|
} |
| 258 |
25640 |
} |
| 259 |
|
|
| 260 |
|
/*--------------------------------------------------------------------*/ |
| 261 |
|
|
| 262 |
|
static void v_matchproto_(cli_func_t) |
| 263 |
1320 |
mcf_param_show(struct cli *cli, const char * const *av, void *priv) |
| 264 |
|
{ |
| 265 |
|
struct plist *pl; |
| 266 |
|
const struct parspec *pp, *pa; |
| 267 |
|
struct parspec alias[1]; |
| 268 |
1320 |
int n, lfmt = 0, chg = 0; |
| 269 |
|
struct vsb *vsb; |
| 270 |
1320 |
const char *show = NULL; |
| 271 |
|
|
| 272 |
1320 |
(void)priv; |
| 273 |
|
|
| 274 |
2400 |
for (n = 2; av[n] != NULL; n++) { |
| 275 |
1120 |
if (strcmp(av[n], "-l") == 0) { |
| 276 |
120 |
lfmt = 1; |
| 277 |
120 |
continue; |
| 278 |
|
} |
| 279 |
1000 |
if (strcmp(av[n], "changed") == 0) { |
| 280 |
40 |
chg = 1; |
| 281 |
40 |
continue; |
| 282 |
|
} |
| 283 |
960 |
if (show != NULL) { |
| 284 |
40 |
VCLI_SetResult(cli, CLIS_TOOMANY); |
| 285 |
40 |
VCLI_Out(cli, "Too many parameters"); |
| 286 |
40 |
return; |
| 287 |
|
} |
| 288 |
920 |
show = av[n]; |
| 289 |
920 |
lfmt = 1; |
| 290 |
920 |
} |
| 291 |
|
|
| 292 |
1280 |
vsb = VSB_new_auto(); |
| 293 |
1280 |
AN(vsb); |
| 294 |
|
|
| 295 |
1280 |
n = 0; |
| 296 |
160000 |
VTAILQ_FOREACH(pl, &phead, list) { |
| 297 |
158720 |
pp = pl->spec; |
| 298 |
158720 |
if (lfmt && show != NULL && strcmp(pp->name, show)) |
| 299 |
108280 |
continue; |
| 300 |
50440 |
if (pp->func == tweak_alias) { |
| 301 |
1760 |
if (show == NULL) |
| 302 |
1600 |
continue; |
| 303 |
160 |
if (strcmp(pp->name, show)) |
| 304 |
0 |
continue; |
| 305 |
160 |
pp = mcf_alias(alias, pp); |
| 306 |
160 |
} |
| 307 |
48840 |
n++; |
| 308 |
|
|
| 309 |
48840 |
VSB_clear(vsb); |
| 310 |
48840 |
if (pp->func(vsb, pp, NULL)) |
| 311 |
0 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 312 |
48840 |
AZ(VSB_finish(vsb)); |
| 313 |
48840 |
if (chg && pp->def != NULL && !strcmp(pp->def, VSB_data(vsb))) |
| 314 |
4320 |
continue; |
| 315 |
|
|
| 316 |
44520 |
if (pp->flags & NOT_IMPLEMENTED) { |
| 317 |
0 |
if (lfmt) { |
| 318 |
0 |
VCLI_Out(cli, "%s\n", pp->name); |
| 319 |
0 |
VCLI_Out(cli, "%-*sNot available", margin1, " "); |
| 320 |
0 |
} else { |
| 321 |
0 |
VCLI_Out(cli, "%-*s-", margin2, pp->name); |
| 322 |
|
} |
| 323 |
0 |
} else { |
| 324 |
44520 |
if (lfmt) { |
| 325 |
15240 |
VCLI_Out(cli, "%s\n", pp->name); |
| 326 |
15240 |
VCLI_Out(cli, "%-*sValue is: ", margin1, " "); |
| 327 |
15240 |
} else { |
| 328 |
29280 |
VCLI_Out(cli, "%-*s", margin2, pp->name); |
| 329 |
|
} |
| 330 |
|
|
| 331 |
44520 |
VCLI_Out(cli, "%s", VSB_data(vsb)); |
| 332 |
44520 |
if (pp->units != NULL && *pp->units != '\0') |
| 333 |
35600 |
VCLI_Out(cli, " [%s]", pp->units); |
| 334 |
44520 |
if (pp->def != NULL && !strcmp(pp->def, VSB_data(vsb))) |
| 335 |
39960 |
VCLI_Out(cli, " (default)"); |
| 336 |
|
} |
| 337 |
44520 |
VCLI_Out(cli, "\n"); |
| 338 |
|
|
| 339 |
44520 |
if (lfmt && pp->func == tweak_alias) { |
| 340 |
0 |
pa = TRUST_ME(pp->priv); |
| 341 |
0 |
VCLI_Out(cli, "%-*sAlias of: %s\n", |
| 342 |
0 |
margin1, " ", pa->name); |
| 343 |
0 |
} |
| 344 |
44520 |
if (lfmt && pp->flags & NOT_IMPLEMENTED) { |
| 345 |
0 |
VCLI_Out(cli, "\n"); |
| 346 |
0 |
mcf_wrap(cli, NOT_IMPLEMENTED_TEXT); |
| 347 |
0 |
VCLI_Out(cli, "\n\n"); |
| 348 |
44520 |
} else if (lfmt) { |
| 349 |
15240 |
if (pp->def != NULL && strcmp(pp->def, VSB_data(vsb))) |
| 350 |
3440 |
VCLI_Out(cli, "%-*sDefault is: %s\n", |
| 351 |
1720 |
margin1, "", pp->def); |
| 352 |
15240 |
if (pp->min != NULL) |
| 353 |
23680 |
VCLI_Out(cli, "%-*sMinimum is: %s\n", |
| 354 |
11840 |
margin1, "", pp->min); |
| 355 |
15240 |
if (pp->max != NULL) |
| 356 |
6960 |
VCLI_Out(cli, "%-*sMaximum is: %s\n", |
| 357 |
3480 |
margin1, "", pp->max); |
| 358 |
15240 |
VCLI_Out(cli, "\n"); |
| 359 |
15240 |
mcf_wrap(cli, pp->descr); |
| 360 |
15240 |
if (pp->func == tweak_timeout) |
| 361 |
1600 |
mcf_wrap(cli, TYPE_TIMEOUT_TEXT); |
| 362 |
15240 |
if (pp->flags & OBJ_STICKY) |
| 363 |
520 |
mcf_wrap(cli, OBJ_STICKY_TEXT); |
| 364 |
15240 |
if (pp->flags & DELAYED_EFFECT) |
| 365 |
2160 |
mcf_wrap(cli, DELAYED_EFFECT_TEXT); |
| 366 |
15240 |
if (pp->flags & EXPERIMENTAL) |
| 367 |
3600 |
mcf_wrap(cli, EXPERIMENTAL_TEXT); |
| 368 |
15240 |
if (pp->flags & MUST_RELOAD) |
| 369 |
280 |
mcf_wrap(cli, MUST_RELOAD_TEXT); |
| 370 |
15240 |
if (pp->flags & MUST_RESTART) |
| 371 |
960 |
mcf_wrap(cli, MUST_RESTART_TEXT); |
| 372 |
15240 |
if (pp->flags & WIZARD) |
| 373 |
720 |
mcf_wrap(cli, WIZARD_TEXT); |
| 374 |
15240 |
if (pp->flags & PROTECTED) |
| 375 |
40 |
mcf_wrap(cli, PROTECTED_TEXT); |
| 376 |
15240 |
if (pp->flags & ONLY_ROOT) |
| 377 |
0 |
mcf_wrap(cli, ONLY_ROOT_TEXT); |
| 378 |
15240 |
if (pp->flags & BUILD_OPTIONS) |
| 379 |
520 |
mcf_wrap(cli, BUILD_OPTIONS_TEXT); |
| 380 |
15240 |
VCLI_Out(cli, "\n\n"); |
| 381 |
15240 |
} |
| 382 |
44520 |
} |
| 383 |
1280 |
if (show != NULL && n == 0) { |
| 384 |
40 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 385 |
40 |
VCLI_Out(cli, "Unknown parameter \"%s\".", show); |
| 386 |
40 |
} |
| 387 |
1280 |
VSB_destroy(&vsb); |
| 388 |
1320 |
} |
| 389 |
|
|
| 390 |
|
static inline void |
| 391 |
49920 |
mcf_json_key_valstr(struct cli *cli, const char *key, const char *val) |
| 392 |
|
{ |
| 393 |
49920 |
VCLI_Out(cli, "\"%s\": ", key); |
| 394 |
49920 |
VCLI_JSON_str(cli, val); |
| 395 |
49920 |
VCLI_Out(cli, ",\n"); |
| 396 |
49920 |
} |
| 397 |
|
|
| 398 |
|
static void v_matchproto_(cli_func_t) |
| 399 |
600 |
mcf_param_show_json(struct cli *cli, const char * const *av, void *priv) |
| 400 |
|
{ |
| 401 |
600 |
int n, comma = 0, chg = 0; |
| 402 |
|
struct plist *pl; |
| 403 |
|
const struct parspec *pp, *pa; |
| 404 |
|
struct parspec alias[1]; |
| 405 |
|
struct vsb *vsb, *def; |
| 406 |
600 |
const char *show = NULL, *sep; |
| 407 |
|
|
| 408 |
600 |
(void)priv; |
| 409 |
|
|
| 410 |
1680 |
for (int i = 2; av[i] != NULL; i++) { |
| 411 |
1160 |
if (strcmp(av[i], "-l") == 0) { |
| 412 |
40 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 413 |
40 |
VCLI_Out(cli, "-l not permitted with param.show -j"); |
| 414 |
40 |
return; |
| 415 |
|
} |
| 416 |
1120 |
if (strcmp(av[i], "changed") == 0) { |
| 417 |
40 |
chg = 1; |
| 418 |
40 |
continue; |
| 419 |
|
} |
| 420 |
1080 |
if (strcmp(av[i], "-j") == 0) |
| 421 |
600 |
continue; |
| 422 |
480 |
if (show != NULL) { |
| 423 |
40 |
VCLI_SetResult(cli, CLIS_TOOMANY); |
| 424 |
40 |
VCLI_Out(cli, "Too many parameters"); |
| 425 |
40 |
return; |
| 426 |
|
} |
| 427 |
440 |
show = av[i]; |
| 428 |
440 |
} |
| 429 |
|
|
| 430 |
520 |
vsb = VSB_new_auto(); |
| 431 |
520 |
AN(vsb); |
| 432 |
520 |
def = VSB_new_auto(); |
| 433 |
520 |
AN(def); |
| 434 |
|
|
| 435 |
520 |
n = 0; |
| 436 |
520 |
VCLI_JSON_begin(cli, 2, av); |
| 437 |
520 |
VCLI_Out(cli, ",\n"); |
| 438 |
65000 |
VTAILQ_FOREACH(pl, &phead, list) { |
| 439 |
64480 |
pp = pl->spec; |
| 440 |
64480 |
if (show != NULL && strcmp(pp->name, show) != 0) |
| 441 |
49240 |
continue; |
| 442 |
15240 |
if (pp->func == tweak_alias) { |
| 443 |
520 |
if (show == NULL) |
| 444 |
480 |
continue; |
| 445 |
40 |
if (strcmp(pp->name, show)) |
| 446 |
0 |
continue; |
| 447 |
40 |
pp = mcf_alias(alias, pp); |
| 448 |
40 |
} |
| 449 |
14760 |
n++; |
| 450 |
|
|
| 451 |
14760 |
VSB_clear(vsb); |
| 452 |
14760 |
if (pp->func(vsb, pp, JSON_FMT)) |
| 453 |
0 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 454 |
14760 |
AZ(VSB_finish(vsb)); |
| 455 |
14760 |
VSB_clear(def); |
| 456 |
14760 |
if (pp->func(def, pp, NULL)) |
| 457 |
0 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 458 |
14760 |
AZ(VSB_finish(def)); |
| 459 |
14760 |
if (chg && pp->def != NULL && !strcmp(pp->def, VSB_data(def))) |
| 460 |
4320 |
continue; |
| 461 |
|
|
| 462 |
10440 |
VCLI_Out(cli, "%s", comma ? ",\n" : ""); |
| 463 |
10440 |
comma++; |
| 464 |
10440 |
VCLI_Out(cli, "{\n"); |
| 465 |
10440 |
VSB_indent(cli->sb, 2); |
| 466 |
10440 |
mcf_json_key_valstr(cli, "name", pp->name); |
| 467 |
10440 |
if (pp->func == tweak_alias) { |
| 468 |
0 |
pa = TRUST_ME(pp->priv); |
| 469 |
0 |
mcf_json_key_valstr(cli, "alias", pa->name); |
| 470 |
0 |
} |
| 471 |
10440 |
if (pp->flags & NOT_IMPLEMENTED) { |
| 472 |
0 |
VCLI_Out(cli, "\"implemented\": false\n"); |
| 473 |
0 |
VSB_indent(cli->sb, -2); |
| 474 |
0 |
VCLI_Out(cli, "}"); |
| 475 |
0 |
continue; |
| 476 |
|
} |
| 477 |
10440 |
VCLI_Out(cli, "\"implemented\": true,\n"); |
| 478 |
10440 |
VCLI_Out(cli, "\"value\": %s,\n", VSB_data(vsb)); |
| 479 |
10440 |
if (pp->units != NULL && *pp->units != '\0') |
| 480 |
8160 |
mcf_json_key_valstr(cli, "units", pp->units); |
| 481 |
|
|
| 482 |
10440 |
if (pp->def != NULL) |
| 483 |
10440 |
mcf_json_key_valstr(cli, "default", pp->def); |
| 484 |
10440 |
if (pp->min != NULL) |
| 485 |
7960 |
mcf_json_key_valstr(cli, "minimum", pp->min); |
| 486 |
10440 |
if (pp->max != NULL) |
| 487 |
2480 |
mcf_json_key_valstr(cli, "maximum", pp->max); |
| 488 |
10440 |
mcf_json_key_valstr(cli, "description", pp->descr); |
| 489 |
|
|
| 490 |
10440 |
VCLI_Out(cli, "\"flags\": ["); |
| 491 |
10440 |
VSB_indent(cli->sb, 2); |
| 492 |
10440 |
sep = ""; |
| 493 |
|
|
| 494 |
|
#define flag_out(flag, string) do { \ |
| 495 |
|
if (pp->flags & flag) { \ |
| 496 |
|
VCLI_Out(cli, "%s\n", sep); \ |
| 497 |
|
VCLI_Out(cli, "\"%s\"", #string); \ |
| 498 |
|
sep = ","; \ |
| 499 |
|
} \ |
| 500 |
|
} while(0) |
| 501 |
|
|
| 502 |
10440 |
flag_out(OBJ_STICKY, obj_sticky); |
| 503 |
10440 |
flag_out(DELAYED_EFFECT, delayed_effect); |
| 504 |
10440 |
flag_out(EXPERIMENTAL, experimental); |
| 505 |
10440 |
flag_out(MUST_RELOAD, must_reload); |
| 506 |
10440 |
flag_out(MUST_RESTART, must_restart); |
| 507 |
10440 |
flag_out(WIZARD, wizard); |
| 508 |
10440 |
flag_out(PROTECTED, protected); |
| 509 |
10440 |
flag_out(ONLY_ROOT, only_root); |
| 510 |
10440 |
flag_out(BUILD_OPTIONS, build_options); |
| 511 |
|
|
| 512 |
|
#undef flag_out |
| 513 |
|
|
| 514 |
10440 |
if (pp->flags) |
| 515 |
5320 |
VCLI_Out(cli, "\n"); |
| 516 |
10440 |
VSB_indent(cli->sb, -2); |
| 517 |
10440 |
VCLI_Out(cli, "]\n"); |
| 518 |
10440 |
VSB_indent(cli->sb, -2); |
| 519 |
10440 |
VCLI_Out(cli, "}"); |
| 520 |
10440 |
} |
| 521 |
520 |
VCLI_JSON_end(cli); |
| 522 |
520 |
if (show != NULL && n == 0) { |
| 523 |
40 |
VSB_clear(cli->sb); |
| 524 |
40 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 525 |
40 |
VCLI_Out(cli, "Unknown parameter \"%s\".", show); |
| 526 |
40 |
} |
| 527 |
520 |
VSB_destroy(&vsb); |
| 528 |
520 |
VSB_destroy(&def); |
| 529 |
600 |
} |
| 530 |
|
|
| 531 |
|
/*-------------------------------------------------------------------- |
| 532 |
|
* Mark parameters as protected |
| 533 |
|
*/ |
| 534 |
|
|
| 535 |
|
void |
| 536 |
120 |
MCF_ParamProtect(struct cli *cli, const char *args) |
| 537 |
|
{ |
| 538 |
|
const struct parspec *orig; |
| 539 |
|
struct parspec *pp; |
| 540 |
|
char **av; |
| 541 |
|
int i; |
| 542 |
|
|
| 543 |
120 |
av = VAV_Parse(args, NULL, ARGV_COMMA); |
| 544 |
120 |
if (av[0] != NULL) { |
| 545 |
0 |
VCLI_Out(cli, "Parse error: %s", av[0]); |
| 546 |
0 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 547 |
0 |
VAV_Free(av); |
| 548 |
0 |
return; |
| 549 |
|
} |
| 550 |
200 |
for (i = 1; av[i] != NULL; i++) { |
| 551 |
120 |
pp = mcf_findpar(av[i]); |
| 552 |
120 |
if (pp == NULL) { |
| 553 |
0 |
VCLI_Out(cli, "Unknown parameter %s", av[i]); |
| 554 |
0 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 555 |
0 |
break; |
| 556 |
|
} |
| 557 |
120 |
if (pp->func == tweak_alias) { |
| 558 |
40 |
orig = TRUST_ME(pp->priv); |
| 559 |
40 |
AN(orig); |
| 560 |
80 |
VCLI_Out(cli, |
| 561 |
|
"Cannot mark alias %s read only.\n" |
| 562 |
|
"Did you mean to mark %s read only?", |
| 563 |
40 |
pp->name, orig->name); |
| 564 |
40 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 565 |
40 |
break; |
| 566 |
|
} |
| 567 |
80 |
pp->flags |= PROTECTED; |
| 568 |
80 |
} |
| 569 |
120 |
VAV_Free(av); |
| 570 |
120 |
} |
| 571 |
|
|
| 572 |
|
/*--------------------------------------------------------------------*/ |
| 573 |
|
|
| 574 |
|
void |
| 575 |
377440 |
MCF_ParamSet(struct cli *cli, const char *param, const char *val) |
| 576 |
|
{ |
| 577 |
|
const struct parspec *pp; |
| 578 |
|
struct parspec alias[1]; |
| 579 |
|
|
| 580 |
377440 |
pp = mcf_findpar(param); |
| 581 |
377440 |
if (pp == NULL) { |
| 582 |
160 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 583 |
160 |
VCLI_Out(cli, "Unknown parameter \"%s\".", param); |
| 584 |
160 |
return; |
| 585 |
|
} |
| 586 |
377280 |
if (pp->flags & NOT_IMPLEMENTED) { |
| 587 |
0 |
VCLI_SetResult(cli, CLIS_CANT); |
| 588 |
0 |
VCLI_Out(cli, |
| 589 |
|
"parameter \"%s\" is not available on this platform.", |
| 590 |
0 |
param |
| 591 |
|
); |
| 592 |
0 |
return; |
| 593 |
|
} |
| 594 |
377280 |
if (!val) |
| 595 |
1400 |
val = pp->def; |
| 596 |
377280 |
if (pp->func == tweak_alias) { |
| 597 |
40 |
pp = mcf_alias(alias, pp); |
| 598 |
40 |
alias->name = param; |
| 599 |
40 |
} |
| 600 |
377280 |
if (pp->flags & PROTECTED) { |
| 601 |
120 |
VCLI_SetResult(cli, CLIS_AUTH); |
| 602 |
120 |
VCLI_Out(cli, "parameter \"%s\" is protected.", param); |
| 603 |
120 |
return; |
| 604 |
|
} |
| 605 |
377160 |
if (pp->func(cli->sb, pp, val)) |
| 606 |
1160 |
VCLI_SetResult(cli, CLIS_PARAM); |
| 607 |
|
|
| 608 |
377160 |
if (cli->result == CLIS_OK && heritage.param != NULL) |
| 609 |
13880 |
*heritage.param = mgt_param; |
| 610 |
|
|
| 611 |
377160 |
if (cli->result != CLIS_OK) { |
| 612 |
2320 |
VCLI_Out(cli, "\n(attempting to set param '%s' to '%s')", |
| 613 |
1160 |
pp->name, val); |
| 614 |
377160 |
} else if (MCH_Running() && pp->flags & MUST_RESTART) { |
| 615 |
0 |
VCLI_Out(cli, |
| 616 |
|
"\nChange will take effect when child is restarted"); |
| 617 |
376000 |
} else if (pp->flags & MUST_RELOAD) { |
| 618 |
80 |
VCLI_Out(cli, |
| 619 |
|
"\nChange will take effect when VCL script is reloaded"); |
| 620 |
80 |
} |
| 621 |
377440 |
} |
| 622 |
|
|
| 623 |
|
|
| 624 |
|
/*--------------------------------------------------------------------*/ |
| 625 |
|
|
| 626 |
|
static void v_matchproto_(cli_func_t) |
| 627 |
22160 |
mcf_param_set(struct cli *cli, const char * const *av, void *priv) |
| 628 |
|
{ |
| 629 |
|
|
| 630 |
22160 |
(void)priv; |
| 631 |
22160 |
MCF_ParamSet(cli, av[2], av[3]); |
| 632 |
22160 |
} |
| 633 |
|
|
| 634 |
|
static void v_matchproto_(cli_func_t) |
| 635 |
240 |
mcf_param_set_json(struct cli *cli, const char * const *av, void *priv) |
| 636 |
|
{ |
| 637 |
240 |
const char *const avs[] = { av[0], av[1], av[2], av[3], NULL }; |
| 638 |
|
|
| 639 |
240 |
MCF_ParamSet(cli, av[3], av[4]); |
| 640 |
240 |
if (cli->result == CLIS_OK) |
| 641 |
240 |
mcf_param_show_json(cli, avs, priv); |
| 642 |
240 |
} |
| 643 |
|
|
| 644 |
|
/*--------------------------------------------------------------------*/ |
| 645 |
|
|
| 646 |
|
static void v_matchproto_(cli_func_t) |
| 647 |
1360 |
mcf_param_reset(struct cli *cli, const char * const *av, void *priv) |
| 648 |
|
{ |
| 649 |
|
|
| 650 |
1360 |
(void)priv; |
| 651 |
1360 |
MCF_ParamSet(cli, av[2], NULL); |
| 652 |
1360 |
} |
| 653 |
|
|
| 654 |
|
/*-------------------------------------------------------------------- |
| 655 |
|
* Initialize parameters and sort by name. |
| 656 |
|
*/ |
| 657 |
|
|
| 658 |
|
static struct parspec mgt_parspec[] = { |
| 659 |
|
#define PARAM_ALL |
| 660 |
|
#define PARAM_PRE { |
| 661 |
|
#define PARAM(typ, fld, nm, ...) #nm, __VA_ARGS__ |
| 662 |
|
#define PARAM_POST }, |
| 663 |
|
#include "tbl/params.h" |
| 664 |
|
{ NULL, NULL, NULL } |
| 665 |
|
}; |
| 666 |
|
|
| 667 |
|
static void |
| 668 |
42200 |
mcf_init_params(void) |
| 669 |
|
{ |
| 670 |
|
struct parspec *pp; |
| 671 |
|
const char *s; |
| 672 |
|
|
| 673 |
5275000 |
for (pp = mgt_parspec; pp->name != NULL; pp++) { |
| 674 |
5232800 |
AN(pp->func); |
| 675 |
5232800 |
s = strchr(pp->descr, '\0'); |
| 676 |
5232800 |
if (isspace(s[-1])) { |
| 677 |
0 |
fprintf(stderr, |
| 678 |
0 |
"Param->descr has trailing space: %s\n", pp->name); |
| 679 |
0 |
exit(4); |
| 680 |
|
} |
| 681 |
5232800 |
mcf_addpar(pp); |
| 682 |
5232800 |
margin2 = vmax_t(int, margin2, strlen(pp->name) + 1); |
| 683 |
5232800 |
} |
| 684 |
42200 |
} |
| 685 |
|
|
| 686 |
|
/*-------------------------------------------------------------------- |
| 687 |
|
* Wash a min/max/default value |
| 688 |
|
*/ |
| 689 |
|
|
| 690 |
|
static void |
| 691 |
3627280 |
mcf_dyn_vsb(enum mcf_which_e which, struct parspec *pp, struct vsb *vsb) |
| 692 |
|
{ |
| 693 |
|
|
| 694 |
3627280 |
switch (which) { |
| 695 |
|
case MCF_DEFAULT: |
| 696 |
1181600 |
REPLACE(pp->dyn_def, VSB_data(vsb)); |
| 697 |
1181600 |
pp->def = pp->dyn_def; |
| 698 |
1181600 |
break; |
| 699 |
|
case MCF_MINIMUM: |
| 700 |
1517520 |
REPLACE(pp->dyn_min, VSB_data(vsb)); |
| 701 |
1517520 |
pp->min = pp->dyn_min; |
| 702 |
1517520 |
break; |
| 703 |
|
case MCF_MAXIMUM: |
| 704 |
928160 |
REPLACE(pp->dyn_max, VSB_data(vsb)); |
| 705 |
928160 |
pp->max = pp->dyn_max; |
| 706 |
928160 |
break; |
| 707 |
|
default: |
| 708 |
0 |
WRONG("bad 'which'"); |
| 709 |
0 |
} |
| 710 |
3627280 |
} |
| 711 |
|
|
| 712 |
|
static void |
| 713 |
10465600 |
mcf_wash_param(struct cli *cli, struct parspec *pp, enum mcf_which_e which, |
| 714 |
|
const char *name, struct vsb *vsb) |
| 715 |
|
{ |
| 716 |
|
const char *val; |
| 717 |
|
int err; |
| 718 |
|
|
| 719 |
10465600 |
switch (which) { |
| 720 |
5232800 |
case MCF_DEFAULT: val = pp->def; break; |
| 721 |
4009000 |
case MCF_MINIMUM: val = pp->min; break; |
| 722 |
1223800 |
case MCF_MAXIMUM: val = pp->max; break; |
| 723 |
|
default: |
| 724 |
0 |
WRONG("bad 'which'"); |
| 725 |
0 |
} |
| 726 |
10465600 |
AN(val); |
| 727 |
|
|
| 728 |
10465600 |
if (pp->func == tweak_alias) { |
| 729 |
168800 |
assert(which == MCF_DEFAULT); |
| 730 |
168800 |
pp->priv = mcf_findpar(pp->def); |
| 731 |
168800 |
pp->def = NULL; |
| 732 |
168800 |
return; |
| 733 |
|
} |
| 734 |
|
|
| 735 |
10296800 |
VSB_clear(vsb); |
| 736 |
20593600 |
VSB_printf(vsb, "FAILED to set %s for param %s: %s\n", |
| 737 |
10296800 |
name, pp->name, val); |
| 738 |
10296800 |
err = pp->func(vsb, pp, val); |
| 739 |
10296800 |
AZ(VSB_finish(vsb)); |
| 740 |
10296800 |
if (err) { |
| 741 |
0 |
VCLI_Out(cli, "%s\n", VSB_data(vsb)); |
| 742 |
0 |
VCLI_SetResult(cli, CLIS_CANT); |
| 743 |
0 |
return; |
| 744 |
|
} |
| 745 |
10296800 |
VSB_clear(vsb); |
| 746 |
10296800 |
err = pp->func(vsb, pp, NULL); |
| 747 |
10296800 |
AZ(err); |
| 748 |
10296800 |
AZ(VSB_finish(vsb)); |
| 749 |
10296800 |
if (strcmp(val, VSB_data(vsb))) |
| 750 |
2278800 |
mcf_dyn_vsb(which, pp, vsb); |
| 751 |
10465600 |
} |
| 752 |
|
|
| 753 |
|
/*--------------------------------------------------------------------*/ |
| 754 |
|
|
| 755 |
|
static struct cli_proto cli_params[] = { |
| 756 |
|
{ CLICMD_PARAM_SHOW, "", mcf_param_show, mcf_param_show_json }, |
| 757 |
|
{ CLICMD_PARAM_SET, "", mcf_param_set, mcf_param_set_json }, |
| 758 |
|
{ CLICMD_PARAM_RESET, "", mcf_param_reset, mcf_param_set_json }, |
| 759 |
|
{ NULL } |
| 760 |
|
}; |
| 761 |
|
|
| 762 |
|
/*-------------------------------------------------------------------- |
| 763 |
|
* Configure the parameters |
| 764 |
|
*/ |
| 765 |
|
|
| 766 |
|
void |
| 767 |
42200 |
MCF_InitParams(struct cli *cli) |
| 768 |
|
{ |
| 769 |
|
struct plist *pl; |
| 770 |
|
struct parspec *pp; |
| 771 |
|
struct vsb *vsb; |
| 772 |
|
ssize_t def, low; |
| 773 |
|
|
| 774 |
42200 |
mcf_init_params(); |
| 775 |
42200 |
MCF_TcpParams(); |
| 776 |
|
|
| 777 |
42200 |
def = 80 * 1024; |
| 778 |
|
|
| 779 |
|
if (sizeof(void *) < 8) { /*lint !e506 !e774 */ |
| 780 |
|
/* |
| 781 |
|
* Adjust default parameters for 32 bit systems to conserve |
| 782 |
|
* VM space. |
| 783 |
|
* |
| 784 |
|
* Reflect changes in doc/sphinx/reference/varnishd.rst ! |
| 785 |
|
*/ |
| 786 |
|
MCF_ParamConf(MCF_DEFAULT, "workspace_client", "24k"); |
| 787 |
|
MCF_ParamConf(MCF_DEFAULT, "workspace_backend", "20k"); |
| 788 |
|
MCF_ParamConf(MCF_DEFAULT, "http_resp_size", "8k"); |
| 789 |
|
MCF_ParamConf(MCF_DEFAULT, "http_req_size", "12k"); |
| 790 |
|
MCF_ParamConf(MCF_DEFAULT, "gzip_buffer", "4k"); |
| 791 |
|
MCF_ParamConf(MCF_DEFAULT, "vsl_buffer", "4k"); |
| 792 |
|
MCF_ParamConf(MCF_MAXIMUM, "vsl_space", "1G"); |
| 793 |
|
def = 64 * 1024; |
| 794 |
|
} |
| 795 |
|
|
| 796 |
42200 |
low = sysconf(_SC_THREAD_STACK_MIN); |
| 797 |
42200 |
MCF_ParamConf(MCF_MINIMUM, "thread_pool_stack", "%jdb", (intmax_t)low); |
| 798 |
|
|
| 799 |
|
#if defined(ENABLE_SANITIZER) || defined(ENABLE_COVERAGE) |
| 800 |
42200 |
def = 192 * 1024; |
| 801 |
|
#endif |
| 802 |
|
|
| 803 |
42200 |
if (def < low) |
| 804 |
0 |
def = low; |
| 805 |
42200 |
MCF_ParamConf(MCF_DEFAULT, "thread_pool_stack", "%jdb", (intmax_t)def); |
| 806 |
|
|
| 807 |
|
#if !defined(MAX_THREAD_POOLS) |
| 808 |
|
# define MAX_THREAD_POOLS 32 |
| 809 |
|
#endif |
| 810 |
|
|
| 811 |
42200 |
MCF_ParamConf(MCF_MAXIMUM, "thread_pools", "%d", MAX_THREAD_POOLS); |
| 812 |
|
|
| 813 |
|
#if !defined(HAVE_ACCEPT_FILTERS) || defined(__linux) |
| 814 |
|
MCF_ParamConf(MCF_DEFAULT, "accept_filter", "off"); |
| 815 |
|
#endif |
| 816 |
|
|
| 817 |
42200 |
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_params); |
| 818 |
|
|
| 819 |
42200 |
vsb = VSB_new_auto(); |
| 820 |
42200 |
AN(vsb); |
| 821 |
|
|
| 822 |
5275000 |
VTAILQ_FOREACH(pl, &phead, list) { |
| 823 |
5232800 |
pp = pl->spec; |
| 824 |
|
|
| 825 |
5232800 |
if (pp->flags & NOT_IMPLEMENTED) |
| 826 |
0 |
continue; |
| 827 |
5232800 |
if (pp->min != NULL) |
| 828 |
4009000 |
mcf_wash_param(cli, pp, MCF_MINIMUM, "minimum", vsb); |
| 829 |
5232800 |
if (pp->max != NULL) |
| 830 |
1223800 |
mcf_wash_param(cli, pp, MCF_MAXIMUM, "maximum", vsb); |
| 831 |
5232800 |
AN(pp->def); |
| 832 |
5232800 |
mcf_wash_param(cli, pp, MCF_DEFAULT, "default", vsb); |
| 833 |
5232800 |
} |
| 834 |
42200 |
VSB_destroy(&vsb); |
| 835 |
|
|
| 836 |
42200 |
AN(mgt_cc_cmd); |
| 837 |
42200 |
REPLACE(mgt_cc_cmd_def, mgt_cc_cmd); |
| 838 |
42200 |
} |
| 839 |
|
|
| 840 |
|
/*--------------------------------------------------------------------*/ |
| 841 |
|
|
| 842 |
|
void |
| 843 |
1348480 |
MCF_ParamConf(enum mcf_which_e which, const char * const param, |
| 844 |
|
const char *fmt, ...) |
| 845 |
|
{ |
| 846 |
|
struct parspec *pp; |
| 847 |
|
struct vsb *vsb; |
| 848 |
|
va_list ap; |
| 849 |
|
|
| 850 |
1348480 |
pp = mcf_findpar(param); |
| 851 |
1348480 |
AN(pp); |
| 852 |
1348480 |
vsb = VSB_new_auto(); |
| 853 |
1348480 |
AN(vsb); |
| 854 |
1348480 |
va_start(ap, fmt); |
| 855 |
1348480 |
VSB_vprintf(vsb, fmt, ap); |
| 856 |
1348480 |
va_end(ap); |
| 857 |
1348480 |
AZ(VSB_finish(vsb)); |
| 858 |
1348480 |
mcf_dyn_vsb(which, pp, vsb); |
| 859 |
1348480 |
VSB_destroy(&vsb); |
| 860 |
1348480 |
} |
| 861 |
|
|
| 862 |
|
/*--------------------------------------------------------------------*/ |
| 863 |
|
|
| 864 |
|
void |
| 865 |
80 |
MCF_DumpRstParam(void) |
| 866 |
|
{ |
| 867 |
|
struct plist *pl; |
| 868 |
|
const struct parspec *pp; |
| 869 |
|
const char *p, *q, *t1, *t2; |
| 870 |
|
unsigned flags; |
| 871 |
|
size_t z; |
| 872 |
|
|
| 873 |
80 |
printf("\n.. The following is the autogenerated " |
| 874 |
|
"output from varnishd -x parameter\n\n"); |
| 875 |
10000 |
VTAILQ_FOREACH(pl, &phead, list) { |
| 876 |
9920 |
pp = pl->spec; |
| 877 |
9920 |
if (!strcmp("deprecated_dummy", pp->name)) |
| 878 |
80 |
continue; |
| 879 |
9840 |
printf(".. _ref_param_%s:\n\n", pp->name); |
| 880 |
9840 |
printf("%s\n", pp->name); |
| 881 |
157360 |
for (z = 0; z < strlen(pp->name); z++) |
| 882 |
147520 |
printf("~"); |
| 883 |
9840 |
printf("\n"); |
| 884 |
|
|
| 885 |
9840 |
if (pp->flags && pp->flags & PLATFORM_DEPENDENT) |
| 886 |
400 |
printf("\n%s\n\n", PLATFORM_DEPENDENT_TEXT); |
| 887 |
|
|
| 888 |
9840 |
if (pp->flags && pp->flags & BUILD_OPTIONS) |
| 889 |
320 |
printf("\n%s\n\n", BUILD_OPTIONS_TEXT); |
| 890 |
|
|
| 891 |
9840 |
if (pp->units != NULL && *pp->units != '\0') |
| 892 |
7760 |
printf("\t* Units: %s\n", pp->units); |
| 893 |
|
#define MCF_DYN_REASON(lbl, nm) \ |
| 894 |
|
if (pp->dyn_ ## nm ## _reason != NULL) \ |
| 895 |
|
printf("\t* " #lbl ": %s\n", \ |
| 896 |
|
pp->dyn_ ## nm ## _reason); \ |
| 897 |
|
else if (pp->nm != NULL) \ |
| 898 |
|
printf("\t* " #lbl ": %s\n", pp->nm); |
| 899 |
9840 |
MCF_DYN_REASON(Default, def); |
| 900 |
9840 |
MCF_DYN_REASON(Minimum, min); |
| 901 |
9840 |
MCF_DYN_REASON(Maximum, max); |
| 902 |
|
#undef MCF_DYN_REASON |
| 903 |
9840 |
flags = pp->flags & ~DOCS_FLAGS; |
| 904 |
9840 |
if (pp->func == tweak_timeout) |
| 905 |
880 |
flags |= TYPE_TIMEOUT; |
| 906 |
9840 |
if (flags) { |
| 907 |
5440 |
printf("\t* Flags: "); |
| 908 |
5440 |
q = ""; |
| 909 |
|
|
| 910 |
5440 |
if (flags & TYPE_TIMEOUT) { |
| 911 |
880 |
printf("%stimeout", q); |
| 912 |
880 |
q = ", "; |
| 913 |
880 |
} |
| 914 |
5440 |
if (flags & DELAYED_EFFECT) { |
| 915 |
1440 |
printf("%sdelayed", q); |
| 916 |
1440 |
q = ", "; |
| 917 |
1440 |
} |
| 918 |
5440 |
if (flags & MUST_RESTART) { |
| 919 |
640 |
printf("%smust_restart", q); |
| 920 |
640 |
q = ", "; |
| 921 |
640 |
} |
| 922 |
5440 |
if (flags & MUST_RELOAD) { |
| 923 |
160 |
printf("%smust_reload", q); |
| 924 |
160 |
q = ", "; |
| 925 |
160 |
} |
| 926 |
5440 |
if (flags & EXPERIMENTAL) { |
| 927 |
2400 |
printf("%sexperimental", q); |
| 928 |
2400 |
q = ", "; |
| 929 |
2400 |
} |
| 930 |
5440 |
if (flags & WIZARD) { |
| 931 |
480 |
printf("%swizard", q); |
| 932 |
480 |
q = ", "; |
| 933 |
480 |
} |
| 934 |
5440 |
if (flags & ONLY_ROOT) { |
| 935 |
0 |
printf("%sonly_root", q); |
| 936 |
0 |
q = ", "; |
| 937 |
0 |
} |
| 938 |
5440 |
if (flags & OBJ_STICKY) { |
| 939 |
320 |
printf("%sobj_sticky", q); |
| 940 |
320 |
q = ", "; |
| 941 |
320 |
} |
| 942 |
5440 |
printf("\n"); |
| 943 |
5440 |
} |
| 944 |
9840 |
printf("\n"); |
| 945 |
9840 |
p = pp->descr; |
| 946 |
39120 |
while (*p != '\0') { |
| 947 |
29280 |
q = strchr(p, '\n'); |
| 948 |
29280 |
if (q == NULL) |
| 949 |
9840 |
q = strchr(p, '\0'); |
| 950 |
29280 |
t1 = strchr(p, '\t'); |
| 951 |
29280 |
if (t1 != NULL && t1 < q) { |
| 952 |
4400 |
t2 = strchr(t1 + 1, '\t'); |
| 953 |
4400 |
AN(t2); |
| 954 |
4400 |
printf("\n\t*"); |
| 955 |
4400 |
(void)fwrite(t1 + 1, (t2 - 1) - t1, 1, stdout); |
| 956 |
4400 |
printf("*\n\t\t"); |
| 957 |
4400 |
p = t2 + 1; |
| 958 |
4400 |
} |
| 959 |
29280 |
(void)fwrite(p, q - p, 1, stdout); |
| 960 |
29280 |
p = q; |
| 961 |
29280 |
if (*p == '\n') { |
| 962 |
19440 |
printf("\n"); |
| 963 |
19440 |
p++; |
| 964 |
19440 |
} |
| 965 |
29280 |
continue; |
| 966 |
|
} |
| 967 |
9840 |
printf("\n\n"); |
| 968 |
9840 |
} |
| 969 |
80 |
} |