Browse Source

dialog(k): port db setup to different child_init behaviour on sr

- port db setup to different child_init behaviour on sr, here child_init
  is called two times for PROC_MAIN
- don't open a DB connection in PROC_MAIN in DB_MODE_DELAYED
- don't close the connection during mod_destroy if nothing was opened
Henning Westerholt 16 years ago
parent
commit
ffcf29e66d
1 changed files with 8 additions and 4 deletions
  1. 8 4
      modules_k/dialog/dialog.c

+ 8 - 4
modules_k/dialog/dialog.c

@@ -570,10 +570,9 @@ static int child_init(int rank)
 		if_update_stat(dlg_enable_stats, early_dlgs, early_dlgs_cnt);
 	}
 
-	if ( (dlg_db_mode==DB_MODE_REALTIME && (rank>0 || rank==PROC_TIMER)) ||
-	(dlg_db_mode==DB_MODE_SHUTDOWN && (rank==PROC_MAIN)) ||
-	(dlg_db_mode==DB_MODE_DELAYED && (rank==PROC_MAIN || rank==PROC_TIMER ||
-	rank>0) )){
+	if ( ((dlg_db_mode==DB_MODE_REALTIME || DB_MODE_DELAYED) &&
+	(rank>0 || rank==PROC_TIMER)) ||
+	(dlg_db_mode==DB_MODE_SHUTDOWN && (rank==PROC_MAIN)) ) {
 		if ( dlg_connect_db(&db_url) ) {
 			LM_ERR("failed to connect to database (rank=%d)\n",rank);
 			return -1;
@@ -584,6 +583,11 @@ static int child_init(int rank)
 	 * for the rest of the processes will be the same as DB_MODE_NONE */
 	if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN)
 		dlg_db_mode = DB_MODE_NONE;
+	/* in DB_MODE_REALTIME and DB_MODE_DELAYED the PROC_MAIN or the ones
+	 * with negative rank will have no db connection */
+	if ( (dlg_db_mode==DB_MODE_REALTIME || dlg_db_mode==DB_MODE_DELAYED) &&
+			(rank<0 || rank==PROC_MAIN))
+		dlg_db_mode = DB_MODE_NONE;
 
 	return 0;
 }