Browse code

usrloc: connect to db for main process in PROC_POSTCHILDINIT child init

(cherry picked from commit 4780d46976a7a392f23af0d89f05855d473bcb30)

Daniel-Constantin Mierla authored on 09/05/2022 07:05:18
Showing 1 changed files
... ...
@@ -358,6 +358,16 @@ static int mod_init(void)
358 358
 	}
359 359
 
360 360
 	/* Shall we use database ? */
361
+	switch (ul_db_mode) {
362
+		case DB_ONLY:
363
+		case WRITE_THROUGH:
364
+		case WRITE_BACK:
365
+		/*
366
+		 * register the need to be called post-fork of all children
367
+		 * with the special rank PROC_POSTCHILDINIT
368
+		 */
369
+		ksr_module_set_flag(KSRMOD_FLAG_POSTCHILDINIT);
370
+	}
361 371
 	if (ul_db_mode != NO_DB) { /* Yes */
362 372
 		if (db_bind_mod(&ul_db_url, &ul_dbf) < 0) { /* Find database module */
363 373
 			LM_ERR("failed to bind database module\n");
... ...
@@ -452,14 +462,14 @@ static int child_init(int _rank)
452 462
 		case WRITE_THROUGH:
453 463
 			/* connect to db only from SIP workers, TIMER and MAIN processes,
454 464
 			 *  and RPC processes */
455
-			if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_MAIN
465
+			if (_rank<=0 && _rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT
456 466
 					 && _rank!=PROC_RPC)
457 467
 				return 0;
458 468
 			break;
459 469
 		case WRITE_BACK:
460 470
 			/* connect to db only from TIMER (for flush), from MAIN (for
461 471
 			 * final flush() and from child 1 for preload */
462
-			if (_rank!=PROC_TIMER && _rank!=PROC_MAIN && _rank!=PROC_SIPINIT)
472
+			if (_rank!=PROC_TIMER && _rank!=PROC_POSTCHILDINIT && _rank!=PROC_SIPINIT)
463 473
 				return 0;
464 474
 			break;
465 475
 		case DB_READONLY: