diff --git a/src/mod/event_handlers/mod_erlang_event/handle_msg.c b/src/mod/event_handlers/mod_erlang_event/handle_msg.c index 630a6ed8a0..9f3af150cc 100644 --- a/src/mod/event_handlers/mod_erlang_event/handle_msg.c +++ b/src/mod/event_handlers/mod_erlang_event/handle_msg.c @@ -426,7 +426,7 @@ static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_ } 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 @@ static switch_status_t handle_msg_handlecall(listener_t *listener, erlang_msg *m 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))) { diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index 538e0152d7..7ff8a5ea84 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1365,10 +1365,10 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime) 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 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime) 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 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime) ei_unpublish(&ec); close(epmdfd); +init_failed: close_socket(&listen_list.sockfd); if (pool) { switch_core_destroy_memory_pool(&pool); @@ -1491,7 +1490,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_erlang_event_shutdown) 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);