Hi Leonardo,

Please test the attached fix to solve the problem - triggering of the startup_route when there is no UDP listener.

Regards,

Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
http://www.opensips-solutions.com


On 06/29/2012 12:42 AM, Leonardo wrote:
Hello Guys,

I was doing some tests with the startup_route, but it was not being
executed. After some tests and looking inside OpensSIPS source code, I
figured out that it's not being executed because my OpenSIPS was not
listening to any UDP interface.

After adding a "listen=udp:127.0.0.1:5060" to the config file, startup_route
became to be properly executed.

It sounds like a bug for me, or is this the expected behavior?

Thanks a lot,
Leonardo


--
View this message in context: 
http://opensips-open-sip-server.1449251.n2.nabble.com/startup-route-not-being-executed-tp7580613.html
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Index: main.c
===================================================================
--- main.c	(revision 9292)
+++ main.c	(working copy)
@@ -822,8 +822,7 @@
 
 		if(startup_rlist.a) {/* if a startup route was defined */
 			startup_done = (int*)shm_malloc(sizeof(int));
-			if(startup_done == NULL)
-			{
+			if(startup_done == NULL) {
 				LM_ERR("No more shared memory\n");
 				goto error;
 			}
@@ -862,7 +861,9 @@
 							LM_ERR("failed to send status code\n");
 						clean_write_pipeend();
 
-						if(chd_rank == 1 && startup_rlist.a) {
+						/* first UDP proc runs statup_route (if defined) */
+						if(chd_rank == 1 && startup_done!=NULL) {
+							LM_DBG("runing startup for first UDP\n");
 							if(run_startup_route()< 0) {
 								LM_ERR("Startup route processing failed\n");
 								exit(-1);
@@ -877,13 +878,9 @@
 						exit(-1);
 					}
 					else {
-						/* if the first process that runs startup_route*/
-						if(chd_rank == 1 && startup_rlist.a) {
-							while(!startup_done) {
-								usleep(5);
-							}
-							shm_free(startup_done);
-						}
+						/* wait for first proc to finish the startup route */
+						if(chd_rank == 1 && startup_done!=NULL)
+							while( !(*startup_done) ) usleep(5);
 					}
 				}
 			}
@@ -914,12 +911,27 @@
 						exit(-1);
 					}
 
+					/* was startup route executed so far ? if not, run it only by the 
+					 * first SCTP proc (first proc from first interface) */
+					if( (si==sctp_listen && i==0) && startup_done!=NULL && *startup_done==0) {
+						LM_DBG("runing startup for first SCTP\n");
+						if(run_startup_route()< 0) {
+							LM_ERR("Startup route processing failed\n");
+							exit(-1);
+						}
+						*startup_done = 1;
+					}
+
 					if (send_status_code(0) < 0)
 						LM_ERR("failed to send status code\n");
 					clean_write_pipeend();
 
 					sctp_server_rcv_loop();
 					exit(-1);
+				} else {
+					/* wait for first proc to finish the startup route */
+					if( (si==sctp_listen && i==0) && startup_done!=NULL)
+						while( !(*startup_done) ) usleep(5);
 				}
 			}
 		}
@@ -938,7 +950,10 @@
 	#ifdef USE_TCP
 	if (!tcp_disable){
 		/* start tcp  & tls receivers */
-		if (tcp_init_children(&chd_rank)<0) goto error;
+		if (tcp_init_children(&chd_rank, startup_done)<0) goto error;
+		/* wait for the startup route to be executed */
+		if( startup_done!=NULL)
+			while( !(*startup_done) ) usleep(5);
 		/* start tcp+tls master proc */
 		if ( (pid=internal_fork( "TCP main"))<0 ) {
 			LM_CRIT("cannot fork tcp main process\n");
@@ -970,6 +985,12 @@
 	}
 	#endif
 
+	if (startup_done) {
+		if (*startup_done!=1)
+			LM_CRIT("BUG: startup route defined, but not run :( \n");
+		shm_free(startup_done);
+	}
+
 	/* main process left */
 	is_main=1;
 	set_proc_attrs("attendant");
Index: tcp_init.h
===================================================================
--- tcp_init.h	(revision 9292)
+++ tcp_init.h	(working copy)
@@ -32,7 +32,7 @@
 int init_tcp();
 void destroy_tcp();
 int tcp_init(struct socket_info* sock_info);
-int tcp_init_children(int *chd_rank);
+int tcp_init_children(int *chd_rank, int *startup_done);
 void tcp_main_loop();
 void tcp_receive_loop(int unix_sock);
 
Index: tcp_main.c
===================================================================
--- tcp_main.c	(revision 9292)
+++ tcp_main.c	(working copy)
@@ -1758,7 +1758,7 @@
 
 
 /*! \brief starts the tcp processes */
-int tcp_init_children(int *chd_rank)
+int tcp_init_children(int *chd_rank, int *startup_done)
 {
 	int r;
 	//int sockfd[2];
@@ -1829,6 +1829,16 @@
 				exit(-1);
 			}
 	
+			/* was startup route executed so far ? */
+			if (startup_done!=NULL && *startup_done==0 && r==0) {
+				LM_DBG("runing startup for first TCP\n");
+				if(run_startup_route()< 0) {
+					LM_ERR("Startup route processing failed\n");
+					exit(-1);
+				}
+				*startup_done = 1;
+			}
+
 			if (send_status_code(0) < 0)
 				LM_ERR("failed to send status code\n");
 			clean_write_pipeend();
_______________________________________________
Users mailing list
[email protected]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

Reply via email to