Skip to content

Commit

Permalink
core: stop at the first config error on startup
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
miconda committed Jun 14, 2022
1 parent 649b421 commit f0cea1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/cfg.y
Expand Up @@ -3854,6 +3854,9 @@ static void yyerror_at(struct cfg_pos* p, char* format, ...)
LM_CRIT("parse error in config file %s, line %d, column %d: %s\n",
p->fname, p->s_line, p->s_col, s);
cfg_errors++;
if(ksr_all_errors==0) {
ksr_exit(-1);
}
}


Expand Down
1 change: 1 addition & 0 deletions src/core/globals.h
Expand Up @@ -213,6 +213,7 @@ extern int rt_timer2_policy; /* "slow" timer, SCHED_OTHER */
extern int http_reply_parse;
extern int _sr_ip_free_bind;
extern int ksr_verbose_startup;
extern int ksr_all_errors;
extern int ksr_route_locks_size;
extern str _ksr_xavp_via_params;
extern str _ksr_xavp_via_fields;
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Expand Up @@ -206,6 +206,7 @@ Options:\n\
--modparam=modname:paramname:type:value set the module parameter\n\
type has to be 's' for string value and 'i' for int value, \n\
example: --modparam=corex:alias_subdomains:s:" NAME ".org\n\
--all-errors Print details about all config errors that can be detected\n\
-M nr Size of private memory allocated, in Megabytes\n\
-n processes Number of child processes to fork per interface\n\
(default: 8)\n"
Expand Down Expand Up @@ -482,6 +483,7 @@ int child_rank = 0;
int ser_kill_timeout=DEFAULT_SER_KILL_TIMEOUT;

int ksr_verbose_startup = 0;
int ksr_all_errors = 0;

/* cfg parsing */
int cfg_errors=0;
Expand Down Expand Up @@ -2018,6 +2020,7 @@ int main(int argc, char** argv)
{"debug", required_argument, 0, KARGOPTVAL + 8},
{"cfg-print", no_argument, 0, KARGOPTVAL + 9},
{"atexit", required_argument, 0, KARGOPTVAL + 10},
{"all-errors", no_argument, 0, KARGOPTVAL + 11},
{0, 0, 0, 0 }
};

Expand Down Expand Up @@ -2128,6 +2131,9 @@ int main(int argc, char** argv)
goto error;
}
break;
case KARGOPTVAL+11:
ksr_all_errors = 1;
break;

default:
if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) {
Expand Down Expand Up @@ -2317,6 +2323,7 @@ int main(int argc, char** argv)
case KARGOPTVAL+8:
case KARGOPTVAL+9:
case KARGOPTVAL+10:
case KARGOPTVAL+11:
break;

/* long options */
Expand Down

0 comments on commit f0cea1a

Please sign in to comment.