[sr-dev] git:master: core: fix cfg_update() on config error

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Oct 8 00:13:02 CEST 2009


Module: sip-router
Branch: master
Commit: 29e63735632a379df5d6b49130d05d47e2829a60
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=29e63735632a379df5d6b49130d05d47e2829a60

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Oct  8 00:14:32 2009 +0200

core: fix cfg_update() on config error

Don't try to use the cfg framework if it was not initialized (it
could happen if for example config parsing fails and shutdown is
triggered before the cfg framework is initialized).

---

 main.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c
index c1f9d07..01a6fde 100644
--- a/main.c
+++ b/main.c
@@ -473,6 +473,9 @@ unsigned long shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
 int my_argc;
 char **my_argv;
 
+/* set to 1 when the cfg framework and core cfg is initialized/registered */
+static int cfg_ok=0;
+
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
 		    (normally it shouldn't  be bigger  than 3) */
 
@@ -511,10 +514,12 @@ void cleanup(show_status)
 	/* restore the original core configuration before the
 	 * config block is freed, otherwise even logging is unusable,
 	 * it can case segfault */
-	cfg_update();
-	/* copy current config into default_core_cfg */
-	if (core_cfg)
-		default_core_cfg=*((struct cfg_group_core*)core_cfg);
+	if (cfg_ok){
+		cfg_update();
+		/* copy current config into default_core_cfg */
+		if (core_cfg)
+			default_core_cfg=*((struct cfg_group_core*)core_cfg);
+	}
 	core_cfg = &default_core_cfg;
 	cfg_destroy();
 #ifdef USE_TCP
@@ -2080,6 +2085,7 @@ try_again:
 		LOG(L_CRIT, "could not declare the core configuration\n");
 		goto error;
 	}
+	cfg_ok=1;
 #ifdef USE_TCP
 	if (tcp_register_cfg()){
 		LOG(L_CRIT, "could not register the tcp configuration\n");




More information about the sr-dev mailing list