blob: 694cd70776c8443e248d4cd7ba0e2a33170ed600 [file] [log] [blame]
Willy Tarreau36b9e222018-11-11 15:19:52 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <netdb.h>
5#include <ctype.h>
6#include <pwd.h>
7#include <grp.h>
8#include <errno.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <fcntl.h>
12#include <unistd.h>
13
Eric Salama7cea6062020-10-02 11:58:19 +020014#include <haproxy/buf.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020015#include <haproxy/cfgparse.h>
Amaury Denoyellec90932b2021-04-14 16:16:03 +020016#include <haproxy/cpuset.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020017#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020018#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020019#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020020#include <haproxy/peers.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020021#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010022
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010023/* some keywords that are still being parsed using strcmp() and are not
24 * registered anywhere. They are used as suggestions for mistyped words.
25 */
26static const char *common_kw_list[] = {
27 "global", "daemon", "master-worker", "noepoll", "nokqueue",
28 "noevports", "nopoll", "busy-polling", "set-dumpable",
29 "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
30 "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
31 "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
32 "tune.chksize", "tune.recv_enough", "tune.buffers.limit",
33 "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
34 "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
35 "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
36 "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
37 "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
38 "external-check", "user", "group", "nbproc", "nbthread", "maxconn",
39 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
40 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
41 "chroot", "description", "node", "pidfile", "unix-bind", "log",
42 "log-send-hostname", "server-state-base", "server-state-file",
43 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
44 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
45 "defaults", "listen", "frontend", "backend", "peers", "resolvers",
46 NULL /* must be last */
47};
48
Willy Tarreau36b9e222018-11-11 15:19:52 +010049/*
50 * parse a line in a <global> section. Returns the error code, 0 if OK, or
51 * any combination of :
52 * - ERR_ABORT: must abort ASAP
53 * - ERR_FATAL: we can continue parsing but not start the service
54 * - ERR_WARN: a warning has been emitted
55 * - ERR_ALERT: an alert has been emitted
56 * Only the two first ones can stop processing, the two others are just
57 * indicators.
58 */
59int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
60{
61 int err_code = 0;
62 char *errmsg = NULL;
63
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010064 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010065 /* no option, nothing special to do */
66 alertif_too_many_args(0, file, linenum, args, &err_code);
67 goto out;
68 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010069 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010070 if (alertif_too_many_args(0, file, linenum, args, &err_code))
71 goto out;
72 global.mode |= MODE_DAEMON;
73 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010074 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010075 if (alertif_too_many_args(1, file, linenum, args, &err_code))
76 goto out;
77 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010078 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010079 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
80 } else {
81 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
82 err_code |= ERR_ALERT | ERR_FATAL;
83 goto out;
84 }
85 }
86 global.mode |= MODE_MWORKER;
87 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010088 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010089 if (alertif_too_many_args(0, file, linenum, args, &err_code))
90 goto out;
91 global.tune.options &= ~GTUNE_USE_EPOLL;
92 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010093 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010094 if (alertif_too_many_args(0, file, linenum, args, &err_code))
95 goto out;
96 global.tune.options &= ~GTUNE_USE_KQUEUE;
97 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010098 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +000099 if (alertif_too_many_args(0, file, linenum, args, &err_code))
100 goto out;
101 global.tune.options &= ~GTUNE_USE_EVPORTS;
102 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100103 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100104 if (alertif_too_many_args(0, file, linenum, args, &err_code))
105 goto out;
106 global.tune.options &= ~GTUNE_USE_POLL;
107 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100108 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100109 if (alertif_too_many_args(0, file, linenum, args, &err_code))
110 goto out;
111 if (kwm == KWM_NO)
112 global.tune.options &= ~GTUNE_BUSY_POLLING;
113 else
114 global.tune.options |= GTUNE_BUSY_POLLING;
115 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100116 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200117 if (alertif_too_many_args(0, file, linenum, args, &err_code))
118 goto out;
119 if (kwm == KWM_NO)
120 global.tune.options &= ~GTUNE_SET_DUMPABLE;
121 else
122 global.tune.options |= GTUNE_SET_DUMPABLE;
123 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100124 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100125 if (alertif_too_many_args(0, file, linenum, args, &err_code))
126 goto out;
127 if (kwm == KWM_NO)
128 global.tune.options &= ~GTUNE_INSECURE_FORK;
129 else
130 global.tune.options |= GTUNE_INSECURE_FORK;
131 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100132 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100133 if (alertif_too_many_args(0, file, linenum, args, &err_code))
134 goto out;
135 if (kwm == KWM_NO)
136 global.tune.options &= ~GTUNE_INSECURE_SETUID;
137 else
138 global.tune.options |= GTUNE_INSECURE_SETUID;
139 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100140 else if (strcmp(args[0], "nosplice") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100141 if (alertif_too_many_args(0, file, linenum, args, &err_code))
142 goto out;
143 global.tune.options &= ~GTUNE_USE_SPLICE;
144 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100145 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100146 if (alertif_too_many_args(0, file, linenum, args, &err_code))
147 goto out;
148 global.tune.options &= ~GTUNE_USE_GAI;
149 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100150 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100151 if (alertif_too_many_args(0, file, linenum, args, &err_code))
152 goto out;
153 global.tune.options &= ~GTUNE_USE_REUSEPORT;
154 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100155 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100156 if (alertif_too_many_args(0, file, linenum, args, &err_code))
157 goto out;
158 global.mode |= MODE_QUIET;
159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100160 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200161 if (alertif_too_many_args(0, file, linenum, args, &err_code))
162 goto out;
163 global.mode |= MODE_ZERO_WARNING;
164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100165 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100166 if (alertif_too_many_args(1, file, linenum, args, &err_code))
167 goto out;
168 if (global.tune.runqueue_depth != 0) {
169 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
170 err_code |= ERR_ALERT;
171 goto out;
172 }
173 if (*(args[1]) == 0) {
174 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
175 err_code |= ERR_ALERT | ERR_FATAL;
176 goto out;
177 }
178 global.tune.runqueue_depth = atol(args[1]);
179
180 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100181 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100182 if (alertif_too_many_args(1, file, linenum, args, &err_code))
183 goto out;
184 if (global.tune.maxpollevents != 0) {
185 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
186 err_code |= ERR_ALERT;
187 goto out;
188 }
189 if (*(args[1]) == 0) {
190 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
191 err_code |= ERR_ALERT | ERR_FATAL;
192 goto out;
193 }
194 global.tune.maxpollevents = atol(args[1]);
195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100196 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200197 long max;
198
Willy Tarreau36b9e222018-11-11 15:19:52 +0100199 if (alertif_too_many_args(1, file, linenum, args, &err_code))
200 goto out;
201 if (global.tune.maxaccept != 0) {
202 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
203 err_code |= ERR_ALERT;
204 goto out;
205 }
206 if (*(args[1]) == 0) {
207 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
208 err_code |= ERR_ALERT | ERR_FATAL;
209 goto out;
210 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200211 max = atol(args[1]);
212 if (/*max < -1 || */max > INT_MAX) {
213 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
214 err_code |= ERR_ALERT | ERR_FATAL;
215 goto out;
216 }
217 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100218 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100219 else if (strcmp(args[0], "tune.chksize") == 0) {
Christopher Fauletf8c869b2020-11-25 17:33:03 +0100220 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
221 file, linenum, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100222 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100223 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100224 if (alertif_too_many_args(1, file, linenum, args, &err_code))
225 goto out;
226 if (*(args[1]) == 0) {
227 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
228 err_code |= ERR_ALERT | ERR_FATAL;
229 goto out;
230 }
231 global.tune.recv_enough = atol(args[1]);
232 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100233 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100234 if (alertif_too_many_args(1, file, linenum, args, &err_code))
235 goto out;
236 if (*(args[1]) == 0) {
237 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
238 err_code |= ERR_ALERT | ERR_FATAL;
239 goto out;
240 }
241 global.tune.buf_limit = atol(args[1]);
242 if (global.tune.buf_limit) {
243 if (global.tune.buf_limit < 3)
244 global.tune.buf_limit = 3;
245 if (global.tune.buf_limit <= global.tune.reserved_bufs)
246 global.tune.buf_limit = global.tune.reserved_bufs + 1;
247 }
248 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100249 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100250 if (alertif_too_many_args(1, file, linenum, args, &err_code))
251 goto out;
252 if (*(args[1]) == 0) {
253 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
254 err_code |= ERR_ALERT | ERR_FATAL;
255 goto out;
256 }
257 global.tune.reserved_bufs = atol(args[1]);
258 if (global.tune.reserved_bufs < 2)
259 global.tune.reserved_bufs = 2;
260 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
261 global.tune.buf_limit = global.tune.reserved_bufs + 1;
262 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100263 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100264 if (alertif_too_many_args(1, file, linenum, args, &err_code))
265 goto out;
266 if (*(args[1]) == 0) {
267 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
268 err_code |= ERR_ALERT | ERR_FATAL;
269 goto out;
270 }
271 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100272 /* round it up to support a two-pointer alignment at the end */
273 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100274 if (global.tune.bufsize <= 0) {
275 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
276 err_code |= ERR_ALERT | ERR_FATAL;
277 goto out;
278 }
279 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100280 else if (strcmp(args[0], "tune.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100281 if (alertif_too_many_args(1, file, linenum, args, &err_code))
282 goto out;
283 if (*(args[1]) == 0) {
284 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
285 err_code |= ERR_ALERT | ERR_FATAL;
286 goto out;
287 }
288 global.tune.maxrewrite = atol(args[1]);
289 if (global.tune.maxrewrite < 0) {
290 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
291 err_code |= ERR_ALERT | ERR_FATAL;
292 goto out;
293 }
294 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100295 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100296 unsigned int idle;
297 const char *res;
298
299 if (alertif_too_many_args(1, file, linenum, args, &err_code))
300 goto out;
301 if (*(args[1]) == 0) {
302 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
303 err_code |= ERR_ALERT | ERR_FATAL;
304 goto out;
305 }
306
307 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200308 if (res == PARSE_TIME_OVER) {
309 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
310 file, linenum, args[1], args[0]);
311 err_code |= ERR_ALERT | ERR_FATAL;
312 goto out;
313 }
314 else if (res == PARSE_TIME_UNDER) {
315 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
316 file, linenum, args[1], args[0]);
317 err_code |= ERR_ALERT | ERR_FATAL;
318 goto out;
319 }
320 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100321 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200322 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100323 err_code |= ERR_ALERT | ERR_FATAL;
324 goto out;
325 }
326
327 if (idle > 65535) {
328 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
329 err_code |= ERR_ALERT | ERR_FATAL;
330 goto out;
331 }
332 global.tune.idle_timer = idle;
333 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100334 else if (strcmp(args[0], "tune.rcvbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100335 if (alertif_too_many_args(1, file, linenum, args, &err_code))
336 goto out;
337 if (global.tune.client_rcvbuf != 0) {
338 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
339 err_code |= ERR_ALERT;
340 goto out;
341 }
342 if (*(args[1]) == 0) {
343 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
344 err_code |= ERR_ALERT | ERR_FATAL;
345 goto out;
346 }
347 global.tune.client_rcvbuf = atol(args[1]);
348 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100349 else if (strcmp(args[0], "tune.rcvbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100350 if (alertif_too_many_args(1, file, linenum, args, &err_code))
351 goto out;
352 if (global.tune.server_rcvbuf != 0) {
353 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
354 err_code |= ERR_ALERT;
355 goto out;
356 }
357 if (*(args[1]) == 0) {
358 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
359 err_code |= ERR_ALERT | ERR_FATAL;
360 goto out;
361 }
362 global.tune.server_rcvbuf = atol(args[1]);
363 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100364 else if (strcmp(args[0], "tune.sndbuf.client") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100365 if (alertif_too_many_args(1, file, linenum, args, &err_code))
366 goto out;
367 if (global.tune.client_sndbuf != 0) {
368 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
369 err_code |= ERR_ALERT;
370 goto out;
371 }
372 if (*(args[1]) == 0) {
373 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
374 err_code |= ERR_ALERT | ERR_FATAL;
375 goto out;
376 }
377 global.tune.client_sndbuf = atol(args[1]);
378 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100379 else if (strcmp(args[0], "tune.sndbuf.server") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100380 if (alertif_too_many_args(1, file, linenum, args, &err_code))
381 goto out;
382 if (global.tune.server_sndbuf != 0) {
383 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
384 err_code |= ERR_ALERT;
385 goto out;
386 }
387 if (*(args[1]) == 0) {
388 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
389 err_code |= ERR_ALERT | ERR_FATAL;
390 goto out;
391 }
392 global.tune.server_sndbuf = atol(args[1]);
393 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100394 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100395 if (alertif_too_many_args(1, file, linenum, args, &err_code))
396 goto out;
397 if (*(args[1]) == 0) {
398 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
399 err_code |= ERR_ALERT | ERR_FATAL;
400 goto out;
401 }
402 global.tune.pipesize = atol(args[1]);
403 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100404 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100405 if (alertif_too_many_args(1, file, linenum, args, &err_code))
406 goto out;
407 if (*(args[1]) == 0) {
408 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
409 err_code |= ERR_ALERT | ERR_FATAL;
410 goto out;
411 }
412 global.tune.cookie_len = atol(args[1]) + 1;
413 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100414 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100415 if (alertif_too_many_args(1, file, linenum, args, &err_code))
416 goto out;
417 if (*(args[1]) == 0) {
418 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
419 err_code |= ERR_ALERT | ERR_FATAL;
420 goto out;
421 }
422 global.tune.requri_len = atol(args[1]) + 1;
423 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100424 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100425 if (alertif_too_many_args(1, file, linenum, args, &err_code))
426 goto out;
427 if (*(args[1]) == 0) {
428 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
429 err_code |= ERR_ALERT | ERR_FATAL;
430 goto out;
431 }
432 global.tune.max_http_hdr = atoi(args[1]);
433 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
434 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
435 file, linenum, args[0]);
436 err_code |= ERR_ALERT | ERR_FATAL;
437 goto out;
438 }
439 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100440 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100441 if (alertif_too_many_args(1, file, linenum, args, &err_code))
442 goto out;
443 if (*args[1]) {
444 global.tune.comp_maxlevel = atoi(args[1]);
445 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
446 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
447 file, linenum, args[0]);
448 err_code |= ERR_ALERT | ERR_FATAL;
449 goto out;
450 }
451 } else {
452 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
453 file, linenum, args[0]);
454 err_code |= ERR_ALERT | ERR_FATAL;
455 goto out;
456 }
457 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100458 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100459 if (*args[1]) {
460 global.tune.pattern_cache = atoi(args[1]);
461 if (global.tune.pattern_cache < 0) {
462 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
463 file, linenum, args[0]);
464 err_code |= ERR_ALERT | ERR_FATAL;
465 goto out;
466 }
467 } else {
468 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
469 file, linenum, args[0]);
470 err_code |= ERR_ALERT | ERR_FATAL;
471 goto out;
472 }
473 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100474 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100475 if (alertif_too_many_args(1, file, linenum, args, &err_code))
476 goto out;
477 if (global.uid != 0) {
478 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
479 err_code |= ERR_ALERT;
480 goto out;
481 }
482 if (*(args[1]) == 0) {
483 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
484 err_code |= ERR_ALERT | ERR_FATAL;
485 goto out;
486 }
487 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
488 ha_warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]);
489 err_code |= ERR_WARN;
490 goto out;
491 }
492
493 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100494 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100495 if (alertif_too_many_args(1, file, linenum, args, &err_code))
496 goto out;
497 if (global.gid != 0) {
498 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
499 err_code |= ERR_ALERT;
500 goto out;
501 }
502 if (*(args[1]) == 0) {
503 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
504 err_code |= ERR_ALERT | ERR_FATAL;
505 goto out;
506 }
507 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
508 ha_warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]);
509 err_code |= ERR_WARN;
510 goto out;
511 }
512 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100513 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100514 if (alertif_too_many_args(0, file, linenum, args, &err_code))
515 goto out;
516 global.external_check = 1;
517 }
518 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100519 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100520 struct passwd *ha_user;
521 if (alertif_too_many_args(1, file, linenum, args, &err_code))
522 goto out;
523 if (global.uid != 0) {
524 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
525 err_code |= ERR_ALERT;
526 goto out;
527 }
528 errno = 0;
529 ha_user = getpwnam(args[1]);
530 if (ha_user != NULL) {
531 global.uid = (int)ha_user->pw_uid;
532 }
533 else {
534 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
535 err_code |= ERR_ALERT | ERR_FATAL;
536 }
537 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100538 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100539 struct group *ha_group;
540 if (alertif_too_many_args(1, file, linenum, args, &err_code))
541 goto out;
542 if (global.gid != 0) {
543 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
544 err_code |= ERR_ALERT;
545 goto out;
546 }
547 errno = 0;
548 ha_group = getgrnam(args[1]);
549 if (ha_group != NULL) {
550 global.gid = (int)ha_group->gr_gid;
551 }
552 else {
553 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
554 err_code |= ERR_ALERT | ERR_FATAL;
555 }
556 }
557 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100558 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100559 if (alertif_too_many_args(1, file, linenum, args, &err_code))
560 goto out;
561 if (*(args[1]) == 0) {
562 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
563 err_code |= ERR_ALERT | ERR_FATAL;
564 goto out;
565 }
566 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100567 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100568 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100569 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100570 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100571 err_code |= ERR_ALERT | ERR_FATAL;
572 goto out;
573 }
574 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100575 else if (strcmp(args[0], "nbthread") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100576 if (alertif_too_many_args(1, file, linenum, args, &err_code))
577 goto out;
578 if (*(args[1]) == 0) {
579 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
580 err_code |= ERR_ALERT | ERR_FATAL;
581 goto out;
582 }
Amaury Denoyellec4d47d62021-03-29 10:41:15 +0200583
584 HA_DIAG_WARNING_COND(global.nbthread,
585 "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
586 file, linenum);
587
Willy Tarreau36b9e222018-11-11 15:19:52 +0100588 global.nbthread = parse_nbthread(args[1], &errmsg);
589 if (!global.nbthread) {
590 ha_alert("parsing [%s:%d] : '%s' %s.\n",
591 file, linenum, args[0], errmsg);
592 err_code |= ERR_ALERT | ERR_FATAL;
593 goto out;
594 }
595 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100596 else if (strcmp(args[0], "maxconn") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100597 if (alertif_too_many_args(1, file, linenum, args, &err_code))
598 goto out;
599 if (global.maxconn != 0) {
600 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
601 err_code |= ERR_ALERT;
602 goto out;
603 }
604 if (*(args[1]) == 0) {
605 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
606 err_code |= ERR_ALERT | ERR_FATAL;
607 goto out;
608 }
609 global.maxconn = atol(args[1]);
610#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100611 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
612 ha_alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, SYSTEM_MAXCONN);
613 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100614 err_code |= ERR_ALERT;
615 }
616#endif /* SYSTEM_MAXCONN */
617 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100618 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100619 if (alertif_too_many_args(1, file, linenum, args, &err_code))
620 goto out;
621 if (*(args[1]) == 0) {
622 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
623 err_code |= ERR_ALERT | ERR_FATAL;
624 goto out;
625 }
626 if (strcmp(args[1],"none") == 0)
627 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
628 else if (strcmp(args[1],"required") == 0)
629 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
630 else {
631 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
632 err_code |= ERR_ALERT | ERR_FATAL;
633 goto out;
634 }
635 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100636 else if (strcmp(args[0], "maxconnrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100637 if (alertif_too_many_args(1, file, linenum, args, &err_code))
638 goto out;
639 if (global.cps_lim != 0) {
640 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
641 err_code |= ERR_ALERT;
642 goto out;
643 }
644 if (*(args[1]) == 0) {
645 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
646 err_code |= ERR_ALERT | ERR_FATAL;
647 goto out;
648 }
649 global.cps_lim = atol(args[1]);
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[0], "maxsessrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100652 if (alertif_too_many_args(1, file, linenum, args, &err_code))
653 goto out;
654 if (global.sps_lim != 0) {
655 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
656 err_code |= ERR_ALERT;
657 goto out;
658 }
659 if (*(args[1]) == 0) {
660 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
661 err_code |= ERR_ALERT | ERR_FATAL;
662 goto out;
663 }
664 global.sps_lim = atol(args[1]);
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[0], "maxsslrate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100667 if (alertif_too_many_args(1, file, linenum, args, &err_code))
668 goto out;
669 if (global.ssl_lim != 0) {
670 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
671 err_code |= ERR_ALERT;
672 goto out;
673 }
674 if (*(args[1]) == 0) {
675 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
676 err_code |= ERR_ALERT | ERR_FATAL;
677 goto out;
678 }
679 global.ssl_lim = atol(args[1]);
680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100682 if (alertif_too_many_args(1, file, linenum, args, &err_code))
683 goto out;
684 if (*(args[1]) == 0) {
685 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
686 err_code |= ERR_ALERT | ERR_FATAL;
687 goto out;
688 }
689 global.comp_rate_lim = atoi(args[1]) * 1024;
690 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100691 else if (strcmp(args[0], "maxpipes") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100692 if (alertif_too_many_args(1, file, linenum, args, &err_code))
693 goto out;
694 if (global.maxpipes != 0) {
695 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
696 err_code |= ERR_ALERT;
697 goto out;
698 }
699 if (*(args[1]) == 0) {
700 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704 global.maxpipes = atol(args[1]);
705 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100706 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100707 if (alertif_too_many_args(1, file, linenum, args, &err_code))
708 goto out;
709 if (*(args[1]) == 0) {
710 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
711 err_code |= ERR_ALERT | ERR_FATAL;
712 goto out;
713 }
714 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
715 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100716 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100717 if (alertif_too_many_args(1, file, linenum, args, &err_code))
718 goto out;
719 if (*(args[1]) == 0) {
720 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
721 err_code |= ERR_ALERT | ERR_FATAL;
722 goto out;
723 }
724 compress_min_idle = 100 - atoi(args[1]);
725 if (compress_min_idle > 100) {
726 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
727 err_code |= ERR_ALERT | ERR_FATAL;
728 goto out;
729 }
730 }
731
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100732 else if (strcmp(args[0], "ulimit-n") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100733 if (alertif_too_many_args(1, file, linenum, args, &err_code))
734 goto out;
735 if (global.rlimit_nofile != 0) {
736 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
737 err_code |= ERR_ALERT;
738 goto out;
739 }
740 if (*(args[1]) == 0) {
741 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
742 err_code |= ERR_ALERT | ERR_FATAL;
743 goto out;
744 }
745 global.rlimit_nofile = atol(args[1]);
746 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100747 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100748 if (alertif_too_many_args(1, file, linenum, args, &err_code))
749 goto out;
750 if (global.chroot != NULL) {
751 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
752 err_code |= ERR_ALERT;
753 goto out;
754 }
755 if (*(args[1]) == 0) {
756 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760 global.chroot = strdup(args[1]);
761 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100762 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100763 int i, len=0;
764 char *d;
765
766 if (!*args[1]) {
767 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
768 file, linenum, args[0]);
769 err_code |= ERR_ALERT | ERR_FATAL;
770 goto out;
771 }
772
773 for (i = 1; *args[i]; i++)
774 len += strlen(args[i]) + 1;
775
776 if (global.desc)
777 free(global.desc);
778
779 global.desc = d = calloc(1, len);
780
781 d += snprintf(d, global.desc + len - d, "%s", args[1]);
782 for (i = 2; *args[i]; i++)
783 d += snprintf(d, global.desc + len - d, " %s", args[i]);
784 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100785 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100786 int i;
787 char c;
788
789 if (alertif_too_many_args(1, file, linenum, args, &err_code))
790 goto out;
791
792 for (i=0; args[1][i]; i++) {
793 c = args[1][i];
794 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
795 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
796 break;
797 }
798
799 if (!i || args[1][i]) {
800 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
801 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
802 file, linenum, args[0]);
803 err_code |= ERR_ALERT | ERR_FATAL;
804 goto out;
805 }
806
807 if (global.node)
808 free(global.node);
809
810 global.node = strdup(args[1]);
811 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100812 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100813 if (alertif_too_many_args(1, file, linenum, args, &err_code))
814 goto out;
815 if (global.pidfile != NULL) {
816 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
817 err_code |= ERR_ALERT;
818 goto out;
819 }
820 if (*(args[1]) == 0) {
821 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
822 err_code |= ERR_ALERT | ERR_FATAL;
823 goto out;
824 }
825 global.pidfile = strdup(args[1]);
826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100827 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100828 int cur_arg = 1;
829 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100830 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100831 if (global.unix_bind.prefix != NULL) {
832 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
833 err_code |= ERR_ALERT;
834 cur_arg += 2;
835 continue;
836 }
837
838 if (*(args[cur_arg+1]) == 0) {
839 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
840 err_code |= ERR_ALERT | ERR_FATAL;
841 goto out;
842 }
843 global.unix_bind.prefix = strdup(args[cur_arg+1]);
844 cur_arg += 2;
845 continue;
846 }
847
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100848 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100849
850 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
851 cur_arg += 2;
852 continue;
853 }
854
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100855 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100856
857 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
858 cur_arg += 2;
859 continue;
860 }
861
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100862 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100863
864 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
865 cur_arg += 2;
866 continue;
867 }
868
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100869 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100870 struct passwd *user;
871
872 user = getpwnam(args[cur_arg + 1]);
873 if (!user) {
874 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
875 file, linenum, args[0], args[cur_arg + 1 ]);
876 err_code |= ERR_ALERT | ERR_FATAL;
877 goto out;
878 }
879
880 global.unix_bind.ux.uid = user->pw_uid;
881 cur_arg += 2;
882 continue;
883 }
884
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100885 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100886 struct group *group;
887
888 group = getgrnam(args[cur_arg + 1]);
889 if (!group) {
890 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
891 file, linenum, args[0], args[cur_arg + 1 ]);
892 err_code |= ERR_ALERT | ERR_FATAL;
893 goto out;
894 }
895
896 global.unix_bind.ux.gid = group->gr_gid;
897 cur_arg += 2;
898 continue;
899 }
900
901 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
902 file, linenum, args[0]);
903 err_code |= ERR_ALERT | ERR_FATAL;
904 goto out;
905 }
906 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100907 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200908 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100909 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
910 err_code |= ERR_ALERT | ERR_FATAL;
911 goto out;
912 }
913 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100914 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100915 char *name;
916
917 if (global.log_send_hostname != NULL) {
918 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
919 err_code |= ERR_ALERT;
920 goto out;
921 }
922
923 if (*(args[1]))
924 name = args[1];
925 else
926 name = hostname;
927
928 free(global.log_send_hostname);
929 global.log_send_hostname = strdup(name);
930 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100931 else if (strcmp(args[0], "server-state-base") == 0) { /* path base where HAProxy can find server state files */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100932 if (global.server_state_base != NULL) {
933 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
934 err_code |= ERR_ALERT;
935 goto out;
936 }
937
938 if (!*(args[1])) {
939 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
940 err_code |= ERR_FATAL;
941 goto out;
942 }
943
944 global.server_state_base = strdup(args[1]);
945 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100946 else if (strcmp(args[0], "server-state-file") == 0) { /* path to the file where HAProxy can load the server states */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100947 if (global.server_state_file != NULL) {
948 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
949 err_code |= ERR_ALERT;
950 goto out;
951 }
952
953 if (!*(args[1])) {
954 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
955 err_code |= ERR_FATAL;
956 goto out;
957 }
958
959 global.server_state_file = strdup(args[1]);
960 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100961 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100962 if (alertif_too_many_args(1, file, linenum, args, &err_code))
963 goto out;
964 if (*(args[1]) == 0) {
965 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
966 err_code |= ERR_ALERT | ERR_FATAL;
967 goto out;
968 }
969 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200970 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
971 if (b_orig(&global.log_tag) == NULL) {
972 chunk_destroy(&global.log_tag);
973 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
974 err_code |= ERR_ALERT | ERR_FATAL;
975 goto out;
976 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100977 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100978 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100979 if (alertif_too_many_args(1, file, linenum, args, &err_code))
980 goto out;
981 if (global.spread_checks != 0) {
982 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
983 err_code |= ERR_ALERT;
984 goto out;
985 }
986 if (*(args[1]) == 0) {
987 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
988 err_code |= ERR_ALERT | ERR_FATAL;
989 goto out;
990 }
991 global.spread_checks = atol(args[1]);
992 if (global.spread_checks < 0 || global.spread_checks > 50) {
993 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
994 err_code |= ERR_ALERT | ERR_FATAL;
995 }
996 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100997 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100998 const char *err;
999 unsigned int val;
1000
1001 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1002 goto out;
1003 if (*(args[1]) == 0) {
1004 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1005 err_code |= ERR_ALERT | ERR_FATAL;
1006 goto out;
1007 }
1008
1009 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001010 if (err == PARSE_TIME_OVER) {
1011 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1012 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001013 err_code |= ERR_ALERT | ERR_FATAL;
1014 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001015 else if (err == PARSE_TIME_UNDER) {
1016 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1017 file, linenum, args[1], args[0]);
1018 err_code |= ERR_ALERT | ERR_FATAL;
1019 }
1020 else if (err) {
1021 ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001022 err_code |= ERR_ALERT | ERR_FATAL;
1023 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001024 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001025 }
1026 else if (strcmp(args[0], "cpu-map") == 0) {
1027 /* map a process list to a CPU set */
1028#ifdef USE_CPU_AFFINITY
1029 char *slash;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001030 unsigned long proc = 0, thread = 0;
1031 int i, j, n, autoinc;
1032 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001033
1034 if (!*args[1] || !*args[2]) {
1035 ha_alert("parsing [%s:%d] : %s expects a process number "
1036 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1037 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001038 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001039 err_code |= ERR_ALERT | ERR_FATAL;
1040 goto out;
1041 }
1042
1043 if ((slash = strchr(args[1], '/')) != NULL)
1044 *slash = 0;
1045
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001046 /* note: we silently ignore processes over MAX_PROCS and
1047 * threads over MAX_THREADS so as not to make configurations a
1048 * pain to maintain.
1049 */
1050 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001051 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1052 err_code |= ERR_ALERT | ERR_FATAL;
1053 goto out;
1054 }
1055
1056 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001057 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001058 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1059 err_code |= ERR_ALERT | ERR_FATAL;
1060 goto out;
1061 }
1062 *slash = '/';
1063
1064 if (autoinc && atleast2(proc) && atleast2(thread)) {
1065 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1066 "a process range _AND_ a thread range\n",
1067 file, linenum, args[0], args[1]);
1068 err_code |= ERR_ALERT | ERR_FATAL;
1069 goto out;
1070 }
1071 }
1072
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001073 if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001074 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1075 err_code |= ERR_ALERT | ERR_FATAL;
1076 goto out;
1077 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001078
Willy Tarreau36b9e222018-11-11 15:19:52 +01001079 if (autoinc &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001080 my_popcountl(proc) != ha_cpuset_count(&cpus) &&
1081 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001082 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1083 "must have the same size to be automatically bound\n",
1084 file, linenum, args[0]);
1085 err_code |= ERR_ALERT | ERR_FATAL;
1086 goto out;
1087 }
1088
Willy Tarreau7764a572019-07-16 15:10:34 +02001089 /* we now have to deal with 3 real cases :
1090 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1091 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1092 * cpu-map 1/T-U => mapping of threads T to U of process 1
1093 * Otherwise other combinations are silently ignored since nbthread
1094 * and nbproc cannot both be >1 :
1095 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1096 * Only one of T,Q may be > 1, others ignored.
1097 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1098 * one of P,U may be > 1, others ignored.
1099 */
1100 if (!thread) {
1101 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001102 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau81492c92019-05-03 09:41:23 +02001103 for (i = n = 0; i < MAX_PROCS; i++) {
1104 /* No mapping for this process */
1105 if (!(proc & (1UL << i)))
1106 continue;
1107
Willy Tarreau36b9e222018-11-11 15:19:52 +01001108 if (!autoinc)
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001109 ha_cpuset_assign(&global.cpu_map.proc[i], &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001110 else {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001111 ha_cpuset_zero(&global.cpu_map.proc[i]);
1112 n = ha_cpuset_ffs(&cpus_copy) - 1;
1113 ha_cpuset_clr(&cpus_copy, n);
1114 ha_cpuset_set(&global.cpu_map.proc[i], n);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001115 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001116 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001117 } else {
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001118 /* Mapping at the thread level.
1119 * Either proc and/or thread must be 1 and only 1. All
1120 * other combinations are silently ignored.
Willy Tarreau7764a572019-07-16 15:10:34 +02001121 */
1122 if (thread == 0x1) {
1123 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001124 struct hap_cpuset *dst;
1125
1126 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001127 for (i = n = 0; i < MAX_PROCS; i++) {
1128 /* No mapping for this process */
1129 if (!(proc & (1UL << i)))
1130 continue;
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001131
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001132 /* For first process, thread[0] is used.
1133 * Use proc_t1[N] for all others
1134 */
1135 dst = i ? &global.cpu_map.proc_t1[i] :
1136 &global.cpu_map.thread[0];
1137
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001138 if (!autoinc) {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001139 ha_cpuset_assign(dst, &cpus);
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001140 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001141 else {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001142 ha_cpuset_zero(dst);
1143 n = ha_cpuset_ffs(&cpus_copy) - 1;
1144 ha_cpuset_clr(&cpus_copy, n);
1145 ha_cpuset_set(dst, n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001146 }
1147 }
1148 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001149
Willy Tarreau7764a572019-07-16 15:10:34 +02001150 if (proc == 0x1) {
1151 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001152 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001153 for (j = n = 0; j < MAX_THREADS; j++) {
1154 /* No mapping for this thread */
1155 if (!(thread & (1UL << j)))
1156 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001157
Willy Tarreau7764a572019-07-16 15:10:34 +02001158 if (!autoinc)
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001159 ha_cpuset_assign(&global.cpu_map.thread[j], &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001160 else {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001161 ha_cpuset_zero(&global.cpu_map.thread[j]);
1162 n = ha_cpuset_ffs(&cpus_copy) - 1;
1163 ha_cpuset_clr(&cpus_copy, n);
1164 ha_cpuset_set(&global.cpu_map.thread[j], n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001165 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001166 }
1167 }
Amaury Denoyellea2944ec2021-04-15 18:07:07 +02001168
1169 HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1,
1170 "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001171 }
1172#else
1173 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1174 file, linenum, args[0]);
1175 err_code |= ERR_ALERT | ERR_FATAL;
1176 goto out;
1177#endif /* ! USE_CPU_AFFINITY */
1178 }
1179 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1180 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1181 goto out;
1182
1183 if (*(args[2]) == 0) {
1184 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1185 err_code |= ERR_ALERT | ERR_FATAL;
1186 goto out;
1187 }
1188
1189 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1190 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1191 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1192 err_code |= ERR_ALERT | ERR_FATAL;
1193 goto out;
1194 }
1195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001196 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001197 int arg;
1198
1199 if (*(args[1]) == 0) {
1200 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1201 err_code |= ERR_ALERT | ERR_FATAL;
1202 goto out;
1203 }
1204
1205 for (arg = 1; *args[arg]; arg++) {
1206 if (unsetenv(args[arg]) != 0) {
1207 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1208 err_code |= ERR_ALERT | ERR_FATAL;
1209 goto out;
1210 }
1211 }
1212 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001213 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001214 extern char **environ;
1215 char **env = environ;
1216
1217 /* args contain variable names to keep, one per argument */
1218 while (*env) {
1219 int arg;
1220
1221 /* look for current variable in among all those we want to keep */
1222 for (arg = 1; *args[arg]; arg++) {
1223 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1224 (*env)[strlen(args[arg])] == '=')
1225 break;
1226 }
1227
1228 /* delete this variable */
1229 if (!*args[arg]) {
1230 char *delim = strchr(*env, '=');
1231
1232 if (!delim || delim - *env >= trash.size) {
1233 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1234 err_code |= ERR_ALERT | ERR_FATAL;
1235 goto out;
1236 }
1237
1238 memcpy(trash.area, *env, delim - *env);
1239 trash.area[delim - *env] = 0;
1240
1241 if (unsetenv(trash.area) != 0) {
1242 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1243 err_code |= ERR_ALERT | ERR_FATAL;
1244 goto out;
1245 }
1246 }
1247 else
1248 env++;
1249 }
1250 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001251 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001252 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1253 goto out;
1254 if (kwm == KWM_NO)
1255 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001256 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001257 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001258 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1259 goto out;
1260
1261 if (*(args[1]) == 0) {
1262 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1263 file, linenum, args[0]);
1264 err_code |= ERR_ALERT | ERR_FATAL;
1265 goto out;
1266 }
1267
1268 if (global.localpeer_cmdline != 0) {
1269 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1270 "command line argument.\n", file, linenum, args[0]);
1271 err_code |= ERR_WARN;
1272 goto out;
1273 }
1274
1275 if (cfg_peers) {
1276 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1277 file, linenum, args[0]);
1278 err_code |= ERR_WARN;
1279 goto out;
1280 }
1281
1282 free(localpeer);
1283 if ((localpeer = strdup(args[1])) == NULL) {
1284 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1285 file, linenum, args[0]);
1286 err_code |= ERR_ALERT | ERR_FATAL;
1287 goto out;
1288 }
1289 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1290 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001291 else {
1292 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001293 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001294 int index;
1295 int rc;
1296
1297 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1298 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1299 if (kwl->kw[index].section != CFG_GLOBAL)
1300 continue;
1301 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
1302 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1303 if (rc < 0) {
1304 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1305 err_code |= ERR_ALERT | ERR_FATAL;
1306 }
1307 else if (rc > 0) {
1308 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1309 err_code |= ERR_WARN;
1310 goto out;
1311 }
1312 goto out;
1313 }
1314 }
1315 }
1316
Willy Tarreau101df312021-03-15 09:12:41 +01001317 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001318 if (best)
1319 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1320 else
1321 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001322 err_code |= ERR_ALERT | ERR_FATAL;
1323 }
1324
1325 out:
1326 free(errmsg);
1327 return err_code;
1328}
1329