]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Use switch_strlen_zero_buf instead of switch_strlen_zero; Handle module init failures...
authorAndrew Thompson <andrew@hijacked.us>
Fri, 20 Feb 2009 18:52:29 +0000 (18:52 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Fri, 20 Feb 2009 18:52:29 +0000 (18:52 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12192 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_erlang_event/handle_msg.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c

index 630a6ed8a0f5dac91a9693a8a7c7e1acf77bb9da..9f3af150cc968110b54c259343ebb3a9cb0b3aa5 100644 (file)
@@ -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))) {
index 538e0152d7c771ffb0300d83fc1a9f0afedfc966..7ff8a5ea84c8534e5fe3fac55a021180c7f9e939 100644 (file)
@@ -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);