Browse code

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

Daniel-Constantin Mierla authored on 07/10/2015 10:11:23
Showing 3 changed files
... ...
@@ -49,6 +49,7 @@
49 49
 #include "globals.h"
50 50
 #include "dset.h"
51 51
 #include "onsend.h"
52
+#include "fmsg.h"
52 53
 #include "resolve.h"
53 54
 #ifdef USE_TCP
54 55
 #include "tcp_server.h"
... ...
@@ -1635,3 +1636,36 @@ int run_top_route(struct action* a, sip_msg_t* msg, struct run_act_ctx *c)
1635 1635
 	setsflagsval(sfbk);
1636 1636
 	return ret;
1637 1637
 }
1638
+
1639
+
1640
+/**
1641
+ *
1642
+ */
1643
+int run_child_one_init_route(void)
1644
+{
1645
+	struct sip_msg *fmsg;
1646
+	struct run_act_ctx ctx;
1647
+	int rtb, rt;
1648
+
1649
+	LM_DBG("attempting to run event_route[core:worker-one-init]\n");
1650
+
1651
+	rt = route_get(&event_rt, "core:worker-one-init");
1652
+	if(rt>=0 && event_rt.rlist[rt]!=NULL) {
1653
+		LM_DBG("executing event_route[core:worker-one-init] (%d)\n", rt);
1654
+		if(faked_msg_init()<0)
1655
+			return -1;
1656
+		fmsg = faked_msg_next();
1657
+		rtb = get_route_type();
1658
+		set_route_type(REQUEST_ROUTE);
1659
+		init_run_actions_ctx(&ctx);
1660
+		run_top_route(event_rt.rlist[rt], fmsg, &ctx);
1661
+		if(ctx.run_flags&DROP_R_F)
1662
+		{
1663
+			LM_ERR("exit due to 'drop' in event route\n");
1664
+			return -1;
1665
+		}
1666
+		set_route_type(rtb);
1667
+	}
1668
+
1669
+	return 0;
1670
+}
... ...
@@ -75,4 +75,6 @@ int run_actions_safe(struct run_act_ctx* c, struct action* a,
75 75
 
76 76
 void log_prefix_set(sip_msg_t *msg);
77 77
 
78
+int run_child_one_init_route(void);
79
+
78 80
 #endif
... ...
@@ -1228,6 +1228,7 @@ int main_loop(void)
1228 1228
 	int r;
1229 1229
 #endif
1230 1230
 	int nrprocs;
1231
+	int woneinit;
1231 1232
 
1232 1233
 	/* one "main" process and n children handling i/o */
1233 1234
 	if (dont_fork){
... ...
@@ -1544,6 +1545,7 @@ int main_loop(void)
1544 1544
 		if (counters_prefork_init(get_max_procs()) == -1) goto error;
1545 1545
 
1546 1546
 
1547
+		woneinit = 0;
1547 1548
 		/* udp processes */
1548 1549
 		for(si=udp_listen; si; si=si->next){
1549 1550
 			nrprocs = (si->workers>0)?si->workers:children_no;
... ...
@@ -1580,8 +1582,13 @@ int main_loop(void)
1580 1580
 #ifdef STATS
1581 1581
 					setstats( i+r*children_no );
1582 1582
 #endif
1583
+					if(woneinit==0) {
1584
+						if(run_child_one_init_route()<0)
1585
+							goto error;
1586
+					}
1583 1587
 					return udp_rcv_loop();
1584 1588
 				}
1589
+				woneinit = 1;
1585 1590
 			}
1586 1591
 			/*parent*/
1587 1592
 			/*close(udp_sock)*/; /*if it's closed=>sendto invalid fd errors?*/