Browse code

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).

Andrei Pelinescu-Onciul authored on 07/10/2009 22:14:32
Showing 1 changed files
... ...
@@ -473,6 +473,9 @@ unsigned long shm_mem_size=SHM_MEM_SIZE * 1024 * 1024;
473 473
 int my_argc;
474 474
 char **my_argv;
475 475
 
476
+/* set to 1 when the cfg framework and core cfg is initialized/registered */
477
+static int cfg_ok=0;
478
+
476 479
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
477 480
 		    (normally it shouldn't  be bigger  than 3) */
478 481
 
... ...
@@ -511,10 +514,12 @@ void cleanup(show_status)
511 511
 	/* restore the original core configuration before the
512 512
 	 * config block is freed, otherwise even logging is unusable,
513 513
 	 * it can case segfault */
514
-	cfg_update();
515
-	/* copy current config into default_core_cfg */
516
-	if (core_cfg)
517
-		default_core_cfg=*((struct cfg_group_core*)core_cfg);
514
+	if (cfg_ok){
515
+		cfg_update();
516
+		/* copy current config into default_core_cfg */
517
+		if (core_cfg)
518
+			default_core_cfg=*((struct cfg_group_core*)core_cfg);
519
+	}
518 520
 	core_cfg = &default_core_cfg;
519 521
 	cfg_destroy();
520 522
 #ifdef USE_TCP
... ...
@@ -2080,6 +2085,7 @@ try_again:
2080 2080
 		LOG(L_CRIT, "could not declare the core configuration\n");
2081 2081
 		goto error;
2082 2082
 	}
2083
+	cfg_ok=1;
2083 2084
 #ifdef USE_TCP
2084 2085
 	if (tcp_register_cfg()){
2085 2086
 		LOG(L_CRIT, "could not register the tcp configuration\n");