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