Module: kamailio
Branch: master
Commit: f0cea1a7c03e400b4398795c2d8b0f7e45d1dfb5
URL: 
https://github.com/kamailio/kamailio/commit/f0cea1a7c03e400b4398795c2d8b0f7e45d1dfb5

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2022-06-14T11:46:39+02:00

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

---

Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/main.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/f0cea1a7c03e400b4398795c2d8b0f7e45d1dfb5.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f0cea1a7c03e400b4398795c2d8b0f7e45d1dfb5.patch

---

diff --git a/src/core/cfg.y b/src/core/cfg.y
index 713b6789b0..acf5e8c490 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -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);
+       }
 }
 
 
diff --git a/src/core/globals.h b/src/core/globals.h
index a4857cbf0c..03eb1ef897 100644
--- a/src/core/globals.h
+++ b/src/core/globals.h
@@ -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;
diff --git a/src/main.c b/src/main.c
index cb0c92e357..e919a23274 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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"
@@ -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;
@@ -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 }
        };
 
@@ -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)) {
@@ -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 */


_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to