Browse code

Initialize and destory the configuration framework in main.c, and update the local config within the child processes at the beginning of each loop.

TODO: The local config must be updated in all the modules that
fork a new process implementing an endless loop.

Miklos Tirpak authored on 05/12/2007 15:51:24
Showing 5 changed files
... ...
@@ -159,6 +159,7 @@
159 159
 #include "rand/fastrand.h" /* seed */
160 160
 
161 161
 #include "stats.h"
162
+#include "cfg/cfg_struct.h"
162 163
 
163 164
 #ifdef DEBUG_DMALLOC
164 165
 #include <dmalloc.h>
... ...
@@ -477,6 +478,7 @@ void cleanup(show_status)
477 477
 #ifdef USE_DST_BLACKLIST
478 478
 	destroy_dst_blacklist();
479 479
 #endif
480
+	cfg_destroy();
480 481
 #ifdef USE_TCP
481 482
 	destroy_tcp();
482 483
 #endif
... ...
@@ -1663,10 +1665,22 @@ try_again:
1663 1663
 	if (real_time&4)
1664 1664
 			set_rt_prio(rt_prio, rt_policy);
1665 1665
 
1666
+	
1667
+	if (cfg_init() < 0) {
1668
+		LOG(L_CRIT, "could not initialize configuration framework\n");
1669
+		goto error;
1670
+	}
1671
+	
1666 1672
 	if (init_modules() != 0) {
1667 1673
 		fprintf(stderr, "ERROR: error while initializing modules\n");
1668 1674
 		goto error;
1669 1675
 	}
1676
+	
1677
+	if (cfg_shmize() < 0) {
1678
+		LOG(L_CRIT, "could not initialize shared configuration\n");
1679
+		goto error;
1680
+	}
1681
+	
1670 1682
 	/* initialize process_table, add core process no. (calc_proc_no()) to the
1671 1683
 	 * processes registered from the modules*/
1672 1684
 	if (init_pt(calc_proc_no())==-1)
... ...
@@ -147,6 +147,7 @@
147 147
 #include "tcp_info.h"
148 148
 #include "tcp_options.h"
149 149
 #include "ut.h"
150
+#include "cfg/cfg_struct.h"
150 151
 
151 152
 #define local_malloc pkg_malloc
152 153
 #define local_free   pkg_free
... ...
@@ -2573,6 +2574,9 @@ error:
2573 2573
 inline static int handle_io(struct fd_map* fm, short ev, int idx)
2574 2574
 {	
2575 2575
 	int ret;
2576
+
2577
+	/* update the local config */
2578
+	cfg_update();
2576 2579
 	
2577 2580
 	switch(fm->type){
2578 2581
 		case F_SOCKINFO:
... ...
@@ -2811,7 +2815,11 @@ void tcp_main_loop()
2811 2811
 				goto error;
2812 2812
 			}
2813 2813
 	}
2814
-	
2814
+
2815
+
2816
+	/* initialize the cfg framework */
2817
+	if (cfg_child_init()) goto error;
2818
+
2815 2819
 	/* main loop */
2816 2820
 	switch(io_h.poll_method){
2817 2821
 		case POLL_POLL:
... ...
@@ -65,6 +65,7 @@
65 65
 #include "local_timer.h"
66 66
 #include "ut.h"
67 67
 #include "pt.h"
68
+#include "cfg/cfg_struct.h"
68 69
 #ifdef CORE_TLS
69 70
 #include "tls/tls_server.h"
70 71
 #else
... ...
@@ -727,6 +728,9 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
727 727
 	long resp;
728 728
 	ticks_t t;
729 729
 	
730
+	/* update the local config */
731
+	cfg_update();
732
+	
730 733
 	switch(fm->type){
731 734
 		case F_TCPMAIN:
732 735
 again:
... ...
@@ -850,6 +854,10 @@ void tcp_receive_loop(int unix_sock)
850 850
 							" to the fd list\n");
851 851
 		goto error;
852 852
 	}
853
+
854
+	/* initialize the config framework */
855
+	if (cfg_child_init()) goto error;
856
+
853 857
 	/* main loop */
854 858
 	switch(io_w.poll_method){
855 859
 		case POLL_POLL:
... ...
@@ -60,6 +60,7 @@
60 60
 #endif
61 61
 #include "locking.h"
62 62
 #include "sched_yield.h"
63
+#include "cfg/cfg_struct.h"
63 64
 
64 65
 
65 66
 /* how often will the timer handler be called (in ticks) */
... ...
@@ -345,6 +346,9 @@ again:
345 345
 	sigaddset(&slow_timer_sset, SIGCHLD);
346 346
 	sigaddset(&slow_timer_sset, SIGALRM);
347 347
 #endif
348
+	/* initialize the config framework */
349
+	if (cfg_child_init()) goto error;
350
+
348 351
 	return 0;
349 352
 error:
350 353
 	return -1;
... ...
@@ -382,6 +386,9 @@ int arm_timer()
382 382
 				strerror(errno), errno);
383 383
 		return -1;
384 384
 	}
385
+	/* initialize the config framework */
386
+	if (cfg_child_init()) return -1;
387
+
385 388
 	return 0;
386 389
 }
387 390
 
... ...
@@ -915,6 +922,9 @@ void timer_main()
915 915
 	in_timer=1; /* mark this process as the fast timer */
916 916
 	while(1){
917 917
 		if (run_timer){
918
+			/* update the local cfg if needed */
919
+			cfg_update();
920
+
918 921
 			timer_handler();
919 922
 		}
920 923
 		pause();
... ...
@@ -1052,6 +1062,9 @@ void slow_timer_main()
1052 1052
 		continue;
1053 1053
 	}
1054 1054
 #endif
1055
+		/* update the local cfg if needed */
1056
+		cfg_update();
1057
+		
1055 1058
 		LOCK_SLOW_TIMER_LIST();
1056 1059
 		while(*s_idx!=*t_idx){
1057 1060
 			i= *s_idx%SLOW_LISTS_NO;
... ...
@@ -66,6 +66,7 @@
66 66
 #include "receive.h"
67 67
 #include "mem/mem.h"
68 68
 #include "ip_addr.h"
69
+#include "cfg/cfg_struct.h"
69 70
 
70 71
 #ifdef USE_STUN
71 72
   #include "ser_stun.h"
... ...
@@ -428,6 +429,10 @@ int udp_rcv_loop()
428 428
 	ri.dst_ip=bind_address->address;
429 429
 	ri.proto=PROTO_UDP;
430 430
 	ri.proto_reserved1=ri.proto_reserved2=0;
431
+
432
+	/* initialize the config framework */
433
+	if (cfg_child_init()) goto error;
434
+
431 435
 	for(;;){
432 436
 #ifdef DYN_BUF
433 437
 		buf=pkg_malloc(BUF_SIZE+1);
... ...
@@ -504,6 +509,8 @@ int udp_rcv_loop()
504 504
 				}
505 505
 			} else
506 506
 #endif
507
+		/* update the local config */
508
+		cfg_update();
507 509
 		/* receive_msg must free buf too!*/
508 510
 		receive_msg(buf, len, &ri);
509 511