Parcourir la source

mtree: skip db init for special ranks

Daniel-Constantin Mierla il y a 14 ans
Parent
commit
517df28fc6
1 fichiers modifiés avec 15 ajouts et 9 suppressions
  1. 15 9
      modules/mtree/mtree_mod.c

+ 15 - 9
modules/mtree/mtree_mod.c

@@ -104,8 +104,8 @@ static int w_mt_match(struct sip_msg* msg, char* str1, char* str2,
 
 static int  mod_init(void);
 static void mod_destroy(void);
-static int  child_init(void);
-static int  mod_child_init(int r);
+static int  child_init(int rank);
+static int  mi_child_init(void);
 
 static int mt_match(struct sip_msg *msg, gparam_t *dm, gparam_t *var,
 		gparam_t *mode);
@@ -142,7 +142,7 @@ static param_export_t params[]={
 };
 
 static mi_export_t mi_cmds[] = {
-	{ "mt_reload",  mt_mi_reload,  0,  0,  child_init },
+	{ "mt_reload",  mt_mi_reload,  0,  0,  mi_child_init },
 	{ "mt_list",    mt_mi_list,    0,  0,  0 },
 	{ "mt_summary", mt_mi_summary, 0,  0,  0 },
 	{ 0, 0, 0, 0, 0}
@@ -161,7 +161,7 @@ struct module_exports exports = {
 	mod_init,       /* module initialization function */
 	0,              /* response function */
 	mod_destroy,    /* destroy function */
-	mod_child_init  /* per child init function */
+	child_init      /* per child init function */
 };
 
 
@@ -322,8 +322,10 @@ error1:
 	return -1;
 }
 
-
-static int child_init(void)
+/**
+ * mi and worker process initialization
+ */
+static int mi_child_init(void)
 {
 	if(db_con!=NULL)
 		return 0;
@@ -339,12 +341,16 @@ static int child_init(void)
 
 
 /* each child get a new connection to the database */
-static int mod_child_init(int r)
+static int child_init(int rank)
 {
-	if ( child_init()!=0 )
+	/* skip child init for non-worker process ranks */
+	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN)
+		return 0;
+
+	if ( mi_child_init()!=0 )
 		return -1;
 
-	LM_DBG("#%d: database connection opened successfully\n",r);
+	LM_DBG("#%d: database connection opened successfully\n", rank);
 
 	return 0;
 }