db: Fixing problem with incorrect initialization of db connections
The sip-router core is based on the ser core and thus has a slightly
different initialization sequence of the main sr process. Namely we
also call the child_init function of all modules in the main process
with rank PROC_INIT. This is a kind of delayed initialization (called
after all mod_init functions have finished but before the main
process started forking children).
There should be no database connections opened in child_init called
with PROC_INIT parameter. This would result in database connections
opened in the main process and inherited by all children. Such
connections could then be used from multiple processes simultaneously
and that can cause race conditions.
This change checks for the value of the rank parameter in child_init
functions and skips database initialization if the value is PROC_INIT,
PROC_MAIN, or PROC_TCP_MAIN.
The problem was reported by Juha and he deserves the credit for helping to
investigate the issue.