소스 검색

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 12 년 전
부모
커밋
52d339408f
4개의 변경된 파일23개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 16 1
      sr_module.c
  4. 2 0
      sr_module.h

+ 2 - 0
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; }

+ 3 - 0
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; 
 				   }

+ 16 - 1
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++;
 	}

+ 2 - 0
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 */