Browse code

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

Daniel-Constantin Mierla authored on 24/04/2013 11:38:32
Showing 4 changed files
... ...
@@ -337,6 +337,7 @@ AVP_PREF	(([ft][rud]?)|g)\.
337 337
 DEBUG	debug
338 338
 FORK	fork
339 339
 FORK_DELAY	fork_delay
340
+MODINIT_DELAY	modinit_delay
340 341
 LOGSTDERROR	log_stderror
341 342
 LOGFACILITY	log_facility
342 343
 LOGNAME		log_name
... ...
@@ -707,6 +708,7 @@ IMPORTFILE      "import_file"
707 707
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG_V; }
708 708
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
709 709
 <INITIAL>{FORK_DELAY}	{ count(); yylval.strval=yytext; return FORK_DELAY; }
710
+<INITIAL>{MODINIT_DELAY}	{ count(); yylval.strval=yytext; return MODINIT_DELAY; }
710 711
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
711 712
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
712 713
 <INITIAL>{LOGNAME}	{ yylval.strval=yytext; return LOGNAME; }
... ...
@@ -390,6 +390,7 @@ extern char *finame;
390 390
 %token DEBUG_V
391 391
 %token FORK
392 392
 %token FORK_DELAY
393
+%token MODINIT_DELAY
393 394
 %token LOGSTDERROR
394 395
 %token LOGFACILITY
395 396
 %token LOGNAME
... ...
@@ -842,6 +843,8 @@ assign_stm:
842 842
 	| FORK  EQUAL error  { yyerror("boolean value expected"); }
843 843
 	| FORK_DELAY  EQUAL NUMBER { set_fork_delay($3); }
844 844
 	| FORK_DELAY  EQUAL error  { yyerror("number expected"); }
845
+	| MODINIT_DELAY  EQUAL NUMBER { set_modinit_delay($3); }
846
+	| MODINIT_DELAY  EQUAL error  { yyerror("number expected"); }
845 847
 	| LOGSTDERROR EQUAL NUMBER { if (!config_check)  /* if set from cmd line, don't overwrite from yyparse()*/ 
846 848
 					if(log_stderr == 0) log_stderr=$3; 
847 849
 				   }
... ...
@@ -120,6 +120,17 @@ struct sr_module* modules=0;
120 120
 int mod_response_cbk_no=0;
121 121
 response_function* mod_response_cbks=0;
122 122
 
123
+/* number of usec to wait before initializing a module */
124
+static unsigned int modinit_delay = 0;
125
+
126
+unsigned int set_modinit_delay(unsigned int v)
127
+{
128
+	unsigned int r;
129
+	r =  modinit_delay;
130
+	modinit_delay = v;
131
+	return r;
132
+}
133
+
123 134
 /**
124 135
  * if bit 1 set, SIP worker processes handle RPC commands as well
125 136
  * if bit 2 set, RPC worker processes handle SIP commands as well
... ...
@@ -832,12 +843,16 @@ int init_modules(void)
832 832
 	struct sr_module* t;
833 833
 
834 834
 	for(t = modules; t; t = t->next) {
835
-		if (t->exports.init_f)
835
+		if (t->exports.init_f) {
836 836
 			if (t->exports.init_f() != 0) {
837 837
 				LOG(L_ERR, "init_modules(): Error while"
838 838
 						" initializing module %s\n", t->exports.name);
839 839
 				return -1;
840 840
 			}
841
+			/* delay next module init, if configured */
842
+			if(unlikely(modinit_delay>0))
843
+				sleep_us(modinit_delay);
844
+		}
841 845
 		if (t->exports.response_f)
842 846
 			mod_response_cbk_no++;
843 847
 	}
... ...
@@ -670,4 +670,6 @@ void set_child_rpc_sip_mode(void);
670 670
 int is_sip_worker(int rank);
671 671
 int is_rpc_worker(int rank);
672 672
 
673
+unsigned int set_modinit_delay(unsigned int v);
674
+
673 675
 #endif /* sr_module_h */