Hi, according to kamailio-devel-guide child_init function is just called for kamailio workers:
16.10.6. Module Child Init Function This is the function called just after KAMAILIO (OPENSER) forks its worker processes.
but later it says:
The function gets as parameter the rank of the child process. The rank is a positive number if it is a worker process and negative for special processes like timer processes or TCP attendant.
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
For example, in modules_k/alias_db module I see:
----------------------------------------------- static int child_init(int rank) { if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0; /* do nothing for the main process */
db_handle = adbf.init(&db_url); if (!db_handle) { LM_ERR("unable to connect database\n"); return -1; } return 0; } ---------------------------------------------
But in modules/db_flatstore I see:
--------------------------------------------- /* * FIXME: We should check whether just calling km_child_init would really work * here. This function comes from kamailio and since the core of sip-router is * based on SER 2.0, the way how child_init is called and values of the rank * variable could be incompatible with km_child_init function. A solution here * would be to rewrite km_child_init with ser 2.0 init stuff in mind. */ static int child_init(int rank) { char* tmp; unsigned int v;
km_child_init(rank);
if (rank <= 0) { v = -rank; } else { v = rank - PROC_MIN; } [...] ---------------------------------------------
I just want child_init to be run for workers, and no por other special processes. Also I'm writting the module under modules/ so, what should I do to achieve it?
Thanks a lot.
On 10/2/10 4:27 PM, Iñaki Baz Castillo wrote:
Hi, according to kamailio-devel-guide child_init function is just called for kamailio workers:
16.10.6. Module Child Init Function This is the function called just after KAMAILIO (OPENSER) forks its worker processes.
but later it says:
The function gets as parameter the rank of the child process. The rank is a positive number if it is a worker process and negative for special processes like timer processes or TCP attendant.
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
yes, check it. The phrases use same term, while in one case should be 'sip worker process' to differentiate from other type of workers.
Beware than from v3.0 you get also rank PROC_INIT, which is called for main process after all mod_init functions were executed.
Cheers, Daniel
For example, in modules_k/alias_db module I see:
static int child_init(int rank) {
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0; /* do nothing for the main process */
db_handle = adbf.init(&db_url); if (!db_handle) { LM_ERR("unable to connect database\n"); return -1; } return 0; }
But in modules/db_flatstore I see:
/*
- FIXME: We should check whether just calling km_child_init would really work
- here. This function comes from kamailio and since the core of sip-router is
- based on SER 2.0, the way how child_init is called and values of the rank
- variable could be incompatible with km_child_init function. A solution here
- would be to rewrite km_child_init with ser 2.0 init stuff in mind.
*/ static int child_init(int rank) { char* tmp; unsigned int v;
km_child_init(rank);
if (rank<= 0) { v = -rank; } else { v = rank - PROC_MIN; } [...]
I just want child_init to be run for workers, and no por other special processes. Also I'm writting the module under modules/ so, what should I do to achieve it?
Thanks a lot.
2010/10/2 Daniel-Constantin Mierla miconda@gmail.com:
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
yes, check it. The phrases use same term, while in one case should be 'sip worker process' to differentiate from other type of workers.
Beware than from v3.0 you get also rank PROC_INIT, which is called for main process after all mod_init functions were executed.
Then, is it ok if I use:
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0;
?
what about possible PROC_SCTP_MAIN (if it exists) and others? I've checked that all those special processes (non workers) as rack <= 0. Is it safe if I just apply the code for processes with rank > 0?
Thanks a lot.
On Oct 02, 2010 at 18:30, Iñaki Baz Castillo ibc@aliax.net wrote:
2010/10/2 Daniel-Constantin Mierla miconda@gmail.com:
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
yes, check it. The phrases use same term, while in one case should be 'sip worker process' to differentiate from other type of workers.
Beware than from v3.0 you get also rank PROC_INIT, which is called for main process after all mod_init functions were executed.
Then, is it ok if I use:
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0;
?
Yes.
Depending on what your code does you could also add PROC_RPC and PROC_UNIXSOCK if you don't need to do anything in the RPC processes. Do not do this if you implement some RPC function that uses some local per process stuff you initialized in child_init() (for example a db connection, an open file).
what about possible PROC_SCTP_MAIN (if it exists) and others?
There is no PROC_SCTP_MAIN.
I've checked that all those special processes (non workers) as rack <= 0. Is it safe if I just apply the code for processes with rank > 0?
Yes, but you might need the initialization to run for the RPC processes (see above). If you use any timer you might also need the initialization in the timer processes. In this case you could use: if (rank > 0 || rank == PROC_TIMER || rank == PROC_RPC || rank == PROC_UNIXSOCK)
A rank > 0 means a normal sip-router worker process and values <=0 are special.
Andrei P.S.: PROC_UNIXSOCK is deprecated.
2010/10/4 Andrei Pelinescu-Onciul andrei@iptel.org:
On Oct 02, 2010 at 18:30, Iñaki Baz Castillo ibc@aliax.net wrote:
2010/10/2 Daniel-Constantin Mierla miconda@gmail.com:
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
yes, check it. The phrases use same term, while in one case should be 'sip worker process' to differentiate from other type of workers.
Beware than from v3.0 you get also rank PROC_INIT, which is called for main process after all mod_init functions were executed.
Then, is it ok if I use:
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0;
?
Yes.
Depending on what your code does you could also add PROC_RPC and PROC_UNIXSOCK if you don't need to do anything in the RPC processes. Do not do this if you implement some RPC function that uses some local per process stuff you initialized in child_init() (for example a db connection, an open file).
what about possible PROC_SCTP_MAIN (if it exists) and others?
There is no PROC_SCTP_MAIN.
I've checked that all those special processes (non workers) as rack <= 0. Is it safe if I just apply the code for processes with rank > 0?
Yes, but you might need the initialization to run for the RPC processes (see above). If you use any timer you might also need the initialization in the timer processes. In this case you could use: if (rank > 0 || rank == PROC_TIMER || rank == PROC_RPC || rank == PROC_UNIXSOCK)
A rank > 0 means a normal sip-router worker process and values <=0 are special.
Andrei P.S.: PROC_UNIXSOCK is deprecated.
Thanks Andrei. Where could I get the complete list DEFINE's for special processes? For example I expect there is also something as PROC_MI, is it?
Thanks a lot.
On Oct 04, 2010 at 14:44, Iñaki Baz Castillo ibc@aliax.net wrote:
2010/10/4 Andrei Pelinescu-Onciul andrei@iptel.org:
On Oct 02, 2010 at 18:30, Iñaki Baz Castillo ibc@aliax.net wrote:
2010/10/2 Daniel-Constantin Mierla miconda@gmail.com:
So my question is: should I check the rank parameter in child_init function just to run the code for real workers?
yes, check it. The phrases use same term, while in one case should be 'sip worker process' to differentiate from other type of workers.
Beware than from v3.0 you get also rank PROC_INIT, which is called for main process after all mod_init functions were executed.
Then, is it ok if I use:
if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) return 0;
?
Yes.
Depending on what your code does you could also add PROC_RPC and PROC_UNIXSOCK if you don't need to do anything in the RPC processes. Do not do this if you implement some RPC function that uses some local per process stuff you initialized in child_init() (for example a db connection, an open file).
what about possible PROC_SCTP_MAIN (if it exists) and others?
There is no PROC_SCTP_MAIN.
I've checked that all those special processes (non workers) as rack <= 0. Is it safe if I just apply the code for processes with rank > 0?
Yes, but you might need the initialization to run for the RPC processes (see above). If you use any timer you might also need the initialization in the timer processes. In this case you could use: if (rank > 0 || rank == PROC_TIMER || rank == PROC_RPC || rank == PROC_UNIXSOCK)
A rank > 0 means a normal sip-router worker process and values <=0 are special.
Andrei P.S.: PROC_UNIXSOCK is deprecated.
Thanks Andrei. Where could I get the complete list DEFINE's for special processes? For example I expect there is also something as PROC_MI, is it?
sr_module.h, search for PROC_.
There is no PROC_MI. mi does not run child_init() functions in sr and I think it didn't do so in k <= 1.5. Being deprecated it probably makes no sense to fix it.
Andrei
2010/10/4 Andrei Pelinescu-Onciul andrei@iptel.org:
Thanks Andrei. Where could I get the complete list DEFINE's for special processes? For example I expect there is also something as PROC_MI, is it?
sr_module.h, search for PROC_.
There is no PROC_MI. mi does not run child_init() functions in sr and I think it didn't do so in k <= 1.5. Being deprecated it probably makes no sense to fix it.
Thanks a lot.