Initialize and destory the configuration framework in main.c,
authorMiklos Tirpak <miklos@iptel.org>
Wed, 5 Dec 2007 15:51:24 +0000 (15:51 +0000)
committerMiklos Tirpak <miklos@iptel.org>
Wed, 5 Dec 2007 15:51:24 +0000 (15:51 +0000)
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.

main.c
tcp_main.c
tcp_read.c
timer.c
udp_server.c

diff --git a/main.c b/main.c
index 0b21518..d5882eb 100644 (file)
--- a/main.c
+++ b/main.c
 #include "rand/fastrand.h" /* seed */
 
 #include "stats.h"
+#include "cfg/cfg_struct.h"
 
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
@@ -477,6 +478,7 @@ void cleanup(show_status)
 #ifdef USE_DST_BLACKLIST
        destroy_dst_blacklist();
 #endif
+       cfg_destroy();
 #ifdef USE_TCP
        destroy_tcp();
 #endif
@@ -1663,10 +1665,22 @@ try_again:
        if (real_time&4)
                        set_rt_prio(rt_prio, rt_policy);
 
+       
+       if (cfg_init() < 0) {
+               LOG(L_CRIT, "could not initialize configuration framework\n");
+               goto error;
+       }
+       
        if (init_modules() != 0) {
                fprintf(stderr, "ERROR: error while initializing modules\n");
                goto error;
        }
+       
+       if (cfg_shmize() < 0) {
+               LOG(L_CRIT, "could not initialize shared configuration\n");
+               goto error;
+       }
+       
        /* initialize process_table, add core process no. (calc_proc_no()) to the
         * processes registered from the modules*/
        if (init_pt(calc_proc_no())==-1)
index 14eddb4..221af88 100644 (file)
 #include "tcp_info.h"
 #include "tcp_options.h"
 #include "ut.h"
+#include "cfg/cfg_struct.h"
 
 #define local_malloc pkg_malloc
 #define local_free   pkg_free
@@ -2573,6 +2574,9 @@ error:
 inline static int handle_io(struct fd_map* fm, short ev, int idx)
 {      
        int ret;
+
+       /* update the local config */
+       cfg_update();
        
        switch(fm->type){
                case F_SOCKINFO:
@@ -2811,7 +2815,11 @@ void tcp_main_loop()
                                goto error;
                        }
        }
-       
+
+
+       /* initialize the cfg framework */
+       if (cfg_child_init()) goto error;
+
        /* main loop */
        switch(io_h.poll_method){
                case POLL_POLL:
index 7374afb..49bc9e4 100644 (file)
@@ -65,6 +65,7 @@
 #include "local_timer.h"
 #include "ut.h"
 #include "pt.h"
+#include "cfg/cfg_struct.h"
 #ifdef CORE_TLS
 #include "tls/tls_server.h"
 #else
@@ -727,6 +728,9 @@ inline static int handle_io(struct fd_map* fm, short events, int idx)
        long resp;
        ticks_t t;
        
+       /* update the local config */
+       cfg_update();
+       
        switch(fm->type){
                case F_TCPMAIN:
 again:
@@ -850,6 +854,10 @@ void tcp_receive_loop(int unix_sock)
                                                        " to the fd list\n");
                goto error;
        }
+
+       /* initialize the config framework */
+       if (cfg_child_init()) goto error;
+
        /* main loop */
        switch(io_w.poll_method){
                case POLL_POLL:
diff --git a/timer.c b/timer.c
index fcb7591..bb8bbdc 100644 (file)
--- a/timer.c
+++ b/timer.c
@@ -60,6 +60,7 @@
 #endif
 #include "locking.h"
 #include "sched_yield.h"
+#include "cfg/cfg_struct.h"
 
 
 /* how often will the timer handler be called (in ticks) */
@@ -345,6 +346,9 @@ again:
        sigaddset(&slow_timer_sset, SIGCHLD);
        sigaddset(&slow_timer_sset, SIGALRM);
 #endif
+       /* initialize the config framework */
+       if (cfg_child_init()) goto error;
+
        return 0;
 error:
        return -1;
@@ -382,6 +386,9 @@ int arm_timer()
                                strerror(errno), errno);
                return -1;
        }
+       /* initialize the config framework */
+       if (cfg_child_init()) return -1;
+
        return 0;
 }
 
@@ -915,6 +922,9 @@ void timer_main()
        in_timer=1; /* mark this process as the fast timer */
        while(1){
                if (run_timer){
+                       /* update the local cfg if needed */
+                       cfg_update();
+
                        timer_handler();
                }
                pause();
@@ -1052,6 +1062,9 @@ void slow_timer_main()
                continue;
        }
 #endif
+               /* update the local cfg if needed */
+               cfg_update();
+               
                LOCK_SLOW_TIMER_LIST();
                while(*s_idx!=*t_idx){
                        i= *s_idx%SLOW_LISTS_NO;
index d039a42..adf7b9d 100644 (file)
@@ -66,6 +66,7 @@
 #include "receive.h"
 #include "mem/mem.h"
 #include "ip_addr.h"
+#include "cfg/cfg_struct.h"
 
 #ifdef USE_STUN
   #include "ser_stun.h"
@@ -428,6 +429,10 @@ int udp_rcv_loop()
        ri.dst_ip=bind_address->address;
        ri.proto=PROTO_UDP;
        ri.proto_reserved1=ri.proto_reserved2=0;
+
+       /* initialize the config framework */
+       if (cfg_child_init()) goto error;
+
        for(;;){
 #ifdef DYN_BUF
                buf=pkg_malloc(BUF_SIZE+1);
@@ -504,6 +509,8 @@ int udp_rcv_loop()
                                }
                        } else
 #endif
+               /* update the local config */
+               cfg_update();
                /* receive_msg must free buf too!*/
                receive_msg(buf, len, &ri);