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 | { |
vend_natalie.chen | 19609d5 | 2019-12-09 13:49:14 +0800 | [diff] [blame^] | 29 | int i = 0; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 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); |
| 924 | chunk_initstr(&global.log_tag, strdup(args[1])); |
| 925 | } |
| 926 | else if (!strcmp(args[0], "spread-checks")) { /* random time between checks (0-50) */ |
| 927 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 928 | goto out; |
| 929 | if (global.spread_checks != 0) { |
| 930 | ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
| 931 | err_code |= ERR_ALERT; |
| 932 | goto out; |
| 933 | } |
| 934 | if (*(args[1]) == 0) { |
| 935 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 936 | err_code |= ERR_ALERT | ERR_FATAL; |
| 937 | goto out; |
| 938 | } |
| 939 | global.spread_checks = atol(args[1]); |
| 940 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 941 | ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
| 942 | err_code |= ERR_ALERT | ERR_FATAL; |
| 943 | } |
| 944 | } |
| 945 | else if (!strcmp(args[0], "max-spread-checks")) { /* maximum time between first and last check */ |
| 946 | const char *err; |
| 947 | unsigned int val; |
| 948 | |
| 949 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 950 | goto out; |
| 951 | if (*(args[1]) == 0) { |
| 952 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 953 | err_code |= ERR_ALERT | ERR_FATAL; |
| 954 | goto out; |
| 955 | } |
| 956 | |
| 957 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 958 | if (err == PARSE_TIME_OVER) { |
| 959 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 960 | file, linenum, args[1], args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 961 | err_code |= ERR_ALERT | ERR_FATAL; |
| 962 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 963 | else if (err == PARSE_TIME_UNDER) { |
| 964 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 965 | file, linenum, args[1], args[0]); |
| 966 | err_code |= ERR_ALERT | ERR_FATAL; |
| 967 | } |
| 968 | else if (err) { |
| 969 | 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] | 970 | err_code |= ERR_ALERT | ERR_FATAL; |
| 971 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 972 | global.max_spread_checks = val; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 973 | } |
| 974 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 975 | /* map a process list to a CPU set */ |
| 976 | #ifdef USE_CPU_AFFINITY |
| 977 | char *slash; |
| 978 | unsigned long proc = 0, thread = 0, cpus; |
| 979 | int i, j, n, autoinc; |
| 980 | |
| 981 | if (!*args[1] || !*args[2]) { |
| 982 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 983 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 984 | " 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] | 985 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 986 | err_code |= ERR_ALERT | ERR_FATAL; |
| 987 | goto out; |
| 988 | } |
| 989 | |
| 990 | if ((slash = strchr(args[1], '/')) != NULL) |
| 991 | *slash = 0; |
| 992 | |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 993 | /* note: we silently ignore processes over MAX_PROCS and |
| 994 | * threads over MAX_THREADS so as not to make configurations a |
| 995 | * pain to maintain. |
| 996 | */ |
| 997 | if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 998 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 999 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | |
| 1003 | if (slash) { |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1004 | if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1005 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1006 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1007 | goto out; |
| 1008 | } |
| 1009 | *slash = '/'; |
| 1010 | |
| 1011 | if (autoinc && atleast2(proc) && atleast2(thread)) { |
| 1012 | ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind " |
| 1013 | "a process range _AND_ a thread range\n", |
| 1014 | file, linenum, args[0], args[1]); |
| 1015 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1016 | goto out; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | if (parse_cpu_set((const char **)args+2, &cpus, &errmsg)) { |
| 1021 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1023 | goto out; |
| 1024 | } |
| 1025 | |
| 1026 | if (autoinc && |
| 1027 | my_popcountl(proc) != my_popcountl(cpus) && |
| 1028 | my_popcountl(thread) != my_popcountl(cpus)) { |
| 1029 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1030 | "must have the same size to be automatically bound\n", |
| 1031 | file, linenum, args[0]); |
| 1032 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1033 | goto out; |
| 1034 | } |
| 1035 | |
Willy Tarreau | 47b00ae | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1036 | /* we now have to deal with 3 real cases : |
| 1037 | * cpu-map P-Q => mapping for whole processes, numbers P to Q |
| 1038 | * cpu-map P-Q/1 => mapping of first thread of processes P to Q |
| 1039 | * cpu-map 1/T-U => mapping of threads T to U of process 1 |
| 1040 | * Otherwise other combinations are silently ignored since nbthread |
| 1041 | * and nbproc cannot both be >1 : |
| 1042 | * cpu-map P-Q/T => mapping for thread T for processes P to Q. |
| 1043 | * Only one of T,Q may be > 1, others ignored. |
| 1044 | * cpu-map P/T-U => mapping for threads T to U of process P. Only |
| 1045 | * one of P,U may be > 1, others ignored. |
| 1046 | */ |
| 1047 | if (!thread) { |
| 1048 | /* mapping for whole processes. E.g. cpu-map 1-4 0-3 */ |
Willy Tarreau | 81492c9 | 2019-05-03 09:41:23 +0200 | [diff] [blame] | 1049 | for (i = n = 0; i < MAX_PROCS; i++) { |
| 1050 | /* No mapping for this process */ |
| 1051 | if (!(proc & (1UL << i))) |
| 1052 | continue; |
| 1053 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1054 | if (!autoinc) |
| 1055 | global.cpu_map.proc[i] = cpus; |
| 1056 | else { |
| 1057 | n += my_ffsl(cpus >> n); |
| 1058 | global.cpu_map.proc[i] = (1UL << (n-1)); |
| 1059 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1060 | } |
Willy Tarreau | 47b00ae | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1061 | } else { |
| 1062 | /* Mapping at the thread level. All threads are retained |
| 1063 | * for process 1, and only thread 1 is retained for other |
| 1064 | * processes. |
| 1065 | */ |
| 1066 | if (thread == 0x1) { |
| 1067 | /* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */ |
| 1068 | for (i = n = 0; i < MAX_PROCS; i++) { |
| 1069 | /* No mapping for this process */ |
| 1070 | if (!(proc & (1UL << i))) |
| 1071 | continue; |
| 1072 | if (!autoinc) |
| 1073 | global.cpu_map.proc_t1[i] = cpus; |
| 1074 | else { |
| 1075 | n += my_ffsl(cpus >> n); |
| 1076 | global.cpu_map.proc_t1[i] = (1UL << (n-1)); |
| 1077 | } |
| 1078 | } |
| 1079 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1080 | |
Willy Tarreau | 47b00ae | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1081 | if (proc == 0x1) { |
| 1082 | /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ |
| 1083 | for (j = n = 0; j < MAX_THREADS; j++) { |
| 1084 | /* No mapping for this thread */ |
| 1085 | if (!(thread & (1UL << j))) |
| 1086 | continue; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1087 | |
Willy Tarreau | 47b00ae | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1088 | if (!autoinc) |
| 1089 | global.cpu_map.thread[j] = cpus; |
| 1090 | else { |
| 1091 | n += my_ffsl(cpus >> n); |
| 1092 | global.cpu_map.thread[j] = (1UL << (n-1)); |
| 1093 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | #else |
| 1098 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1099 | file, linenum, args[0]); |
| 1100 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1101 | goto out; |
| 1102 | #endif /* ! USE_CPU_AFFINITY */ |
| 1103 | } |
| 1104 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1105 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1106 | goto out; |
| 1107 | |
| 1108 | if (*(args[2]) == 0) { |
| 1109 | ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1110 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1111 | goto out; |
| 1112 | } |
| 1113 | |
| 1114 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1115 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1116 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1117 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1118 | goto out; |
| 1119 | } |
| 1120 | } |
| 1121 | else if (!strcmp(args[0], "unsetenv")) { |
| 1122 | int arg; |
| 1123 | |
| 1124 | if (*(args[1]) == 0) { |
| 1125 | ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1126 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1127 | goto out; |
| 1128 | } |
| 1129 | |
| 1130 | for (arg = 1; *args[arg]; arg++) { |
| 1131 | if (unsetenv(args[arg]) != 0) { |
| 1132 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1133 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1134 | goto out; |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | else if (!strcmp(args[0], "resetenv")) { |
| 1139 | extern char **environ; |
| 1140 | char **env = environ; |
| 1141 | |
| 1142 | /* args contain variable names to keep, one per argument */ |
| 1143 | while (*env) { |
| 1144 | int arg; |
| 1145 | |
| 1146 | /* look for current variable in among all those we want to keep */ |
| 1147 | for (arg = 1; *args[arg]; arg++) { |
| 1148 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1149 | (*env)[strlen(args[arg])] == '=') |
| 1150 | break; |
| 1151 | } |
| 1152 | |
| 1153 | /* delete this variable */ |
| 1154 | if (!*args[arg]) { |
| 1155 | char *delim = strchr(*env, '='); |
| 1156 | |
| 1157 | if (!delim || delim - *env >= trash.size) { |
| 1158 | ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1159 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1160 | goto out; |
| 1161 | } |
| 1162 | |
| 1163 | memcpy(trash.area, *env, delim - *env); |
| 1164 | trash.area[delim - *env] = 0; |
| 1165 | |
| 1166 | if (unsetenv(trash.area) != 0) { |
| 1167 | ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1169 | goto out; |
| 1170 | } |
| 1171 | } |
| 1172 | else |
| 1173 | env++; |
| 1174 | } |
| 1175 | } |
vend_natalie.chen | 19609d5 | 2019-12-09 13:49:14 +0800 | [diff] [blame^] | 1176 | else if (!strcmp(args[0], "email_alert")) { |
| 1177 | global.email_alert = 1; |
| 1178 | if (*(args[1]) == 0) { |
| 1179 | ha_alert("parsing [%s:%d] : email_alert Expects email address as argument.\n", file, linenum); |
| 1180 | global.email_alert = 0; |
| 1181 | err_code |= ERR_ALERT; |
| 1182 | goto out; |
| 1183 | } |
| 1184 | strncpy(global.email_from,args[1],50); |
| 1185 | for (i=0; i<3; i++) { |
| 1186 | if (*(args[i+2]) != 0) |
| 1187 | strncpy(global.email_to[i],args[i+2],50); |
| 1188 | } |
| 1189 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1190 | else { |
| 1191 | struct cfg_kw_list *kwl; |
| 1192 | int index; |
| 1193 | int rc; |
| 1194 | |
| 1195 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1196 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1197 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1198 | continue; |
| 1199 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 1200 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg); |
| 1201 | if (rc < 0) { |
| 1202 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1203 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1204 | } |
| 1205 | else if (rc > 0) { |
| 1206 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1207 | err_code |= ERR_WARN; |
| 1208 | goto out; |
| 1209 | } |
| 1210 | goto out; |
| 1211 | } |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
| 1216 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1217 | } |
| 1218 | |
| 1219 | out: |
| 1220 | free(errmsg); |
| 1221 | return err_code; |
| 1222 | } |
| 1223 | |