From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Mon, 23 Dec 2019 13:53:39 +0100
Subject: [PATCH] core: stop start if ifdef check fails

Related #2057
---
 src/core/ppcfg.c | 20 ++++++++++++++------
 src/core/ppcfg.h |  3 ++-
 src/main.c       |  5 ++---
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/core/ppcfg.c b/src/core/ppcfg.c
index 584a491..115707a 100644
--- a/src/core/ppcfg.c
+++ b/src/core/ppcfg.c
@@ -216,19 +216,27 @@ void pp_ifdef_level_update(int val)
 /**
  *
  */
-void pp_ifdef_level_check(void)
+int pp_ifdef_level_check(void)
+{
+	if(_pp_ifdef_level!=0) {
+		return -1;
+	} else {
+		LM_DBG("same number of pairing preprocessor directives"
+			" #!IF[N]DEF - #!ENDIF\n");
+	}
+	return 0;
+}
+
+void pp_ifdef_level_error(void)
 {
 	if(_pp_ifdef_level!=0) {
 		if (_pp_ifdef_level > 0) {
-	                LM_WARN("different number of preprocessor directives:"
+			LM_ERR("different number of preprocessor directives:"
 				" %d more #!if[n]def as #!endif\n", _pp_ifdef_level);
 		} else {
-			LM_WARN("different number of preprocessor directives:"
+			LM_ERR("different number of preprocessor directives:"
 				" %d more #!endif as #!if[n]def\n", (_pp_ifdef_level)*-1);
 		}
-	} else {
-		LM_DBG("same number of pairing preprocessor directives"
-			" #!IF[N]DEF - #!ENDIF\n");
 	}
 }
 
diff --git a/src/core/ppcfg.h b/src/core/ppcfg.h
index 8485059..6fbd8a3 100644
--- a/src/core/ppcfg.h
+++ b/src/core/ppcfg.h
@@ -44,7 +44,8 @@ int  pp_define_set_type(int type);
 str *pp_define_get(int len, const char * text);
 
 void pp_ifdef_level_update(int val);
-void pp_ifdef_level_check(void);
+int pp_ifdef_level_check(void);
+void pp_ifdef_level_error(void);
 
 void pp_define_core(void);
 
diff --git a/src/main.c b/src/main.c
index b1414a9..c12b9e4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2265,10 +2265,10 @@ try_again:
 
 	yyin=cfg_stream;
 	debug_save = default_core_cfg.debug;
-	if ((yyparse()!=0)||(cfg_errors)){
+	if ((yyparse()!=0)||(cfg_errors)||(pp_ifdef_level_check()<0)){
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
 		if (debug_flag) default_core_cfg.debug = debug_save;
-		pp_ifdef_level_check();
+		pp_ifdef_level_error();
 
 		goto error;
 	}
@@ -2276,7 +2276,6 @@ try_again:
 		fprintf(stderr, "%d config warnings\n", cfg_warnings);
 	}
 	if (debug_flag) default_core_cfg.debug = debug_save;
-	pp_ifdef_level_check();
 	print_rls();
 
 	if(init_dst_set()<0) {
