[sr-dev] git:master:b3d38eac: core: new feature to execute event_route[core:worker-one-init]
Daniel-Constantin Mierla
miconda at gmail.com
Wed Oct 7 15:40:27 CEST 2015
Doing something only one time at kamailio start. There is
event_route[htbale:mod-init], but that would require htable and some
other modules might not be initialized. Anyhow, it is sort of not
finished, because there are some aspects I want to discuss and see what
people would need from such feature.
Cheers,
Daniel
On 07/10/15 12:20, Jason Penton wrote:
> This is interesting, what is the motivation ;) ?
>
> On Wed, 7 Oct 2015 at 12:14 Daniel-Constantin Mierla
> <miconda at gmail.com <mailto:miconda at gmail.com>> wrote:
>
> Module: kamailio
> Branch: master
> Commit: b3d38eac7a24bff88a1ec555aa5a50ea5c3f0232
> URL:
> https://github.com/kamailio/kamailio/commit/b3d38eac7a24bff88a1ec555aa5a50ea5c3f0232
>
> Author: Daniel-Constantin Mierla <miconda at gmail.com
> <mailto:miconda at gmail.com>>
> Committer: Daniel-Constantin Mierla <miconda at gmail.com
> <mailto:miconda at gmail.com>>
> Date: 2015-10-07T12:14:24+02:00
>
> core: new feature to execute event_route[core:worker-one-init]
>
> - the event_route[core:worker-one-init] is executed if defined in
> kamailio.cfg after the first udp sip worker process executed the
> child_init() for all modules, before starting to process sip traffic
> - note that due to forking, other sip workers can get faster to
> listening for sip traffic
>
> ---
>
> Modified: action.c
> Modified: action.h
> Modified: main.c
>
> ---
>
> Diff:
> https://github.com/kamailio/kamailio/commit/b3d38eac7a24bff88a1ec555aa5a50ea5c3f0232.diff
> Patch:
> https://github.com/kamailio/kamailio/commit/b3d38eac7a24bff88a1ec555aa5a50ea5c3f0232.patch
>
> ---
>
> diff --git a/action.c b/action.c
> index 726c000..bef3ec6 100644
> --- a/action.c
> +++ b/action.c
> @@ -49,6 +49,7 @@
> #include "globals.h"
> #include "dset.h"
> #include "onsend.h"
> +#include "fmsg.h"
> #include "resolve.h"
> #ifdef USE_TCP
> #include "tcp_server.h"
> @@ -1635,3 +1636,36 @@ int run_top_route(struct action* a,
> sip_msg_t* msg, struct run_act_ctx *c)
> setsflagsval(sfbk);
> return ret;
> }
> +
> +
> +/**
> + *
> + */
> +int run_child_one_init_route(void)
> +{
> + struct sip_msg *fmsg;
> + struct run_act_ctx ctx;
> + int rtb, rt;
> +
> + LM_DBG("attempting to run
> event_route[core:worker-one-init]\n");
> +
> + rt = route_get(&event_rt, "core:worker-one-init");
> + if(rt>=0 && event_rt.rlist[rt]!=NULL) {
> + LM_DBG("executing
> event_route[core:worker-one-init] (%d)\n", rt);
> + if(faked_msg_init()<0)
> + return -1;
> + fmsg = faked_msg_next();
> + rtb = get_route_type();
> + set_route_type(REQUEST_ROUTE);
> + init_run_actions_ctx(&ctx);
> + run_top_route(event_rt.rlist[rt], fmsg, &ctx);
> + if(ctx.run_flags&DROP_R_F)
> + {
> + LM_ERR("exit due to 'drop' in event route\n");
> + return -1;
> + }
> + set_route_type(rtb);
> + }
> +
> + return 0;
> +}
> diff --git a/action.h b/action.h
> index d6f7810..62eed0c 100644
> --- a/action.h
> +++ b/action.h
> @@ -75,4 +75,6 @@ int run_actions_safe(struct run_act_ctx* c,
> struct action* a,
>
> void log_prefix_set(sip_msg_t *msg);
>
> +int run_child_one_init_route(void);
> +
> #endif
> diff --git a/main.c b/main.c
> index 3970db8..a4407fa 100644
> --- a/main.c
> +++ b/main.c
> @@ -1228,6 +1228,7 @@ int main_loop(void)
> int r;
> #endif
> int nrprocs;
> + int woneinit;
>
> /* one "main" process and n children handling i/o */
> if (dont_fork){
> @@ -1544,6 +1545,7 @@ int main_loop(void)
> if (counters_prefork_init(get_max_procs()) == -1)
> goto error;
>
>
> + woneinit = 0;
> /* udp processes */
> for(si=udp_listen; si; si=si->next){
> nrprocs =
> (si->workers>0)?si->workers:children_no;
> @@ -1580,8 +1582,13 @@ int main_loop(void)
> #ifdef STATS
> setstats( i+r*children_no );
> #endif
> + if(woneinit==0) {
> +
> if(run_child_one_init_route()<0)
> + goto error;
> + }
> return udp_rcv_loop();
> }
> + woneinit = 1;
> }
> /*parent*/
> /*close(udp_sock)*/; /*if it's
> closed=>sendto invalid fd errors?*/
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org <mailto:sr-dev at lists.sip-router.org>
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
--
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Book: SIP Routing With Kamailio - http://www.asipto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-dev/attachments/20151007/0eb0c55a/attachment.html>
More information about the sr-dev
mailing list