blob: a4fed04464827db40c9214171d6e2556c0d09480 [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
Willy Tarreau6be78492020-06-05 00:00:29 +020014#include <haproxy/cfgparse.h>
Willy Tarreau0a3bd392020-06-04 08:52:38 +020015#include <haproxy/compression.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020016#include <haproxy/global.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020017#include <haproxy/log.h>
18#include <haproxy/tools.h>
Willy Tarreau36b9e222018-11-11 15:19:52 +010019
20/*
21 * parse a line in a <global> section. Returns the error code, 0 if OK, or
22 * any combination of :
23 * - ERR_ABORT: must abort ASAP
24 * - ERR_FATAL: we can continue parsing but not start the service
25 * - ERR_WARN: a warning has been emitted
26 * - ERR_ALERT: an alert has been emitted
27 * Only the two first ones can stop processing, the two others are just
28 * indicators.
29 */
30int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
31{
32 int err_code = 0;
33 char *errmsg = NULL;
34
35 if (!strcmp(args[0], "global")) { /* new section */
36 /* no option, nothing special to do */
37 alertif_too_many_args(0, file, linenum, args, &err_code);
38 goto out;
39 }
40 else if (!strcmp(args[0], "daemon")) {
41 if (alertif_too_many_args(0, file, linenum, args, &err_code))
42 goto out;
43 global.mode |= MODE_DAEMON;
44 }
45 else if (!strcmp(args[0], "master-worker")) {
46 if (alertif_too_many_args(1, file, linenum, args, &err_code))
47 goto out;
48 if (*args[1]) {
49 if (!strcmp(args[1], "no-exit-on-failure")) {
50 global.tune.options |= GTUNE_NOEXIT_ONFAILURE;
51 } else {
52 ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]);
53 err_code |= ERR_ALERT | ERR_FATAL;
54 goto out;
55 }
56 }
57 global.mode |= MODE_MWORKER;
58 }
59 else if (!strcmp(args[0], "debug")) {
60 if (alertif_too_many_args(0, file, linenum, args, &err_code))
61 goto out;
62 global.mode |= MODE_DEBUG;
Willy Tarreau1b857852020-02-25 11:27:22 +010063 ha_warning("parsing [%s:%d] : '%s' must never be used and will be removed in 2.3. If you need debug mode, please use '-d' on the command line.\n", file, linenum, args[0]);
64 err_code |= ERR_WARN;
65 goto out;
Willy Tarreau36b9e222018-11-11 15:19:52 +010066 }
67 else if (!strcmp(args[0], "noepoll")) {
68 if (alertif_too_many_args(0, file, linenum, args, &err_code))
69 goto out;
70 global.tune.options &= ~GTUNE_USE_EPOLL;
71 }
72 else if (!strcmp(args[0], "nokqueue")) {
73 if (alertif_too_many_args(0, file, linenum, args, &err_code))
74 goto out;
75 global.tune.options &= ~GTUNE_USE_KQUEUE;
76 }
Emmanuel Hocdet0ba4f482019-04-08 16:53:32 +000077 else if (!strcmp(args[0], "noevports")) {
78 if (alertif_too_many_args(0, file, linenum, args, &err_code))
79 goto out;
80 global.tune.options &= ~GTUNE_USE_EVPORTS;
81 }
Willy Tarreau36b9e222018-11-11 15:19:52 +010082 else if (!strcmp(args[0], "nopoll")) {
83 if (alertif_too_many_args(0, file, linenum, args, &err_code))
84 goto out;
85 global.tune.options &= ~GTUNE_USE_POLL;
86 }
Willy Tarreaubeb859a2018-11-22 18:07:59 +010087 else if (!strcmp(args[0], "busy-polling")) { /* "no busy-polling" or "busy-polling" */
88 if (alertif_too_many_args(0, file, linenum, args, &err_code))
89 goto out;
90 if (kwm == KWM_NO)
91 global.tune.options &= ~GTUNE_BUSY_POLLING;
92 else
93 global.tune.options |= GTUNE_BUSY_POLLING;
94 }
Willy Tarreau636848a2019-04-15 19:38:50 +020095 else if (!strcmp(args[0], "set-dumpable")) { /* "no set-dumpable" or "set-dumpable" */
96 if (alertif_too_many_args(0, file, linenum, args, &err_code))
97 goto out;
98 if (kwm == KWM_NO)
99 global.tune.options &= ~GTUNE_SET_DUMPABLE;
100 else
101 global.tune.options |= GTUNE_SET_DUMPABLE;
102 }
Willy Tarreaud96f1122019-12-03 07:07:36 +0100103 else if (!strcmp(args[0], "insecure-fork-wanted")) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */
104 if (alertif_too_many_args(0, file, linenum, args, &err_code))
105 goto out;
106 if (kwm == KWM_NO)
107 global.tune.options &= ~GTUNE_INSECURE_FORK;
108 else
109 global.tune.options |= GTUNE_INSECURE_FORK;
110 }
Willy Tarreaua45a8b52019-12-06 16:31:45 +0100111 else if (!strcmp(args[0], "insecure-setuid-wanted")) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */
112 if (alertif_too_many_args(0, file, linenum, args, &err_code))
113 goto out;
114 if (kwm == KWM_NO)
115 global.tune.options &= ~GTUNE_INSECURE_SETUID;
116 else
117 global.tune.options |= GTUNE_INSECURE_SETUID;
118 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100119 else if (!strcmp(args[0], "nosplice")) {
120 if (alertif_too_many_args(0, file, linenum, args, &err_code))
121 goto out;
122 global.tune.options &= ~GTUNE_USE_SPLICE;
123 }
124 else if (!strcmp(args[0], "nogetaddrinfo")) {
125 if (alertif_too_many_args(0, file, linenum, args, &err_code))
126 goto out;
127 global.tune.options &= ~GTUNE_USE_GAI;
128 }
129 else if (!strcmp(args[0], "noreuseport")) {
130 if (alertif_too_many_args(0, file, linenum, args, &err_code))
131 goto out;
132 global.tune.options &= ~GTUNE_USE_REUSEPORT;
133 }
134 else if (!strcmp(args[0], "quiet")) {
135 if (alertif_too_many_args(0, file, linenum, args, &err_code))
136 goto out;
137 global.mode |= MODE_QUIET;
138 }
Willy Tarreau3eb10b82020-04-15 16:42:39 +0200139 else if (!strcmp(args[0], "zero-warning")) {
140 if (alertif_too_many_args(0, file, linenum, args, &err_code))
141 goto out;
142 global.mode |= MODE_ZERO_WARNING;
143 }
Willy Tarreau36b9e222018-11-11 15:19:52 +0100144 else if (!strcmp(args[0], "tune.runqueue-depth")) {
145 if (alertif_too_many_args(1, file, linenum, args, &err_code))
146 goto out;
147 if (global.tune.runqueue_depth != 0) {
148 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
149 err_code |= ERR_ALERT;
150 goto out;
151 }
152 if (*(args[1]) == 0) {
153 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
154 err_code |= ERR_ALERT | ERR_FATAL;
155 goto out;
156 }
157 global.tune.runqueue_depth = atol(args[1]);
158
159 }
160 else if (!strcmp(args[0], "tune.maxpollevents")) {
161 if (alertif_too_many_args(1, file, linenum, args, &err_code))
162 goto out;
163 if (global.tune.maxpollevents != 0) {
164 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
165 err_code |= ERR_ALERT;
166 goto out;
167 }
168 if (*(args[1]) == 0) {
169 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
170 err_code |= ERR_ALERT | ERR_FATAL;
171 goto out;
172 }
173 global.tune.maxpollevents = atol(args[1]);
174 }
175 else if (!strcmp(args[0], "tune.maxaccept")) {
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200176 long max;
177
Willy Tarreau36b9e222018-11-11 15:19:52 +0100178 if (alertif_too_many_args(1, file, linenum, args, &err_code))
179 goto out;
180 if (global.tune.maxaccept != 0) {
181 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
182 err_code |= ERR_ALERT;
183 goto out;
184 }
185 if (*(args[1]) == 0) {
186 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
187 err_code |= ERR_ALERT | ERR_FATAL;
188 goto out;
189 }
Christopher Faulet6b02ab82019-04-30 14:03:56 +0200190 max = atol(args[1]);
191 if (/*max < -1 || */max > INT_MAX) {
192 ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]);
193 err_code |= ERR_ALERT | ERR_FATAL;
194 goto out;
195 }
196 global.tune.maxaccept = max;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100197 }
198 else if (!strcmp(args[0], "tune.chksize")) {
199 if (alertif_too_many_args(1, file, linenum, args, &err_code))
200 goto out;
201 if (*(args[1]) == 0) {
202 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
203 err_code |= ERR_ALERT | ERR_FATAL;
204 goto out;
205 }
206 global.tune.chksize = atol(args[1]);
207 }
208 else if (!strcmp(args[0], "tune.recv_enough")) {
209 if (alertif_too_many_args(1, file, linenum, args, &err_code))
210 goto out;
211 if (*(args[1]) == 0) {
212 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
213 err_code |= ERR_ALERT | ERR_FATAL;
214 goto out;
215 }
216 global.tune.recv_enough = atol(args[1]);
217 }
218 else if (!strcmp(args[0], "tune.buffers.limit")) {
219 if (alertif_too_many_args(1, file, linenum, args, &err_code))
220 goto out;
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 }
226 global.tune.buf_limit = atol(args[1]);
227 if (global.tune.buf_limit) {
228 if (global.tune.buf_limit < 3)
229 global.tune.buf_limit = 3;
230 if (global.tune.buf_limit <= global.tune.reserved_bufs)
231 global.tune.buf_limit = global.tune.reserved_bufs + 1;
232 }
233 }
234 else if (!strcmp(args[0], "tune.buffers.reserve")) {
235 if (alertif_too_many_args(1, file, linenum, args, &err_code))
236 goto out;
237 if (*(args[1]) == 0) {
238 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
239 err_code |= ERR_ALERT | ERR_FATAL;
240 goto out;
241 }
242 global.tune.reserved_bufs = atol(args[1]);
243 if (global.tune.reserved_bufs < 2)
244 global.tune.reserved_bufs = 2;
245 if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
246 global.tune.buf_limit = global.tune.reserved_bufs + 1;
247 }
248 else if (!strcmp(args[0], "tune.bufsize")) {
249 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.bufsize = atol(args[1]);
Willy Tarreauc77d3642018-12-12 06:19:42 +0100257 /* round it up to support a two-pointer alignment at the end */
258 global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *));
Willy Tarreau36b9e222018-11-11 15:19:52 +0100259 if (global.tune.bufsize <= 0) {
260 ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
261 err_code |= ERR_ALERT | ERR_FATAL;
262 goto out;
263 }
264 }
265 else if (!strcmp(args[0], "tune.maxrewrite")) {
266 if (alertif_too_many_args(1, file, linenum, args, &err_code))
267 goto out;
268 if (*(args[1]) == 0) {
269 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
270 err_code |= ERR_ALERT | ERR_FATAL;
271 goto out;
272 }
273 global.tune.maxrewrite = atol(args[1]);
274 if (global.tune.maxrewrite < 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 }
280 else if (!strcmp(args[0], "tune.idletimer")) {
281 unsigned int idle;
282 const char *res;
283
284 if (alertif_too_many_args(1, file, linenum, args, &err_code))
285 goto out;
286 if (*(args[1]) == 0) {
287 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
288 err_code |= ERR_ALERT | ERR_FATAL;
289 goto out;
290 }
291
292 res = parse_time_err(args[1], &idle, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200293 if (res == PARSE_TIME_OVER) {
294 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n",
295 file, linenum, args[1], args[0]);
296 err_code |= ERR_ALERT | ERR_FATAL;
297 goto out;
298 }
299 else if (res == PARSE_TIME_UNDER) {
300 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
301 file, linenum, args[1], args[0]);
302 err_code |= ERR_ALERT | ERR_FATAL;
303 goto out;
304 }
305 else if (res) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100306 ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n",
Willy Tarreau9faebe32019-06-07 19:00:37 +0200307 file, linenum, *res, args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100308 err_code |= ERR_ALERT | ERR_FATAL;
309 goto out;
310 }
311
312 if (idle > 65535) {
313 ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]);
314 err_code |= ERR_ALERT | ERR_FATAL;
315 goto out;
316 }
317 global.tune.idle_timer = idle;
318 }
319 else if (!strcmp(args[0], "tune.rcvbuf.client")) {
320 if (alertif_too_many_args(1, file, linenum, args, &err_code))
321 goto out;
322 if (global.tune.client_rcvbuf != 0) {
323 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
324 err_code |= ERR_ALERT;
325 goto out;
326 }
327 if (*(args[1]) == 0) {
328 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
329 err_code |= ERR_ALERT | ERR_FATAL;
330 goto out;
331 }
332 global.tune.client_rcvbuf = atol(args[1]);
333 }
334 else if (!strcmp(args[0], "tune.rcvbuf.server")) {
335 if (alertif_too_many_args(1, file, linenum, args, &err_code))
336 goto out;
337 if (global.tune.server_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.server_rcvbuf = atol(args[1]);
348 }
349 else if (!strcmp(args[0], "tune.sndbuf.client")) {
350 if (alertif_too_many_args(1, file, linenum, args, &err_code))
351 goto out;
352 if (global.tune.client_sndbuf != 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_sndbuf = atol(args[1]);
363 }
364 else if (!strcmp(args[0], "tune.sndbuf.server")) {
365 if (alertif_too_many_args(1, file, linenum, args, &err_code))
366 goto out;
367 if (global.tune.server_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.server_sndbuf = atol(args[1]);
378 }
379 else if (!strcmp(args[0], "tune.pipesize")) {
380 if (alertif_too_many_args(1, file, linenum, args, &err_code))
381 goto out;
382 if (*(args[1]) == 0) {
383 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
384 err_code |= ERR_ALERT | ERR_FATAL;
385 goto out;
386 }
387 global.tune.pipesize = atol(args[1]);
388 }
389 else if (!strcmp(args[0], "tune.http.cookielen")) {
390 if (alertif_too_many_args(1, file, linenum, args, &err_code))
391 goto out;
392 if (*(args[1]) == 0) {
393 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
394 err_code |= ERR_ALERT | ERR_FATAL;
395 goto out;
396 }
397 global.tune.cookie_len = atol(args[1]) + 1;
398 }
399 else if (!strcmp(args[0], "tune.http.logurilen")) {
400 if (alertif_too_many_args(1, file, linenum, args, &err_code))
401 goto out;
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.requri_len = atol(args[1]) + 1;
408 }
409 else if (!strcmp(args[0], "tune.http.maxhdr")) {
410 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.max_http_hdr = atoi(args[1]);
418 if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) {
419 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n",
420 file, linenum, args[0]);
421 err_code |= ERR_ALERT | ERR_FATAL;
422 goto out;
423 }
424 }
425 else if (!strcmp(args[0], "tune.comp.maxlevel")) {
426 if (alertif_too_many_args(1, file, linenum, args, &err_code))
427 goto out;
428 if (*args[1]) {
429 global.tune.comp_maxlevel = atoi(args[1]);
430 if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
431 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
432 file, linenum, args[0]);
433 err_code |= ERR_ALERT | ERR_FATAL;
434 goto out;
435 }
436 } else {
437 ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
438 file, linenum, args[0]);
439 err_code |= ERR_ALERT | ERR_FATAL;
440 goto out;
441 }
442 }
443 else if (!strcmp(args[0], "tune.pattern.cache-size")) {
444 if (*args[1]) {
445 global.tune.pattern_cache = atoi(args[1]);
446 if (global.tune.pattern_cache < 0) {
447 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
448 file, linenum, args[0]);
449 err_code |= ERR_ALERT | ERR_FATAL;
450 goto out;
451 }
452 } else {
453 ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n",
454 file, linenum, args[0]);
455 err_code |= ERR_ALERT | ERR_FATAL;
456 goto out;
457 }
458 }
459 else if (!strcmp(args[0], "uid")) {
460 if (alertif_too_many_args(1, file, linenum, args, &err_code))
461 goto out;
462 if (global.uid != 0) {
463 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
464 err_code |= ERR_ALERT;
465 goto out;
466 }
467 if (*(args[1]) == 0) {
468 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
469 err_code |= ERR_ALERT | ERR_FATAL;
470 goto out;
471 }
472 if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) {
473 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]);
474 err_code |= ERR_WARN;
475 goto out;
476 }
477
478 }
479 else if (!strcmp(args[0], "gid")) {
480 if (alertif_too_many_args(1, file, linenum, args, &err_code))
481 goto out;
482 if (global.gid != 0) {
483 ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
484 err_code |= ERR_ALERT;
485 goto out;
486 }
487 if (*(args[1]) == 0) {
488 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
489 err_code |= ERR_ALERT | ERR_FATAL;
490 goto out;
491 }
492 if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) {
493 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]);
494 err_code |= ERR_WARN;
495 goto out;
496 }
497 }
498 else if (!strcmp(args[0], "external-check")) {
499 if (alertif_too_many_args(0, file, linenum, args, &err_code))
500 goto out;
501 global.external_check = 1;
502 }
503 /* user/group name handling */
504 else if (!strcmp(args[0], "user")) {
505 struct passwd *ha_user;
506 if (alertif_too_many_args(1, file, linenum, args, &err_code))
507 goto out;
508 if (global.uid != 0) {
509 ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
510 err_code |= ERR_ALERT;
511 goto out;
512 }
513 errno = 0;
514 ha_user = getpwnam(args[1]);
515 if (ha_user != NULL) {
516 global.uid = (int)ha_user->pw_uid;
517 }
518 else {
519 ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
520 err_code |= ERR_ALERT | ERR_FATAL;
521 }
522 }
523 else if (!strcmp(args[0], "group")) {
524 struct group *ha_group;
525 if (alertif_too_many_args(1, file, linenum, args, &err_code))
526 goto out;
527 if (global.gid != 0) {
528 ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum);
529 err_code |= ERR_ALERT;
530 goto out;
531 }
532 errno = 0;
533 ha_group = getgrnam(args[1]);
534 if (ha_group != NULL) {
535 global.gid = (int)ha_group->gr_gid;
536 }
537 else {
538 ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
539 err_code |= ERR_ALERT | ERR_FATAL;
540 }
541 }
542 /* end of user/group name handling*/
543 else if (!strcmp(args[0], "nbproc")) {
544 if (alertif_too_many_args(1, file, linenum, args, &err_code))
545 goto out;
546 if (*(args[1]) == 0) {
547 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
548 err_code |= ERR_ALERT | ERR_FATAL;
549 goto out;
550 }
551 global.nbproc = atol(args[1]);
Willy Tarreaua38a7172019-02-02 17:11:28 +0100552 all_proc_mask = nbits(global.nbproc);
Willy Tarreauff9c9142019-02-07 10:39:36 +0100553 if (global.nbproc < 1 || global.nbproc > MAX_PROCS) {
Willy Tarreau36b9e222018-11-11 15:19:52 +0100554 ha_alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n",
Willy Tarreauff9c9142019-02-07 10:39:36 +0100555 file, linenum, args[0], MAX_PROCS, global.nbproc);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100556 err_code |= ERR_ALERT | ERR_FATAL;
557 goto out;
558 }
559 }
560 else if (!strcmp(args[0], "nbthread")) {
561 if (alertif_too_many_args(1, file, linenum, args, &err_code))
562 goto out;
563 if (*(args[1]) == 0) {
564 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
565 err_code |= ERR_ALERT | ERR_FATAL;
566 goto out;
567 }
568 global.nbthread = parse_nbthread(args[1], &errmsg);
569 if (!global.nbthread) {
570 ha_alert("parsing [%s:%d] : '%s' %s.\n",
571 file, linenum, args[0], errmsg);
572 err_code |= ERR_ALERT | ERR_FATAL;
573 goto out;
574 }
575 }
576 else if (!strcmp(args[0], "maxconn")) {
577 if (alertif_too_many_args(1, file, linenum, args, &err_code))
578 goto out;
579 if (global.maxconn != 0) {
580 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
581 err_code |= ERR_ALERT;
582 goto out;
583 }
584 if (*(args[1]) == 0) {
585 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
586 err_code |= ERR_ALERT | ERR_FATAL;
587 goto out;
588 }
589 global.maxconn = atol(args[1]);
590#ifdef SYSTEM_MAXCONN
Willy Tarreauca783d42019-03-13 10:03:07 +0100591 if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) {
592 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);
593 global.maxconn = SYSTEM_MAXCONN;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100594 err_code |= ERR_ALERT;
595 }
596#endif /* SYSTEM_MAXCONN */
597 }
598 else if (!strcmp(args[0], "ssl-server-verify")) {
599 if (alertif_too_many_args(1, file, linenum, args, &err_code))
600 goto out;
601 if (*(args[1]) == 0) {
602 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
603 err_code |= ERR_ALERT | ERR_FATAL;
604 goto out;
605 }
606 if (strcmp(args[1],"none") == 0)
607 global.ssl_server_verify = SSL_SERVER_VERIFY_NONE;
608 else if (strcmp(args[1],"required") == 0)
609 global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED;
610 else {
611 ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]);
612 err_code |= ERR_ALERT | ERR_FATAL;
613 goto out;
614 }
615 }
616 else if (!strcmp(args[0], "maxconnrate")) {
617 if (alertif_too_many_args(1, file, linenum, args, &err_code))
618 goto out;
619 if (global.cps_lim != 0) {
620 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
621 err_code |= ERR_ALERT;
622 goto out;
623 }
624 if (*(args[1]) == 0) {
625 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
626 err_code |= ERR_ALERT | ERR_FATAL;
627 goto out;
628 }
629 global.cps_lim = atol(args[1]);
630 }
631 else if (!strcmp(args[0], "maxsessrate")) {
632 if (alertif_too_many_args(1, file, linenum, args, &err_code))
633 goto out;
634 if (global.sps_lim != 0) {
635 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
636 err_code |= ERR_ALERT;
637 goto out;
638 }
639 if (*(args[1]) == 0) {
640 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
641 err_code |= ERR_ALERT | ERR_FATAL;
642 goto out;
643 }
644 global.sps_lim = atol(args[1]);
645 }
646 else if (!strcmp(args[0], "maxsslrate")) {
647 if (alertif_too_many_args(1, file, linenum, args, &err_code))
648 goto out;
649 if (global.ssl_lim != 0) {
650 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
651 err_code |= ERR_ALERT;
652 goto out;
653 }
654 if (*(args[1]) == 0) {
655 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
656 err_code |= ERR_ALERT | ERR_FATAL;
657 goto out;
658 }
659 global.ssl_lim = atol(args[1]);
660 }
661 else if (!strcmp(args[0], "maxcomprate")) {
662 if (alertif_too_many_args(1, file, linenum, args, &err_code))
663 goto out;
664 if (*(args[1]) == 0) {
665 ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]);
666 err_code |= ERR_ALERT | ERR_FATAL;
667 goto out;
668 }
669 global.comp_rate_lim = atoi(args[1]) * 1024;
670 }
671 else if (!strcmp(args[0], "maxpipes")) {
672 if (alertif_too_many_args(1, file, linenum, args, &err_code))
673 goto out;
674 if (global.maxpipes != 0) {
675 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
676 err_code |= ERR_ALERT;
677 goto out;
678 }
679 if (*(args[1]) == 0) {
680 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
681 err_code |= ERR_ALERT | ERR_FATAL;
682 goto out;
683 }
684 global.maxpipes = atol(args[1]);
685 }
686 else if (!strcmp(args[0], "maxzlibmem")) {
687 if (alertif_too_many_args(1, file, linenum, args, &err_code))
688 goto out;
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.maxzlibmem = atol(args[1]) * 1024L * 1024L;
695 }
696 else if (!strcmp(args[0], "maxcompcpuusage")) {
697 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 between 0 and 100.\n", file, linenum, args[0]);
701 err_code |= ERR_ALERT | ERR_FATAL;
702 goto out;
703 }
704 compress_min_idle = 100 - atoi(args[1]);
705 if (compress_min_idle > 100) {
706 ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]);
707 err_code |= ERR_ALERT | ERR_FATAL;
708 goto out;
709 }
710 }
711
712 else if (!strcmp(args[0], "ulimit-n")) {
713 if (alertif_too_many_args(1, file, linenum, args, &err_code))
714 goto out;
715 if (global.rlimit_nofile != 0) {
716 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
717 err_code |= ERR_ALERT;
718 goto out;
719 }
720 if (*(args[1]) == 0) {
721 ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
722 err_code |= ERR_ALERT | ERR_FATAL;
723 goto out;
724 }
725 global.rlimit_nofile = atol(args[1]);
726 }
727 else if (!strcmp(args[0], "chroot")) {
728 if (alertif_too_many_args(1, file, linenum, args, &err_code))
729 goto out;
730 if (global.chroot != NULL) {
731 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
732 err_code |= ERR_ALERT;
733 goto out;
734 }
735 if (*(args[1]) == 0) {
736 ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
737 err_code |= ERR_ALERT | ERR_FATAL;
738 goto out;
739 }
740 global.chroot = strdup(args[1]);
741 }
742 else if (!strcmp(args[0], "description")) {
743 int i, len=0;
744 char *d;
745
746 if (!*args[1]) {
747 ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n",
748 file, linenum, args[0]);
749 err_code |= ERR_ALERT | ERR_FATAL;
750 goto out;
751 }
752
753 for (i = 1; *args[i]; i++)
754 len += strlen(args[i]) + 1;
755
756 if (global.desc)
757 free(global.desc);
758
759 global.desc = d = calloc(1, len);
760
761 d += snprintf(d, global.desc + len - d, "%s", args[1]);
762 for (i = 2; *args[i]; i++)
763 d += snprintf(d, global.desc + len - d, " %s", args[i]);
764 }
765 else if (!strcmp(args[0], "node")) {
766 int i;
767 char c;
768
769 if (alertif_too_many_args(1, file, linenum, args, &err_code))
770 goto out;
771
772 for (i=0; args[1][i]; i++) {
773 c = args[1][i];
774 if (!isupper((unsigned char)c) && !islower((unsigned char)c) &&
775 !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.')
776 break;
777 }
778
779 if (!i || args[1][i]) {
780 ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string"
781 " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n",
782 file, linenum, args[0]);
783 err_code |= ERR_ALERT | ERR_FATAL;
784 goto out;
785 }
786
787 if (global.node)
788 free(global.node);
789
790 global.node = strdup(args[1]);
791 }
792 else if (!strcmp(args[0], "pidfile")) {
793 if (alertif_too_many_args(1, file, linenum, args, &err_code))
794 goto out;
795 if (global.pidfile != NULL) {
796 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
797 err_code |= ERR_ALERT;
798 goto out;
799 }
800 if (*(args[1]) == 0) {
801 ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
802 err_code |= ERR_ALERT | ERR_FATAL;
803 goto out;
804 }
805 global.pidfile = strdup(args[1]);
806 }
807 else if (!strcmp(args[0], "unix-bind")) {
808 int cur_arg = 1;
809 while (*(args[cur_arg])) {
810 if (!strcmp(args[cur_arg], "prefix")) {
811 if (global.unix_bind.prefix != NULL) {
812 ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]);
813 err_code |= ERR_ALERT;
814 cur_arg += 2;
815 continue;
816 }
817
818 if (*(args[cur_arg+1]) == 0) {
819 ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]);
820 err_code |= ERR_ALERT | ERR_FATAL;
821 goto out;
822 }
823 global.unix_bind.prefix = strdup(args[cur_arg+1]);
824 cur_arg += 2;
825 continue;
826 }
827
828 if (!strcmp(args[cur_arg], "mode")) {
829
830 global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8);
831 cur_arg += 2;
832 continue;
833 }
834
835 if (!strcmp(args[cur_arg], "uid")) {
836
837 global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]);
838 cur_arg += 2;
839 continue;
840 }
841
842 if (!strcmp(args[cur_arg], "gid")) {
843
844 global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]);
845 cur_arg += 2;
846 continue;
847 }
848
849 if (!strcmp(args[cur_arg], "user")) {
850 struct passwd *user;
851
852 user = getpwnam(args[cur_arg + 1]);
853 if (!user) {
854 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n",
855 file, linenum, args[0], args[cur_arg + 1 ]);
856 err_code |= ERR_ALERT | ERR_FATAL;
857 goto out;
858 }
859
860 global.unix_bind.ux.uid = user->pw_uid;
861 cur_arg += 2;
862 continue;
863 }
864
865 if (!strcmp(args[cur_arg], "group")) {
866 struct group *group;
867
868 group = getgrnam(args[cur_arg + 1]);
869 if (!group) {
870 ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n",
871 file, linenum, args[0], args[cur_arg + 1 ]);
872 err_code |= ERR_ALERT | ERR_FATAL;
873 goto out;
874 }
875
876 global.unix_bind.ux.gid = group->gr_gid;
877 cur_arg += 2;
878 continue;
879 }
880
881 ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n",
882 file, linenum, args[0]);
883 err_code |= ERR_ALERT | ERR_FATAL;
884 goto out;
885 }
886 }
887 else if (!strcmp(args[0], "log")) { /* "no log" or "log ..." */
888 if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), &errmsg)) {
889 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
890 err_code |= ERR_ALERT | ERR_FATAL;
891 goto out;
892 }
893 }
894 else if (!strcmp(args[0], "log-send-hostname")) { /* set the hostname in syslog header */
895 char *name;
896
897 if (global.log_send_hostname != NULL) {
898 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
899 err_code |= ERR_ALERT;
900 goto out;
901 }
902
903 if (*(args[1]))
904 name = args[1];
905 else
906 name = hostname;
907
908 free(global.log_send_hostname);
909 global.log_send_hostname = strdup(name);
910 }
911 else if (!strcmp(args[0], "server-state-base")) { /* path base where HAProxy can find server state files */
912 if (global.server_state_base != NULL) {
913 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
914 err_code |= ERR_ALERT;
915 goto out;
916 }
917
918 if (!*(args[1])) {
919 ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]);
920 err_code |= ERR_FATAL;
921 goto out;
922 }
923
924 global.server_state_base = strdup(args[1]);
925 }
926 else if (!strcmp(args[0], "server-state-file")) { /* path to the file where HAProxy can load the server states */
927 if (global.server_state_file != NULL) {
928 ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
929 err_code |= ERR_ALERT;
930 goto out;
931 }
932
933 if (!*(args[1])) {
934 ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]);
935 err_code |= ERR_FATAL;
936 goto out;
937 }
938
939 global.server_state_file = strdup(args[1]);
940 }
941 else if (!strcmp(args[0], "log-tag")) { /* tag to report to syslog */
942 if (alertif_too_many_args(1, file, linenum, args, &err_code))
943 goto out;
944 if (*(args[1]) == 0) {
945 ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]);
946 err_code |= ERR_ALERT | ERR_FATAL;
947 goto out;
948 }
949 chunk_destroy(&global.log_tag);
950 chunk_initstr(&global.log_tag, strdup(args[1]));
951 }
952 else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */
953 if (alertif_too_many_args(1, file, linenum, args, &err_code))
954 goto out;
955 if (global.spread_checks != 0) {
956 ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum);
957 err_code |= ERR_ALERT;
958 goto out;
959 }
960 if (*(args[1]) == 0) {
961 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
962 err_code |= ERR_ALERT | ERR_FATAL;
963 goto out;
964 }
965 global.spread_checks = atol(args[1]);
966 if (global.spread_checks < 0 || global.spread_checks > 50) {
967 ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum);
968 err_code |= ERR_ALERT | ERR_FATAL;
969 }
970 }
971 else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */
972 const char *err;
973 unsigned int val;
974
975 if (alertif_too_many_args(1, file, linenum, args, &err_code))
976 goto out;
977 if (*(args[1]) == 0) {
978 ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]);
979 err_code |= ERR_ALERT | ERR_FATAL;
980 goto out;
981 }
982
983 err = parse_time_err(args[1], &val, TIME_UNIT_MS);
Willy Tarreau9faebe32019-06-07 19:00:37 +0200984 if (err == PARSE_TIME_OVER) {
985 ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n",
986 file, linenum, args[1], args[0]);
Willy Tarreau36b9e222018-11-11 15:19:52 +0100987 err_code |= ERR_ALERT | ERR_FATAL;
988 }
Willy Tarreau9faebe32019-06-07 19:00:37 +0200989 else if (err == PARSE_TIME_UNDER) {
990 ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n",
991 file, linenum, args[1], args[0]);
992 err_code |= ERR_ALERT | ERR_FATAL;
993 }
994 else if (err) {
995 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 +0100996 err_code |= ERR_ALERT | ERR_FATAL;
997 }
Willy Tarreau9faebe32019-06-07 19:00:37 +0200998 global.max_spread_checks = val;
Willy Tarreau36b9e222018-11-11 15:19:52 +0100999 }
1000 else if (strcmp(args[0], "cpu-map") == 0) {
1001 /* map a process list to a CPU set */
1002#ifdef USE_CPU_AFFINITY
1003 char *slash;
1004 unsigned long proc = 0, thread = 0, cpus;
1005 int i, j, n, autoinc;
1006
1007 if (!*args[1] || !*args[2]) {
1008 ha_alert("parsing [%s:%d] : %s expects a process number "
1009 " ('all', 'odd', 'even', a number from 1 to %d or a range), "
1010 " followed by a list of CPU ranges with numbers from 0 to %d.\n",
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001011 file, linenum, args[0], LONGBITS, LONGBITS - 1);
Willy Tarreau36b9e222018-11-11 15:19:52 +01001012 err_code |= ERR_ALERT | ERR_FATAL;
1013 goto out;
1014 }
1015
1016 if ((slash = strchr(args[1], '/')) != NULL)
1017 *slash = 0;
1018
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001019 /* note: we silently ignore processes over MAX_PROCS and
1020 * threads over MAX_THREADS so as not to make configurations a
1021 * pain to maintain.
1022 */
1023 if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001024 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1025 err_code |= ERR_ALERT | ERR_FATAL;
1026 goto out;
1027 }
1028
1029 if (slash) {
Willy Tarreau5799e9c2019-03-05 18:14:03 +01001030 if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) {
Willy Tarreau36b9e222018-11-11 15:19:52 +01001031 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1032 err_code |= ERR_ALERT | ERR_FATAL;
1033 goto out;
1034 }
1035 *slash = '/';
1036
1037 if (autoinc && atleast2(proc) && atleast2(thread)) {
1038 ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
1039 "a process range _AND_ a thread range\n",
1040 file, linenum, args[0], args[1]);
1041 err_code |= ERR_ALERT | ERR_FATAL;
1042 goto out;
1043 }
1044 }
1045
1046 if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) {
1047 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1048 err_code |= ERR_ALERT | ERR_FATAL;
1049 goto out;
1050 }
1051
1052 if (autoinc &&
1053 my_popcountl(proc) != my_popcountl(cpus) &&
1054 my_popcountl(thread) != my_popcountl(cpus)) {
1055 ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets "
1056 "must have the same size to be automatically bound\n",
1057 file, linenum, args[0]);
1058 err_code |= ERR_ALERT | ERR_FATAL;
1059 goto out;
1060 }
1061
Willy Tarreau7764a572019-07-16 15:10:34 +02001062 /* we now have to deal with 3 real cases :
1063 * cpu-map P-Q => mapping for whole processes, numbers P to Q
1064 * cpu-map P-Q/1 => mapping of first thread of processes P to Q
1065 * cpu-map 1/T-U => mapping of threads T to U of process 1
1066 * Otherwise other combinations are silently ignored since nbthread
1067 * and nbproc cannot both be >1 :
1068 * cpu-map P-Q/T => mapping for thread T for processes P to Q.
1069 * Only one of T,Q may be > 1, others ignored.
1070 * cpu-map P/T-U => mapping for threads T to U of process P. Only
1071 * one of P,U may be > 1, others ignored.
1072 */
1073 if (!thread) {
1074 /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */
Willy Tarreau81492c92019-05-03 09:41:23 +02001075 for (i = n = 0; i < MAX_PROCS; i++) {
1076 /* No mapping for this process */
1077 if (!(proc & (1UL << i)))
1078 continue;
1079
Willy Tarreau36b9e222018-11-11 15:19:52 +01001080 if (!autoinc)
1081 global.cpu_map.proc[i] = cpus;
1082 else {
1083 n += my_ffsl(cpus >> n);
1084 global.cpu_map.proc[i] = (1UL << (n-1));
1085 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001086 }
Willy Tarreau7764a572019-07-16 15:10:34 +02001087 } else {
1088 /* Mapping at the thread level. All threads are retained
1089 * for process 1, and only thread 1 is retained for other
1090 * processes.
1091 */
1092 if (thread == 0x1) {
1093 /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
1094 for (i = n = 0; i < MAX_PROCS; i++) {
1095 /* No mapping for this process */
1096 if (!(proc & (1UL << i)))
1097 continue;
1098 if (!autoinc)
1099 global.cpu_map.proc_t1[i] = cpus;
1100 else {
1101 n += my_ffsl(cpus >> n);
1102 global.cpu_map.proc_t1[i] = (1UL << (n-1));
1103 }
1104 }
1105 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001106
Willy Tarreau7764a572019-07-16 15:10:34 +02001107 if (proc == 0x1) {
1108 /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
1109 for (j = n = 0; j < MAX_THREADS; j++) {
1110 /* No mapping for this thread */
1111 if (!(thread & (1UL << j)))
1112 continue;
Willy Tarreau36b9e222018-11-11 15:19:52 +01001113
Willy Tarreau7764a572019-07-16 15:10:34 +02001114 if (!autoinc)
1115 global.cpu_map.thread[j] = cpus;
1116 else {
1117 n += my_ffsl(cpus >> n);
1118 global.cpu_map.thread[j] = (1UL << (n-1));
1119 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001120 }
1121 }
1122 }
1123#else
1124 ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n",
1125 file, linenum, args[0]);
1126 err_code |= ERR_ALERT | ERR_FATAL;
1127 goto out;
1128#endif /* ! USE_CPU_AFFINITY */
1129 }
1130 else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) {
1131 if (alertif_too_many_args(3, file, linenum, args, &err_code))
1132 goto out;
1133
1134 if (*(args[2]) == 0) {
1135 ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]);
1136 err_code |= ERR_ALERT | ERR_FATAL;
1137 goto out;
1138 }
1139
1140 /* "setenv" overwrites, "presetenv" only sets if not yet set */
1141 if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) {
1142 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno));
1143 err_code |= ERR_ALERT | ERR_FATAL;
1144 goto out;
1145 }
1146 }
1147 else if (!strcmp(args[0], "unsetenv")) {
1148 int arg;
1149
1150 if (*(args[1]) == 0) {
1151 ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]);
1152 err_code |= ERR_ALERT | ERR_FATAL;
1153 goto out;
1154 }
1155
1156 for (arg = 1; *args[arg]; arg++) {
1157 if (unsetenv(args[arg]) != 0) {
1158 ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno));
1159 err_code |= ERR_ALERT | ERR_FATAL;
1160 goto out;
1161 }
1162 }
1163 }
1164 else if (!strcmp(args[0], "resetenv")) {
1165 extern char **environ;
1166 char **env = environ;
1167
1168 /* args contain variable names to keep, one per argument */
1169 while (*env) {
1170 int arg;
1171
1172 /* look for current variable in among all those we want to keep */
1173 for (arg = 1; *args[arg]; arg++) {
1174 if (strncmp(*env, args[arg], strlen(args[arg])) == 0 &&
1175 (*env)[strlen(args[arg])] == '=')
1176 break;
1177 }
1178
1179 /* delete this variable */
1180 if (!*args[arg]) {
1181 char *delim = strchr(*env, '=');
1182
1183 if (!delim || delim - *env >= trash.size) {
1184 ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env);
1185 err_code |= ERR_ALERT | ERR_FATAL;
1186 goto out;
1187 }
1188
1189 memcpy(trash.area, *env, delim - *env);
1190 trash.area[delim - *env] = 0;
1191
1192 if (unsetenv(trash.area) != 0) {
1193 ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno));
1194 err_code |= ERR_ALERT | ERR_FATAL;
1195 goto out;
1196 }
1197 }
1198 else
1199 env++;
1200 }
1201 }
William Dauchy0fec3ab2019-10-27 20:08:11 +01001202 else if (!strcmp(args[0], "strict-limits")) { /* "no strict-limits" or "strict-limits" */
1203 if (alertif_too_many_args(0, file, linenum, args, &err_code))
1204 goto out;
1205 if (kwm == KWM_NO)
1206 global.tune.options &= ~GTUNE_STRICT_LIMITS;
1207 else
1208 global.tune.options |= GTUNE_STRICT_LIMITS;
1209 }
Willy Tarreau36b9e222018-11-11 15:19:52 +01001210 else {
1211 struct cfg_kw_list *kwl;
1212 int index;
1213 int rc;
1214
1215 list_for_each_entry(kwl, &cfg_keywords.list, list) {
1216 for (index = 0; kwl->kw[index].kw != NULL; index++) {
1217 if (kwl->kw[index].section != CFG_GLOBAL)
1218 continue;
1219 if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
1220 rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
1221 if (rc < 0) {
1222 ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1223 err_code |= ERR_ALERT | ERR_FATAL;
1224 }
1225 else if (rc > 0) {
1226 ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg);
1227 err_code |= ERR_WARN;
1228 goto out;
1229 }
1230 goto out;
1231 }
1232 }
1233 }
1234
1235 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
1236 err_code |= ERR_ALERT | ERR_FATAL;
1237 }
1238
1239 out:
1240 free(errmsg);
1241 return err_code;
1242}
1243