blob: c2a44d9b73a1651c8e67ba7d99dedf3152d39aee [file] [log] [blame]
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001#define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */
Willy Tarreau36b9e222018-11-11 15:19:52 +01002#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <netdb.h>
6#include <ctype.h>
7#include <pwd.h>
8#include <grp.h>
9#include <errno.h>
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <unistd.h>
14
Eric Salama7cea6062020-10-02 11:58:19 +020015#include <haproxy/buf.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020016#include <haproxy/cfgparse.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020017#ifdef USE_CPU_AFFINITY
Amaury Denoyellec90932b2021-04-14 16:16:03 +020018#include <haproxy/cpuset.h>
Amaury Denoyellea6f9c5d2021-04-23 16:58:08 +020019#endif
Willy Tarreau0a3bd392020-06-04 08:52:38 +020020#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020021#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020022#include <haproxy/log.h>
Dragan Dosen13cd54c2020-06-18 18:24:05 +020023#include <haproxy/peers.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020024#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010025
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010026/* some keywords that are still being parsed using strcmp() and are not
27 * registered anywhere. They are used as suggestions for mistyped words.
28 */
29static const char *common_kw_list[] = {
30 "global", "daemon", "master-worker", "noepoll", "nokqueue",
31 "noevports", "nopoll", "busy-polling", "set-dumpable",
32 "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
33 "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
34 "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
35 "tune.chksize", "tune.recv_enough", "tune.buffers.limit",
36 "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
37 "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
38 "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
39 "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
40 "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid",
41 "external-check", "user", "group", "nbproc", "nbthread", "maxconn",
42 "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate",
43 "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n",
44 "chroot", "description", "node", "pidfile", "unix-bind", "log",
45 "log-send-hostname", "server-state-base", "server-state-file",
46 "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv",
47 "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer",
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +010048 "numa-cpu-mapping", "defaults", "listen", "frontend", "backend",
49 "peers", "resolvers",
Willy Tarreaua0e8eb82021-03-12 09:30:14 +010050 NULL /* must be last */
51};
52
Willy Tarreau36b9e222018-11-11 15:19:52 +010053/*
54 * parse a line in a <global> section. Returns the error code, 0 if OK, or
55 * any combination of :
56 * - ERR_ABORT: must abort ASAP
57 * - ERR_FATAL: we can continue parsing but not start the service
58 * - ERR_WARN: a warning has been emitted
59 * - ERR_ALERT: an alert has been emitted
60 * Only the two first ones can stop processing, the two others are just
61 * indicators.
62 */
63int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
64{
65 int err_code = 0;
66 char *errmsg = NULL;
67
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010068 if (strcmp(args[0], "global") == 0) { /* new section */
Willy Tarreau36b9e222018-11-11 15:19:52 +010069 /* no option, nothing special to do */
70 alertif_too_many_args(0, file, linenum, args, &err_code);
71 goto out;
72 }
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +020073 else if (strcmp(args[0], "expose-experimental-directives") == 0) {
74 experimental_directives_allowed = 1;
75 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010076 else if (strcmp(args[0], "daemon") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010077 if (alertif_too_many_args(0, file, linenum, args, &err_code))
78 goto out;
79 global.mode |= MODE_DAEMON;
80 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010081 else if (strcmp(args[0], "master-worker") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010082 if (alertif_too_many_args(1, file, linenum, args, &err_code))
83 goto out;
84 if (*args[1]) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010085 if (strcmp(args[1], "no-exit-on-failure") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010086 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
87 } else {
88 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
89 err_code |= ERR_ALERT | ERR_FATAL;
90 goto out;
91 }
92 }
93 global.mode |= MODE_MWORKER;
94 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +010095 else if (strcmp(args[0], "noepoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +010096 if (alertif_too_many_args(0, file, linenum, args, &err_code))
97 goto out;
98 global.tune.options &= ~GTUNE_USE_EPOLL;
99 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100100 else if (strcmp(args[0], "nokqueue") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100101 if (alertif_too_many_args(0, file, linenum, args, &err_code))
102 goto out;
103 global.tune.options &= ~GTUNE_USE_KQUEUE;
104 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100105 else if (strcmp(args[0], "noevports") == 0) {
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +0000106 if (alertif_too_many_args(0, file, linenum, args, &err_code))
107 goto out;
108 global.tune.options &= ~GTUNE_USE_EVPORTS;
109 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100110 else if (strcmp(args[0], "nopoll") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100111 if (alertif_too_many_args(0, file, linenum, args, &err_code))
112 goto out;
113 global.tune.options &= ~GTUNE_USE_POLL;
114 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100115 else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100116 if (alertif_too_many_args(0, file, linenum, args, &err_code))
117 goto out;
118 if (kwm == KWM_NO)
119 global.tune.options &= ~GTUNE_BUSY_POLLING;
120 else
121 global.tune.options |= GTUNE_BUSY_POLLING;
122 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100123 else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */
Willy Tarreau636848a2019-04-15 19:38:50 +0200124 if (alertif_too_many_args(0, file, linenum, args, &err_code))
125 goto out;
126 if (kwm == KWM_NO)
127 global.tune.options &= ~GTUNE_SET_DUMPABLE;
128 else
129 global.tune.options |= GTUNE_SET_DUMPABLE;
130 }
Amaury Denoyelle0ea2c4f2021-07-09 17:14:30 +0200131 else if (strcmp(args[0], "h2-workaround-bogus-websocket-clients") == 0) { /* "no h2-workaround-bogus-websocket-clients" or "h2-workaround-bogus-websocket-clients" */
132 if (alertif_too_many_args(0, file, linenum, args, &err_code))
133 goto out;
134 if (kwm == KWM_NO)
135 global.tune.options &= ~GTUNE_DISABLE_H2_WEBSOCKET;
136 else
137 global.tune.options |= GTUNE_DISABLE_H2_WEBSOCKET;
138 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100139 else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
Willy Tarreaud96f1122019-12-03 07:07:36 +0100140 if (alertif_too_many_args(0, file, linenum, args, &err_code))
141 goto out;
142 if (kwm == KWM_NO)
143 global.tune.options &= ~GTUNE_INSECURE_FORK;
144 else
145 global.tune.options |= GTUNE_INSECURE_FORK;
146 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100147 else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100148 if (alertif_too_many_args(0, file, linenum, args, &err_code))
149 goto out;
150 if (kwm == KWM_NO)
151 global.tune.options &= ~GTUNE_INSECURE_SETUID;
152 else
153 global.tune.options |= GTUNE_INSECURE_SETUID;
154 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100155 else if (strcmp(args[0], "nosplice") == 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.tune.options &= ~GTUNE_USE_SPLICE;
159 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100160 else if (strcmp(args[0], "nogetaddrinfo") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100161 if (alertif_too_many_args(0, file, linenum, args, &err_code))
162 goto out;
163 global.tune.options &= ~GTUNE_USE_GAI;
164 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100165 else if (strcmp(args[0], "noreuseport") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100166 if (alertif_too_many_args(0, file, linenum, args, &err_code))
167 goto out;
168 global.tune.options &= ~GTUNE_USE_REUSEPORT;
169 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100170 else if (strcmp(args[0], "quiet") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100171 if (alertif_too_many_args(0, file, linenum, args, &err_code))
172 goto out;
173 global.mode |= MODE_QUIET;
174 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100175 else if (strcmp(args[0], "zero-warning") == 0) {
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200176 if (alertif_too_many_args(0, file, linenum, args, &err_code))
177 goto out;
178 global.mode |= MODE_ZERO_WARNING;
179 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100180 else if (strcmp(args[0], "tune.runqueue-depth") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100181 if (alertif_too_many_args(1, file, linenum, args, &err_code))
182 goto out;
183 if (global.tune.runqueue_depth != 0) {
184 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
185 err_code |= ERR_ALERT;
186 goto out;
187 }
188 if (*(args[1]) == 0) {
189 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
190 err_code |= ERR_ALERT | ERR_FATAL;
191 goto out;
192 }
193 global.tune.runqueue_depth = atol(args[1]);
194
195 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100196 else if (strcmp(args[0], "tune.maxpollevents") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100197 if (alertif_too_many_args(1, file, linenum, args, &err_code))
198 goto out;
199 if (global.tune.maxpollevents != 0) {
200 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
201 err_code |= ERR_ALERT;
202 goto out;
203 }
204 if (*(args[1]) == 0) {
205 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
206 err_code |= ERR_ALERT | ERR_FATAL;
207 goto out;
208 }
209 global.tune.maxpollevents = atol(args[1]);
210 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100211 else if (strcmp(args[0], "tune.maxaccept") == 0) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200212 long max;
213
Willy Tarreau36b9e222018-11-11 15:19:52 +0100214 if (alertif_too_many_args(1, file, linenum, args, &err_code))
215 goto out;
216 if (global.tune.maxaccept != 0) {
217 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
218 err_code |= ERR_ALERT;
219 goto out;
220 }
221 if (*(args[1]) == 0) {
222 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
223 err_code |= ERR_ALERT | ERR_FATAL;
224 goto out;
225 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200226 max = atol(args[1]);
227 if (/*max < -1 || */max > INT_MAX) {
228 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
229 err_code |= ERR_ALERT | ERR_FATAL;
230 goto out;
231 }
232 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100233 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100234 else if (strcmp(args[0], "tune.chksize") == 0) {
Christopher Fauletf8c869b2020-11-25 17:33:03 +0100235 ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n",
236 file, linenum, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100237 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100238 else if (strcmp(args[0], "tune.recv_enough") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100239 if (alertif_too_many_args(1, file, linenum, args, &err_code))
240 goto out;
241 if (*(args[1]) == 0) {
242 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
243 err_code |= ERR_ALERT | ERR_FATAL;
244 goto out;
245 }
246 global.tune.recv_enough = atol(args[1]);
247 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100248 else if (strcmp(args[0], "tune.buffers.limit") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100249 if (alertif_too_many_args(1, file, linenum, args, &err_code))
250 goto out;
251 if (*(args[1]) == 0) {
252 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
253 err_code |= ERR_ALERT | ERR_FATAL;
254 goto out;
255 }
256 global.tune.buf_limit = atol(args[1]);
257 if (global.tune.buf_limit) {
258 if (global.tune.buf_limit < 3)
259 global.tune.buf_limit = 3;
260 if (global.tune.buf_limit <= global.tune.reserved_bufs)
261 global.tune.buf_limit = global.tune.reserved_bufs + 1;
262 }
263 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100264 else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100265 if (alertif_too_many_args(1, file, linenum, args, &err_code))
266 goto out;
267 if (*(args[1]) == 0) {
268 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
269 err_code |= ERR_ALERT | ERR_FATAL;
270 goto out;
271 }
272 global.tune.reserved_bufs = atol(args[1]);
273 if (global.tune.reserved_bufs < 2)
274 global.tune.reserved_bufs = 2;
275 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
276 global.tune.buf_limit = global.tune.reserved_bufs + 1;
277 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100278 else if (strcmp(args[0], "tune.bufsize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100279 if (alertif_too_many_args(1, file, linenum, args, &err_code))
280 goto out;
281 if (*(args[1]) == 0) {
282 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
283 err_code |= ERR_ALERT | ERR_FATAL;
284 goto out;
285 }
286 global.tune.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100287 /* round it up to support a two-pointer alignment at the end */
288 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100289 if (global.tune.bufsize <= 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.maxrewrite") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100296 if (alertif_too_many_args(1, file, linenum, args, &err_code))
297 goto out;
298 if (*(args[1]) == 0) {
299 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
300 err_code |= ERR_ALERT | ERR_FATAL;
301 goto out;
302 }
303 global.tune.maxrewrite = atol(args[1]);
304 if (global.tune.maxrewrite < 0) {
305 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
306 err_code |= ERR_ALERT | ERR_FATAL;
307 goto out;
308 }
309 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100310 else if (strcmp(args[0], "tune.idletimer") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100311 unsigned int idle;
312 const char *res;
313
314 if (alertif_too_many_args(1, file, linenum, args, &err_code))
315 goto out;
316 if (*(args[1]) == 0) {
317 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
318 err_code |= ERR_ALERT | ERR_FATAL;
319 goto out;
320 }
321
322 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200323 if (res == PARSE_TIME_OVER) {
324 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
325 file, linenum, args[1], args[0]);
326 err_code |= ERR_ALERT | ERR_FATAL;
327 goto out;
328 }
329 else if (res == PARSE_TIME_UNDER) {
330 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
331 file, linenum, args[1], args[0]);
332 err_code |= ERR_ALERT | ERR_FATAL;
333 goto out;
334 }
335 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100336 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200337 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100338 err_code |= ERR_ALERT | ERR_FATAL;
339 goto out;
340 }
341
342 if (idle > 65535) {
343 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
344 err_code |= ERR_ALERT | ERR_FATAL;
345 goto out;
346 }
347 global.tune.idle_timer = idle;
348 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100349 else if (strcmp(args[0], "tune.rcvbuf.client") == 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.client_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.client_rcvbuf = atol(args[1]);
363 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100364 else if (strcmp(args[0], "tune.rcvbuf.server") == 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.server_rcvbuf != 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.server_rcvbuf = atol(args[1]);
378 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100379 else if (strcmp(args[0], "tune.sndbuf.client") == 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.client_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.client_sndbuf = atol(args[1]);
393 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100394 else if (strcmp(args[0], "tune.sndbuf.server") == 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 (global.tune.server_sndbuf != 0) {
398 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
399 err_code |= ERR_ALERT;
400 goto out;
401 }
402 if (*(args[1]) == 0) {
403 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
404 err_code |= ERR_ALERT | ERR_FATAL;
405 goto out;
406 }
407 global.tune.server_sndbuf = atol(args[1]);
408 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100409 else if (strcmp(args[0], "tune.pipesize") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100410 if (alertif_too_many_args(1, file, linenum, args, &err_code))
411 goto out;
412 if (*(args[1]) == 0) {
413 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
414 err_code |= ERR_ALERT | ERR_FATAL;
415 goto out;
416 }
417 global.tune.pipesize = atol(args[1]);
418 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100419 else if (strcmp(args[0], "tune.http.cookielen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100420 if (alertif_too_many_args(1, file, linenum, args, &err_code))
421 goto out;
422 if (*(args[1]) == 0) {
423 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
424 err_code |= ERR_ALERT | ERR_FATAL;
425 goto out;
426 }
427 global.tune.cookie_len = atol(args[1]) + 1;
428 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100429 else if (strcmp(args[0], "tune.http.logurilen") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100430 if (alertif_too_many_args(1, file, linenum, args, &err_code))
431 goto out;
432 if (*(args[1]) == 0) {
433 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
434 err_code |= ERR_ALERT | ERR_FATAL;
435 goto out;
436 }
437 global.tune.requri_len = atol(args[1]) + 1;
438 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100439 else if (strcmp(args[0], "tune.http.maxhdr") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100440 if (alertif_too_many_args(1, file, linenum, args, &err_code))
441 goto out;
442 if (*(args[1]) == 0) {
443 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
444 err_code |= ERR_ALERT | ERR_FATAL;
445 goto out;
446 }
447 global.tune.max_http_hdr = atoi(args[1]);
448 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
449 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
450 file, linenum, args[0]);
451 err_code |= ERR_ALERT | ERR_FATAL;
452 goto out;
453 }
454 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100455 else if (strcmp(args[0], "tune.comp.maxlevel") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100456 if (alertif_too_many_args(1, file, linenum, args, &err_code))
457 goto out;
458 if (*args[1]) {
459 global.tune.comp_maxlevel = atoi(args[1]);
460 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
461 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
462 file, linenum, args[0]);
463 err_code |= ERR_ALERT | ERR_FATAL;
464 goto out;
465 }
466 } else {
467 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
468 file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100473 else if (strcmp(args[0], "tune.pattern.cache-size") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100474 if (*args[1]) {
475 global.tune.pattern_cache = atoi(args[1]);
476 if (global.tune.pattern_cache < 0) {
477 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
478 file, linenum, args[0]);
479 err_code |= ERR_ALERT | ERR_FATAL;
480 goto out;
481 }
482 } else {
483 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
484 file, linenum, args[0]);
485 err_code |= ERR_ALERT | ERR_FATAL;
486 goto out;
487 }
488 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100489 else if (strcmp(args[0], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100490 if (alertif_too_many_args(1, file, linenum, args, &err_code))
491 goto out;
492 if (global.uid != 0) {
493 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
494 err_code |= ERR_ALERT;
495 goto out;
496 }
497 if (*(args[1]) == 0) {
498 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
499 err_code |= ERR_ALERT | ERR_FATAL;
500 goto out;
501 }
502 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
503 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]);
504 err_code |= ERR_WARN;
505 goto out;
506 }
507
508 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100509 else if (strcmp(args[0], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100510 if (alertif_too_many_args(1, file, linenum, args, &err_code))
511 goto out;
512 if (global.gid != 0) {
513 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
514 err_code |= ERR_ALERT;
515 goto out;
516 }
517 if (*(args[1]) == 0) {
518 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
519 err_code |= ERR_ALERT | ERR_FATAL;
520 goto out;
521 }
522 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
523 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]);
524 err_code |= ERR_WARN;
525 goto out;
526 }
527 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100528 else if (strcmp(args[0], "external-check") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100529 if (alertif_too_many_args(0, file, linenum, args, &err_code))
530 goto out;
531 global.external_check = 1;
532 }
533 /* user/group name handling */
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100534 else if (strcmp(args[0], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100535 struct passwd *ha_user;
536 if (alertif_too_many_args(1, file, linenum, args, &err_code))
537 goto out;
538 if (global.uid != 0) {
539 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
540 err_code |= ERR_ALERT;
541 goto out;
542 }
543 errno = 0;
544 ha_user = getpwnam(args[1]);
545 if (ha_user != NULL) {
546 global.uid = (int)ha_user->pw_uid;
547 }
548 else {
549 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
550 err_code |= ERR_ALERT | ERR_FATAL;
551 }
552 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100553 else if (strcmp(args[0], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100554 struct group *ha_group;
555 if (alertif_too_many_args(1, file, linenum, args, &err_code))
556 goto out;
557 if (global.gid != 0) {
558 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
559 err_code |= ERR_ALERT;
560 goto out;
561 }
562 errno = 0;
563 ha_group = getgrnam(args[1]);
564 if (ha_group != NULL) {
565 global.gid = (int)ha_group->gr_gid;
566 }
567 else {
568 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
569 err_code |= ERR_ALERT | ERR_FATAL;
570 }
571 }
572 /* end of user/group name handling*/
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100573 else if (strcmp(args[0], "nbproc") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100574 if (alertif_too_many_args(1, file, linenum, args, &err_code))
575 goto out;
576 if (*(args[1]) == 0) {
577 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
578 err_code |= ERR_ALERT | ERR_FATAL;
579 goto out;
580 }
581 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100582 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100583 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100584 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100585 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100586 err_code |= ERR_ALERT | ERR_FATAL;
587 goto out;
588 }
589 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100590 else if (strcmp(args[0], "nbthread") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100591 if (alertif_too_many_args(1, file, linenum, args, &err_code))
592 goto out;
593 if (*(args[1]) == 0) {
594 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
595 err_code |= ERR_ALERT | ERR_FATAL;
596 goto out;
597 }
Amaury Denoyellec4d47d62021-03-29 10:41:15 +0200598
599 HA_DIAG_WARNING_COND(global.nbthread,
600 "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
601 file, linenum);
602
Willy Tarreau36b9e222018-11-11 15:19:52 +0100603 global.nbthread = parse_nbthread(args[1], &errmsg);
604 if (!global.nbthread) {
605 ha_alert("parsing [%s:%d] : '%s' %s.\n",
606 file, linenum, args[0], errmsg);
607 err_code |= ERR_ALERT | ERR_FATAL;
608 goto out;
609 }
610 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100611 else if (strcmp(args[0], "maxconn") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100612 if (alertif_too_many_args(1, file, linenum, args, &err_code))
613 goto out;
614 if (global.maxconn != 0) {
615 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
616 err_code |= ERR_ALERT;
617 goto out;
618 }
619 if (*(args[1]) == 0) {
620 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
621 err_code |= ERR_ALERT | ERR_FATAL;
622 goto out;
623 }
624 global.maxconn = atol(args[1]);
625#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100626 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
627 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);
628 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100629 err_code |= ERR_ALERT;
630 }
631#endif /* SYSTEM_MAXCONN */
632 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100633 else if (strcmp(args[0], "ssl-server-verify") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100634 if (alertif_too_many_args(1, file, linenum, args, &err_code))
635 goto out;
636 if (*(args[1]) == 0) {
637 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
638 err_code |= ERR_ALERT | ERR_FATAL;
639 goto out;
640 }
641 if (strcmp(args[1],"none") == 0)
642 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
643 else if (strcmp(args[1],"required") == 0)
644 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
645 else {
646 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
647 err_code |= ERR_ALERT | ERR_FATAL;
648 goto out;
649 }
650 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100651 else if (strcmp(args[0], "maxconnrate") == 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.cps_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.cps_lim = atol(args[1]);
665 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100666 else if (strcmp(args[0], "maxsessrate") == 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.sps_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.sps_lim = atol(args[1]);
680 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100681 else if (strcmp(args[0], "maxsslrate") == 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 (global.ssl_lim != 0) {
685 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
686 err_code |= ERR_ALERT;
687 goto out;
688 }
689 if (*(args[1]) == 0) {
690 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
691 err_code |= ERR_ALERT | ERR_FATAL;
692 goto out;
693 }
694 global.ssl_lim = atol(args[1]);
695 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100696 else if (strcmp(args[0], "maxcomprate") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100697 if (alertif_too_many_args(1, file, linenum, args, &err_code))
698 goto out;
699 if (*(args[1]) == 0) {
700 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704 global.comp_rate_lim = atoi(args[1]) * 1024;
705 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100706 else if (strcmp(args[0], "maxpipes") == 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 (global.maxpipes != 0) {
710 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
711 err_code |= ERR_ALERT;
712 goto out;
713 }
714 if (*(args[1]) == 0) {
715 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
716 err_code |= ERR_ALERT | ERR_FATAL;
717 goto out;
718 }
719 global.maxpipes = atol(args[1]);
720 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100721 else if (strcmp(args[0], "maxzlibmem") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100722 if (alertif_too_many_args(1, file, linenum, args, &err_code))
723 goto out;
724 if (*(args[1]) == 0) {
725 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
726 err_code |= ERR_ALERT | ERR_FATAL;
727 goto out;
728 }
729 global.maxzlibmem = atol(args[1]) * 1024L * 1024L;
730 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100731 else if (strcmp(args[0], "maxcompcpuusage") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100732 if (alertif_too_many_args(1, file, linenum, args, &err_code))
733 goto out;
734 if (*(args[1]) == 0) {
735 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
736 err_code |= ERR_ALERT | ERR_FATAL;
737 goto out;
738 }
739 compress_min_idle = 100 - atoi(args[1]);
740 if (compress_min_idle > 100) {
741 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
742 err_code |= ERR_ALERT | ERR_FATAL;
743 goto out;
744 }
745 }
746
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100747 else if (strcmp(args[0], "ulimit-n") == 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.rlimit_nofile != 0) {
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 an integer argument.\n", file, linenum, args[0]);
757 err_code |= ERR_ALERT | ERR_FATAL;
758 goto out;
759 }
760 global.rlimit_nofile = atol(args[1]);
761 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100762 else if (strcmp(args[0], "chroot") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100763 if (alertif_too_many_args(1, file, linenum, args, &err_code))
764 goto out;
765 if (global.chroot != NULL) {
766 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
767 err_code |= ERR_ALERT;
768 goto out;
769 }
770 if (*(args[1]) == 0) {
771 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
772 err_code |= ERR_ALERT | ERR_FATAL;
773 goto out;
774 }
775 global.chroot = strdup(args[1]);
776 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100777 else if (strcmp(args[0], "description") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100778 int i, len=0;
779 char *d;
780
781 if (!*args[1]) {
782 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
783 file, linenum, args[0]);
784 err_code |= ERR_ALERT | ERR_FATAL;
785 goto out;
786 }
787
788 for (i = 1; *args[i]; i++)
789 len += strlen(args[i]) + 1;
790
791 if (global.desc)
792 free(global.desc);
793
794 global.desc = d = calloc(1, len);
795
796 d += snprintf(d, global.desc + len - d, "%s", args[1]);
797 for (i = 2; *args[i]; i++)
798 d += snprintf(d, global.desc + len - d, " %s", args[i]);
799 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100800 else if (strcmp(args[0], "node") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100801 int i;
802 char c;
803
804 if (alertif_too_many_args(1, file, linenum, args, &err_code))
805 goto out;
806
807 for (i=0; args[1][i]; i++) {
808 c = args[1][i];
809 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
810 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
811 break;
812 }
813
814 if (!i || args[1][i]) {
815 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
816 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
817 file, linenum, args[0]);
818 err_code |= ERR_ALERT | ERR_FATAL;
819 goto out;
820 }
821
822 if (global.node)
823 free(global.node);
824
825 global.node = strdup(args[1]);
826 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100827 else if (strcmp(args[0], "pidfile") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100828 if (alertif_too_many_args(1, file, linenum, args, &err_code))
829 goto out;
830 if (global.pidfile != NULL) {
831 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
832 err_code |= ERR_ALERT;
833 goto out;
834 }
835 if (*(args[1]) == 0) {
836 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
837 err_code |= ERR_ALERT | ERR_FATAL;
838 goto out;
839 }
840 global.pidfile = strdup(args[1]);
841 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100842 else if (strcmp(args[0], "unix-bind") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100843 int cur_arg = 1;
844 while (*(args[cur_arg])) {
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100845 if (strcmp(args[cur_arg], "prefix") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100846 if (global.unix_bind.prefix != NULL) {
847 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
848 err_code |= ERR_ALERT;
849 cur_arg += 2;
850 continue;
851 }
852
853 if (*(args[cur_arg+1]) == 0) {
854 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
855 err_code |= ERR_ALERT | ERR_FATAL;
856 goto out;
857 }
858 global.unix_bind.prefix = strdup(args[cur_arg+1]);
859 cur_arg += 2;
860 continue;
861 }
862
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100863 if (strcmp(args[cur_arg], "mode") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100864
865 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
866 cur_arg += 2;
867 continue;
868 }
869
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100870 if (strcmp(args[cur_arg], "uid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100871
872 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
873 cur_arg += 2;
874 continue;
875 }
876
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100877 if (strcmp(args[cur_arg], "gid") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100878
879 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
880 cur_arg += 2;
881 continue;
882 }
883
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100884 if (strcmp(args[cur_arg], "user") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100885 struct passwd *user;
886
887 user = getpwnam(args[cur_arg + 1]);
888 if (!user) {
889 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
890 file, linenum, args[0], args[cur_arg + 1 ]);
891 err_code |= ERR_ALERT | ERR_FATAL;
892 goto out;
893 }
894
895 global.unix_bind.ux.uid = user->pw_uid;
896 cur_arg += 2;
897 continue;
898 }
899
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100900 if (strcmp(args[cur_arg], "group") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100901 struct group *group;
902
903 group = getgrnam(args[cur_arg + 1]);
904 if (!group) {
905 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
906 file, linenum, args[0], args[cur_arg + 1 ]);
907 err_code |= ERR_ALERT | ERR_FATAL;
908 goto out;
909 }
910
911 global.unix_bind.ux.gid = group->gr_gid;
912 cur_arg += 2;
913 continue;
914 }
915
916 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
917 file, linenum, args[0]);
918 err_code |= ERR_ALERT | ERR_FATAL;
919 goto out;
920 }
921 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100922 else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */
Emeric Brun9533a702021-04-02 10:13:43 +0200923 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100924 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
925 err_code |= ERR_ALERT | ERR_FATAL;
926 goto out;
927 }
928 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100929 else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100930 char *name;
931
932 if (global.log_send_hostname != 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 name = args[1];
940 else
941 name = hostname;
942
943 free(global.log_send_hostname);
944 global.log_send_hostname = strdup(name);
945 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100946 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 +0100947 if (global.server_state_base != 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' expects one argument: a directory path.\n", file, linenum, args[0]);
955 err_code |= ERR_FATAL;
956 goto out;
957 }
958
959 global.server_state_base = strdup(args[1]);
960 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100961 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 +0100962 if (global.server_state_file != NULL) {
963 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
964 err_code |= ERR_ALERT;
965 goto out;
966 }
967
968 if (!*(args[1])) {
969 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
970 err_code |= ERR_FATAL;
971 goto out;
972 }
973
974 global.server_state_file = strdup(args[1]);
975 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100976 else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100977 if (alertif_too_many_args(1, file, linenum, args, &err_code))
978 goto out;
979 if (*(args[1]) == 0) {
980 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
981 err_code |= ERR_ALERT | ERR_FATAL;
982 goto out;
983 }
984 chunk_destroy(&global.log_tag);
Eric Salama7cea6062020-10-02 11:58:19 +0200985 chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1]));
986 if (b_orig(&global.log_tag) == NULL) {
987 chunk_destroy(&global.log_tag);
988 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]);
989 err_code |= ERR_ALERT | ERR_FATAL;
990 goto out;
991 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100992 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +0100993 else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */
Willy Tarreau36b9e222018-11-11 15:19:52 +0100994 if (alertif_too_many_args(1, file, linenum, args, &err_code))
995 goto out;
996 if (global.spread_checks != 0) {
997 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
998 err_code |= ERR_ALERT;
999 goto out;
1000 }
1001 if (*(args[1]) == 0) {
1002 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1003 err_code |= ERR_ALERT | ERR_FATAL;
1004 goto out;
1005 }
1006 global.spread_checks = atol(args[1]);
1007 if (global.spread_checks < 0 || global.spread_checks > 50) {
1008 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
1009 err_code |= ERR_ALERT | ERR_FATAL;
1010 }
1011 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001012 else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */
Willy Tarreau36b9e222018-11-11 15:19:52 +01001013 const char *err;
1014 unsigned int val;
1015
1016 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1017 goto out;
1018 if (*(args[1]) == 0) {
1019 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
1020 err_code |= ERR_ALERT | ERR_FATAL;
1021 goto out;
1022 }
1023
1024 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +02001025 if (err == PARSE_TIME_OVER) {
1026 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
1027 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001028 err_code |= ERR_ALERT | ERR_FATAL;
1029 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001030 else if (err == PARSE_TIME_UNDER) {
1031 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
1032 file, linenum, args[1], args[0]);
1033 err_code |= ERR_ALERT | ERR_FATAL;
1034 }
1035 else if (err) {
1036 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 +01001037 err_code |= ERR_ALERT | ERR_FATAL;
1038 }
Willy Tarreau9faebe32019-06-07 19:00:37 +02001039 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001040 }
1041 else if (strcmp(args[0], "cpu-map") == 0) {
1042 /* map a process list to a CPU set */
1043#ifdef USE_CPU_AFFINITY
1044 char *slash;
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001045 unsigned long proc = 0, thread = 0;
1046 int i, j, n, autoinc;
1047 struct hap_cpuset cpus, cpus_copy;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001048
1049 if (!*args[1] || !*args[2]) {
1050 ha_alert("parsing [%s:%d] : %s expects a process number "
1051 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1052 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001053 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001054 err_code |= ERR_ALERT | ERR_FATAL;
1055 goto out;
1056 }
1057
1058 if ((slash = strchr(args[1], '/')) != NULL)
1059 *slash = 0;
1060
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001061 /* note: we silently ignore processes over MAX_PROCS and
1062 * threads over MAX_THREADS so as not to make configurations a
1063 * pain to maintain.
1064 */
1065 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001066 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1067 err_code |= ERR_ALERT | ERR_FATAL;
1068 goto out;
1069 }
1070
1071 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001072 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001073 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1074 err_code |= ERR_ALERT | ERR_FATAL;
1075 goto out;
1076 }
1077 *slash = '/';
1078
1079 if (autoinc && atleast2(proc) && atleast2(thread)) {
1080 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1081 "a process range _AND_ a thread range\n",
1082 file, linenum, args[0], args[1]);
1083 err_code |= ERR_ALERT | ERR_FATAL;
1084 goto out;
1085 }
1086 }
1087
Amaury Denoyellea8082352021-04-06 16:46:15 +02001088 if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001089 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1090 err_code |= ERR_ALERT | ERR_FATAL;
1091 goto out;
1092 }
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001093
Willy Tarreau36b9e222018-11-11 15:19:52 +01001094 if (autoinc &&
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001095 my_popcountl(proc) != ha_cpuset_count(&cpus) &&
1096 my_popcountl(thread) != ha_cpuset_count(&cpus)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001097 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1098 "must have the same size to be automatically bound\n",
1099 file, linenum, args[0]);
1100 err_code |= ERR_ALERT | ERR_FATAL;
1101 goto out;
1102 }
1103
Willy Tarreau7764a572019-07-16 15:10:34 +02001104 /* we now have to deal with 3 real cases :
1105 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1106 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1107 * cpu-map 1/T-U => mapping of threads T to U of process 1
1108 * Otherwise other combinations are silently ignored since nbthread
1109 * and nbproc cannot both be >1 :
1110 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1111 * Only one of T,Q may be > 1, others ignored.
1112 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1113 * one of P,U may be > 1, others ignored.
1114 */
1115 if (!thread) {
1116 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001117 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau81492c92019-05-03 09:41:23 +02001118 for (i = n = 0; i < MAX_PROCS; i++) {
1119 /* No mapping for this process */
1120 if (!(proc & (1UL << i)))
1121 continue;
1122
Willy Tarreau36b9e222018-11-11 15:19:52 +01001123 if (!autoinc)
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001124 ha_cpuset_assign(&cpu_map.proc[i], &cpus);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001125 else {
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001126 ha_cpuset_zero(&cpu_map.proc[i]);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001127 n = ha_cpuset_ffs(&cpus_copy) - 1;
1128 ha_cpuset_clr(&cpus_copy, n);
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001129 ha_cpuset_set(&cpu_map.proc[i], n);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001130 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001131 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001132 } else {
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001133 /* Mapping at the thread level.
1134 * Either proc and/or thread must be 1 and only 1. All
1135 * other combinations are silently ignored.
Willy Tarreau7764a572019-07-16 15:10:34 +02001136 */
1137 if (thread == 0x1) {
1138 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001139 struct hap_cpuset *dst;
1140
1141 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001142 for (i = n = 0; i < MAX_PROCS; i++) {
1143 /* No mapping for this process */
1144 if (!(proc & (1UL << i)))
1145 continue;
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001146
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001147 /* For first process, thread[0] is used.
1148 * Use proc_t1[N] for all others
1149 */
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001150 dst = i ? &cpu_map.proc_t1[i] :
1151 &cpu_map.thread[0];
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001152
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001153 if (!autoinc) {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001154 ha_cpuset_assign(dst, &cpus);
Amaury Denoyelleaf02c572021-04-15 16:29:58 +02001155 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001156 else {
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001157 ha_cpuset_zero(dst);
1158 n = ha_cpuset_ffs(&cpus_copy) - 1;
1159 ha_cpuset_clr(&cpus_copy, n);
1160 ha_cpuset_set(dst, n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001161 }
1162 }
1163 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001164
Willy Tarreau7764a572019-07-16 15:10:34 +02001165 if (proc == 0x1) {
1166 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001167 ha_cpuset_assign(&cpus_copy, &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001168 for (j = n = 0; j < MAX_THREADS; j++) {
1169 /* No mapping for this thread */
1170 if (!(thread & (1UL << j)))
1171 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001172
Willy Tarreau7764a572019-07-16 15:10:34 +02001173 if (!autoinc)
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001174 ha_cpuset_assign(&cpu_map.thread[j], &cpus);
Willy Tarreau7764a572019-07-16 15:10:34 +02001175 else {
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001176 ha_cpuset_zero(&cpu_map.thread[j]);
Amaury Denoyelle982fb532021-04-21 18:39:58 +02001177 n = ha_cpuset_ffs(&cpus_copy) - 1;
1178 ha_cpuset_clr(&cpus_copy, n);
Amaury Denoyellefc6ac532021-04-27 10:46:36 +02001179 ha_cpuset_set(&cpu_map.thread[j], n);
Willy Tarreau7764a572019-07-16 15:10:34 +02001180 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001181 }
1182 }
Amaury Denoyellea2944ec2021-04-15 18:07:07 +02001183
1184 HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1,
1185 "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 +01001186 }
1187#else
1188 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1189 file, linenum, args[0]);
1190 err_code |= ERR_ALERT | ERR_FATAL;
1191 goto out;
1192#endif /* ! USE_CPU_AFFINITY */
1193 }
1194 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1195 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1196 goto out;
1197
1198 if (*(args[2]) == 0) {
1199 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1200 err_code |= ERR_ALERT | ERR_FATAL;
1201 goto out;
1202 }
1203
1204 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1205 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1206 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1207 err_code |= ERR_ALERT | ERR_FATAL;
1208 goto out;
1209 }
1210 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001211 else if (strcmp(args[0], "unsetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001212 int arg;
1213
1214 if (*(args[1]) == 0) {
1215 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1216 err_code |= ERR_ALERT | ERR_FATAL;
1217 goto out;
1218 }
1219
1220 for (arg = 1; *args[arg]; arg++) {
1221 if (unsetenv(args[arg]) != 0) {
1222 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 goto out;
1225 }
1226 }
1227 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001228 else if (strcmp(args[0], "resetenv") == 0) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001229 extern char **environ;
1230 char **env = environ;
1231
1232 /* args contain variable names to keep, one per argument */
1233 while (*env) {
1234 int arg;
1235
1236 /* look for current variable in among all those we want to keep */
1237 for (arg = 1; *args[arg]; arg++) {
1238 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1239 (*env)[strlen(args[arg])] == '=')
1240 break;
1241 }
1242
1243 /* delete this variable */
1244 if (!*args[arg]) {
1245 char *delim = strchr(*env, '=');
1246
1247 if (!delim || delim - *env >= trash.size) {
1248 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1249 err_code |= ERR_ALERT | ERR_FATAL;
1250 goto out;
1251 }
1252
1253 memcpy(trash.area, *env, delim - *env);
1254 trash.area[delim - *env] = 0;
1255
1256 if (unsetenv(trash.area) != 0) {
1257 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1258 err_code |= ERR_ALERT | ERR_FATAL;
1259 goto out;
1260 }
1261 }
1262 else
1263 env++;
1264 }
1265 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001266 else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */
William Dauchy0fec3ab2019-10-27 20:08:11 +01001267 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1268 goto out;
1269 if (kwm == KWM_NO)
1270 global.tune.options &= ~GTUNE_STRICT_LIMITS;
William Dauchy0fec3ab2019-10-27 20:08:11 +01001271 }
Tim Duesterhuse5ff1412021-01-02 22:31:53 +01001272 else if (strcmp(args[0], "localpeer") == 0) {
Dragan Dosen13cd54c2020-06-18 18:24:05 +02001273 if (alertif_too_many_args(1, file, linenum, args, &err_code))
1274 goto out;
1275
1276 if (*(args[1]) == 0) {
1277 ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
1278 file, linenum, args[0]);
1279 err_code |= ERR_ALERT | ERR_FATAL;
1280 goto out;
1281 }
1282
1283 if (global.localpeer_cmdline != 0) {
1284 ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
1285 "command line argument.\n", file, linenum, args[0]);
1286 err_code |= ERR_WARN;
1287 goto out;
1288 }
1289
1290 if (cfg_peers) {
1291 ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
1292 file, linenum, args[0]);
1293 err_code |= ERR_WARN;
1294 goto out;
1295 }
1296
1297 free(localpeer);
1298 if ((localpeer = strdup(args[1])) == NULL) {
1299 ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
1300 file, linenum, args[0]);
1301 err_code |= ERR_ALERT | ERR_FATAL;
1302 goto out;
1303 }
1304 setenv("HAPROXY_LOCALPEER", localpeer, 1);
1305 }
Amaury Denoyelle0f50cb92021-03-26 18:50:33 +01001306 else if (strcmp(args[0], "numa-cpu-mapping") == 0) {
1307 global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1;
1308 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001309 else {
1310 struct cfg_kw_list *kwl;
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001311 const char *best;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001312 int index;
1313 int rc;
1314
1315 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1316 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1317 if (kwl->kw[index].section != CFG_GLOBAL)
1318 continue;
1319 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001320 if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) {
Amaury Denoyelle86c1d0f2021-05-07 15:07:21 +02001321 ha_alert("%s\n", errmsg);
Amaury Denoyelled2e53cd2021-05-06 16:21:39 +02001322 err_code |= ERR_ALERT | ERR_FATAL;
1323 goto out;
1324 }
1325
Willy Tarreau36b9e222018-11-11 15:19:52 +01001326 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1327 if (rc < 0) {
1328 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1329 err_code |= ERR_ALERT | ERR_FATAL;
1330 }
1331 else if (rc > 0) {
1332 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1333 err_code |= ERR_WARN;
1334 goto out;
1335 }
1336 goto out;
1337 }
1338 }
1339 }
1340
Willy Tarreau101df312021-03-15 09:12:41 +01001341 best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list);
Willy Tarreaua0e8eb82021-03-12 09:30:14 +01001342 if (best)
1343 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best);
1344 else
1345 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
Willy Tarreau36b9e222018-11-11 15:19:52 +01001346 err_code |= ERR_ALERT | ERR_FATAL;
1347 }
1348
1349 out:
1350 free(errmsg);
1351 return err_code;
1352}
1353