|
@@ -1,40 +1,44 @@
|
|
|
#$Id$
|
|
|
#
|
|
|
-# Module intialization description
|
|
|
#
|
|
|
# History
|
|
|
#--------
|
|
|
# 2007-06-07 created by Andrei Pelinescu <[email protected]>
|
|
|
#
|
|
|
|
|
|
+SIP-router Module intialization description
|
|
|
+===========================================
|
|
|
|
|
|
This document is a very brief overview on what possibilities are for a module
|
|
|
-to run some initializations (or put in another way what's safe and what's
|
|
|
+to run some initializations (or put in another way: What's safe and what's
|
|
|
not safe to do in mod_init and mod_child_init).
|
|
|
|
|
|
The interesting function are the mod_init (the init_f memeber of
|
|
|
- the module_exports structure) and the mod_child_init (init_child_f in
|
|
|
- module_exports) functions.
|
|
|
+the module_exports structure) and the mod_child_init (init_child_f in
|
|
|
+module_exports) functions.
|
|
|
|
|
|
mod_init
|
|
|
--------
|
|
|
|
|
|
mod_init is called after parsing the config, loading all the modules and
|
|
|
- going into daemon mode. mod_init is called in the main process context,
|
|
|
- before changing the uid or gid (so if you want to do something requiring
|
|
|
- higher privileges this is the place to do it). This is not the right place
|
|
|
- to fork more ser processes, but instead is the only place where one can
|
|
|
- register future forked processes (see register_procs()).
|
|
|
+going into daemon mode. mod_init is called in the main process context,
|
|
|
+before changing the uid or gid (so if you want to do something requiring
|
|
|
+higher privileges this is the place to do it). This is not the right place
|
|
|
+to fork more SIP-router processes, but instead is the only place where one can
|
|
|
+register future forked processes (see register_procs()).
|
|
|
+
|
|
|
mod_init is ideal for initializing per process variables, assuming that you
|
|
|
- don't need different values for each ser child (in which case see mod_child_init below) and shared memory variables assuming that you don't need ser's number of processes (which is not available at this point).
|
|
|
+don't need different values for each SIP-router child (in which case see
|
|
|
+mod_child_init below) and shared memory variables assuming that you don't
|
|
|
+need SIP-router's number of processes (which is not available at this point).
|
|
|
|
|
|
|
|
|
mod_child_init
|
|
|
---------------
|
|
|
|
|
|
-mod_child_init is called for each forked ser process with 2 exceptions:
|
|
|
+mod_child_init is called for each forked SIP-router process with 2 exceptions:
|
|
|
- it's called for the main process too and it's called twice
|
|
|
- - it's not called for ser processes forked with PROC_NOCHLDINIT
|
|
|
+ - it's not called for SIP-router processes forked with PROC_NOCHLDINIT
|
|
|
|
|
|
mod_child_init is always called after mod_init. It takes one parameter, the
|
|
|
process rank. This parameter can be used to differentiate between normal
|
|
@@ -44,7 +48,7 @@ There are two very special rank values: PROC_INIT (as of 2007-06-06) and
|
|
|
mod_child_init(PROC_INIT) is the first mod_child_init call made, and it's
|
|
|
guaranteed to happen before any child process is forked. The process context
|
|
|
is the "main" process (as for mod_init), but this time we have a little bit
|
|
|
- more information: we know the number of ser processes. This is the right
|
|
|
+ more information: we know the number of SIP-router processes. This is the right
|
|
|
place to initialize things like shared arrays[get_max_procs()].
|
|
|
Note also that everything done here will be inherited in all the future
|
|
|
children processes (since it's executed in the "main" process context before
|
|
@@ -52,14 +56,14 @@ Note also that everything done here will be inherited in all the future
|
|
|
|
|
|
mod_child_init(PROC_MAIN) is another call that is done in the same "main"
|
|
|
process context. This call happens just before initializing the main tcp
|
|
|
- process. This is the only right place for forking more ser processes
|
|
|
+ process. This is the only right place for forking more SIP-router processes
|
|
|
(see fork_process()). WARNING: the context is the same "main" process as
|
|
|
for mod_child_init(PROC_INIT) and mod_init() so care must be taken not to
|
|
|
initialize things twice or three times for the "main" process.
|
|
|
|
|
|
Except for the "main" process case mod_child_init(rank) will be called only
|
|
|
once for each new child process, just after forking. A positive non-zero rank
|
|
|
- means the current process is a normal ser process and a negative rank has
|
|
|
+ means the current process is a normal SIP-router process and a negative rank has
|
|
|
some special meaning (grep PROC_ sr_module.h for more info).
|
|
|
mod_child_init(rank) is the best place for initializing per process variables,
|
|
|
opening per process database connections, new sockets a.s.o. Note however
|
|
@@ -72,15 +76,15 @@ mod_child_init(rank) is the best place for initializing per process variables,
|
|
|
mod_child_init in the no-fork case
|
|
|
----------------------------------
|
|
|
|
|
|
-If ser is started in no-fork mode it will try to start as few processes as
|
|
|
+If SIP-router is started in no-fork mode it will try to start as few processes as
|
|
|
possible (as of this date it will start 3 processes the main process and the
|
|
|
- 2 timers). In this case mod_child_init() will be called 3 times in the
|
|
|
- same "main" process context: mod_child_init(PROC_INIT);
|
|
|
- mod_child_init(PROC_MAIN) and mod_child_init(1) (since the first process is
|
|
|
- also the "main" one).
|
|
|
+2 timers). In this case mod_child_init() will be called 3 times in the
|
|
|
+same "main" process context: mod_child_init(PROC_INIT);
|
|
|
+mod_child_init(PROC_MAIN) and mod_child_init(1) (since the first process is
|
|
|
+also the "main" one).
|
|
|
|
|
|
|
|
|
-Forking new ser processes from a module
|
|
|
+Forking new SIP-router processes from a module
|
|
|
---------------------------------------
|
|
|
|
|
|
static int mod_init()
|
|
@@ -133,8 +137,9 @@ mod_child_init(PROC_INIT)
|
|
|
process.
|
|
|
|
|
|
mod_child_init(PROC_MAIN)
|
|
|
- - the only place from where another ser process can be forked (see fork_process ()), but remember first to register the number of to-be-forked processes in
|
|
|
- mod_init()
|
|
|
+ - the only place from where another SIP-router process can be forked
|
|
|
+ (see fork_process ()), but remember first to register the number of
|
|
|
+ to-be-forked processes in mod_init()
|
|
|
|
|
|
mod_child_init(rank!=PROC_INIT && rank!=PROC_MAIN)
|
|
|
- initialize other per process variables (e.g. different values), whose
|