Browse code

core: stop at the first config error on startup

- continuing to look for more errors to print them on one check can end
up in crashing because some internal interpreter structure may not be
filled properly
- new cli option --all-errors that can be used to enable printing
details for more detected config errors

Daniel-Constantin Mierla authored on 14/06/2022 09:44:24
Showing 3 changed files
... ...
@@ -3854,6 +3854,9 @@ static void yyerror_at(struct cfg_pos* p, char* format, ...)
3854 3854
 		LM_CRIT("parse error in config file %s, line %d, column %d: %s\n",
3855 3855
 					p->fname, p->s_line, p->s_col, s);
3856 3856
 	cfg_errors++;
3857
+	if(ksr_all_errors==0) {
3858
+		ksr_exit(-1);
3859
+	}
3857 3860
 }
3858 3861
 
3859 3862
 
... ...
@@ -213,6 +213,7 @@ extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
213 213
 extern int http_reply_parse;
214 214
 extern int _sr_ip_free_bind;
215 215
 extern int ksr_verbose_startup;
216
+extern int ksr_all_errors;
216 217
 extern int ksr_route_locks_size;
217 218
 extern str _ksr_xavp_via_params;
218 219
 extern str _ksr_xavp_via_fields;
... ...
@@ -206,6 +206,7 @@ Options:\n\
206 206
     --modparam=modname:paramname:type:value set the module parameter\n\
207 207
                   type has to be 's' for string value and 'i' for int value, \n\
208 208
                   example: --modparam=corex:alias_subdomains:s:" NAME ".org\n\
209
+    --all-errors Print details about all config errors that can be detected\n\
209 210
     -M nr        Size of private memory allocated, in Megabytes\n\
210 211
     -n processes Number of child processes to fork per interface\n\
211 212
                   (default: 8)\n"
... ...
@@ -482,6 +483,7 @@ int child_rank = 0;
482 483
 int ser_kill_timeout=DEFAULT_SER_KILL_TIMEOUT;
483 484
 
484 485
 int ksr_verbose_startup = 0;
486
+int ksr_all_errors = 0;
485 487
 
486 488
 /* cfg parsing */
487 489
 int cfg_errors=0;
... ...
@@ -2018,6 +2020,7 @@ int main(int argc, char** argv)
2018 2020
 		{"debug",       required_argument, 0, KARGOPTVAL + 8},
2019 2021
 		{"cfg-print",   no_argument,       0, KARGOPTVAL + 9},
2020 2022
 		{"atexit",      required_argument, 0, KARGOPTVAL + 10},
2023
+		{"all-errors",  no_argument,       0, KARGOPTVAL + 11},
2021 2024
 		{0, 0, 0, 0 }
2022 2025
 	};
2023 2026
 
... ...
@@ -2128,6 +2131,9 @@ int main(int argc, char** argv)
2128 2131
 						goto error;
2129 2132
 					}
2130 2133
 					break;
2134
+			case KARGOPTVAL+11:
2135
+					ksr_all_errors = 1;
2136
+					break;
2131 2137
 
2132 2138
 			default:
2133 2139
 					if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
... ...
@@ -2317,6 +2323,7 @@ int main(int argc, char** argv)
2317 2323
 			case KARGOPTVAL+8:
2318 2324
 			case KARGOPTVAL+9:
2319 2325
 			case KARGOPTVAL+10:
2326
+			case KARGOPTVAL+11:
2320 2327
 					break;
2321 2328
 
2322 2329
 			/* long options */