[Freeswitch-svn] [commit] r12192 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event

FreeSWITCH SVN andrew at freeswitch.org
Fri Feb 20 10:52:29 PST 2009


Author: andrew
Date: Fri Feb 20 12:52:29 2009
New Revision: 12192

Log:
Use switch_strlen_zero_buf instead of switch_strlen_zero; Handle module init failures better


Modified:
   freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
   freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c

Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c	Fri Feb 20 12:52:29 2009
@@ -426,7 +426,7 @@
 	}
 	else {
 		switch_core_session_t *session;
-		if (!switch_strlen_zero(uuid) && (session = switch_core_session_locate(uuid))) {
+		if (!switch_strlen_zero_buf(uuid) && (session = switch_core_session_locate(uuid))) {
 			switch_event_t *event;	  
 			if (switch_event_create(&event, SWITCH_EVENT_SEND_MESSAGE) == SWITCH_STATUS_SUCCESS) {
 				
@@ -538,7 +538,7 @@
 		ei_x_encode_atom(rbuf, "badarg");
 	} else {
 		switch_core_session_t *session;
-		if (!switch_strlen_zero(uuid_str) && (session = switch_core_session_locate(uuid_str))) {
+		if (!switch_strlen_zero_buf(uuid_str) && (session = switch_core_session_locate(uuid_str))) {
 			/* create a new session list element and attach it to this listener */
 			if ((arity==2 && attach_call_to_pid(listener, &msg->from, session)) ||
 				(arity==3 && attach_call_to_registered_process(listener, reg_name, session))) {

Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	Fri Feb 20 12:52:29 2009
@@ -1365,10 +1365,10 @@
 	rv = inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
 	if (rv == 0) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip);
-		return SWITCH_STATUS_GENERR;
+		goto init_failed;
 	} else if (rv == -1) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error when parsing ip address %s : %s\n", prefs.ip, strerror(errno));
-		return SWITCH_STATUS_GENERR;
+		goto init_failed;
 	}
 
 	/* set the address family and port */
@@ -1406,22 +1406,20 @@
 
 	if (SWITCH_STATUS_SUCCESS!=initialise_ei(&ec)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to init ei connection\n");
-		close_socket(&listen_list.sockfd);
-		return SWITCH_STATUS_GENERR;
+		goto init_failed;
 	}
 
 	/* return value is -1 for error, a descriptor pointing to epmd otherwise */
 	if ((epmdfd = ei_publish(&ec, prefs.port)) == -1) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to publish port to empd, trying to start empd manually\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to publish port to empd, trying to start empd via system()\n");
 		if (system("epmd -daemon")) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to start empd manually\n");
-			close_socket(&listen_list.sockfd);
-			return SWITCH_STATUS_GENERR;
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to start empd manually! Is epmd in $PATH? If not, start it yourself or run an erl shell with -sname or -name\n");
+			goto init_failed;
 		}
+		switch_yield(100000);
 		if ((epmdfd = ei_publish(&ec, prefs.port)) == -1) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to publish port to empd AGAIN\n");
-			close_socket(&listen_list.sockfd);
-			return SWITCH_STATUS_GENERR;
+			goto init_failed;
 		}
 	}
 
@@ -1470,6 +1468,7 @@
 	ei_unpublish(&ec);
 	close(epmdfd);
 
+init_failed:
 	close_socket(&listen_list.sockfd);
 	if (pool) {
 		switch_core_destroy_memory_pool(&pool);
@@ -1491,7 +1490,8 @@
 	listener_t *l;
 	int sanity = 0;
 
-	prefs.done = 1;
+	if (prefs.done == 0) /* main thread might already have exited */
+		prefs.done = 1;
 
 	switch_log_unbind_logger(socket_logger);
 



More information about the Freeswitch-svn mailing list