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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date:   Wed Apr 24 13:38:32 2013 +0200

core: new global parameter - modinit_delay

- sepecify microseconds to sleep after initializing a module in order to
  cope with systems having rate limits on new connections to db or other
  servers

---

 cfg.lex     |    2 ++
 cfg.y       |    3 +++
 sr_module.c |   17 ++++++++++++++++-
 sr_module.h |    2 ++
 4 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/cfg.lex b/cfg.lex
index a290e0f..3f754ac 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -337,6 +337,7 @@ AVP_PREF    (([ft][rud]?)|g)\.
 DEBUG  debug
 FORK   fork
 FORK_DELAY     fork_delay
+MODINIT_DELAY  modinit_delay
 LOGSTDERROR    log_stderror
 LOGFACILITY    log_facility
 LOGNAME                log_name
@@ -707,6 +708,7 @@ IMPORTFILE      "import_file"
 <INITIAL>{DEBUG}       { count(); yylval.strval=yytext; return DEBUG_V; }
 <INITIAL>{FORK}                { count(); yylval.strval=yytext; return FORK; }
 <INITIAL>{FORK_DELAY}  { count(); yylval.strval=yytext; return FORK_DELAY; }
+<INITIAL>{MODINIT_DELAY}       { count(); yylval.strval=yytext; return 
MODINIT_DELAY; }
 <INITIAL>{LOGSTDERROR} { yylval.strval=yytext; return LOGSTDERROR; }
 <INITIAL>{LOGFACILITY} { yylval.strval=yytext; return LOGFACILITY; }
 <INITIAL>{LOGNAME}     { yylval.strval=yytext; return LOGNAME; }
diff --git a/cfg.y b/cfg.y
index c448883..ac4fa58 100644
--- a/cfg.y
+++ b/cfg.y
@@ -390,6 +390,7 @@ extern char *finame;
 %token DEBUG_V
 %token FORK
 %token FORK_DELAY
+%token MODINIT_DELAY
 %token LOGSTDERROR
 %token LOGFACILITY
 %token LOGNAME
@@ -842,6 +843,8 @@ assign_stm:
        | FORK  EQUAL error  { yyerror("boolean value expected"); }
        | FORK_DELAY  EQUAL NUMBER { set_fork_delay($3); }
        | FORK_DELAY  EQUAL error  { yyerror("number expected"); }
+       | MODINIT_DELAY  EQUAL NUMBER { set_modinit_delay($3); }
+       | MODINIT_DELAY  EQUAL error  { yyerror("number expected"); }
        | LOGSTDERROR EQUAL NUMBER { if (!config_check)  /* if set from cmd 
line, don't overwrite from yyparse()*/ 
                                        if(log_stderr == 0) log_stderr=$3; 
                                   }
diff --git a/sr_module.c b/sr_module.c
index 3cce9fe..e169291 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -120,6 +120,17 @@ struct sr_module* modules=0;
 int mod_response_cbk_no=0;
 response_function* mod_response_cbks=0;
 
+/* number of usec to wait before initializing a module */
+static unsigned int modinit_delay = 0;
+
+unsigned int set_modinit_delay(unsigned int v)
+{
+       unsigned int r;
+       r =  modinit_delay;
+       modinit_delay = v;
+       return r;
+}
+
 /**
  * if bit 1 set, SIP worker processes handle RPC commands as well
  * if bit 2 set, RPC worker processes handle SIP commands as well
@@ -832,12 +843,16 @@ int init_modules(void)
        struct sr_module* t;
 
        for(t = modules; t; t = t->next) {
-               if (t->exports.init_f)
+               if (t->exports.init_f) {
                        if (t->exports.init_f() != 0) {
                                LOG(L_ERR, "init_modules(): Error while"
                                                " initializing module %s\n", 
t->exports.name);
                                return -1;
                        }
+                       /* delay next module init, if configured */
+                       if(unlikely(modinit_delay>0))
+                               sleep_us(modinit_delay);
+               }
                if (t->exports.response_f)
                        mod_response_cbk_no++;
        }
diff --git a/sr_module.h b/sr_module.h
index 810008f..14f9936 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -670,4 +670,6 @@ void set_child_rpc_sip_mode(void);
 int is_sip_worker(int rank);
 int is_rpc_worker(int rank);
 
+unsigned int set_modinit_delay(unsigned int v);
+
 #endif /* sr_module_h */


_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to