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