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