]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7951 #resolve #comment completely clean up mod_rayo if it fails to load
authorChris Rienzo <chris.rienzo@citrix.com>
Wed, 12 Aug 2015 22:00:19 +0000 (18:00 -0400)
committerChris Rienzo <chris.rienzo@citrix.com>
Wed, 12 Aug 2015 22:00:19 +0000 (18:00 -0400)
src/mod/event_handlers/mod_rayo/mod_rayo.c
src/mod/event_handlers/mod_rayo/rayo_cpa_component.c
src/mod/event_handlers/mod_rayo/rayo_cpa_detector.c
src/mod/event_handlers/mod_rayo/rayo_input_component.c
src/mod/event_handlers/mod_rayo/rayo_output_component.c

index 28d7ae1013ea2e952c15b177e67e2285425d4ec5..ef6b0b7a6570895942f983ec1754249fe58b6a7e 100644 (file)
@@ -885,9 +885,15 @@ static void start_deliver_message_thread(switch_memory_pool_t *pool)
 static void stop_all_threads(void)
 {
        globals.shutdown = 1;
-       switch_queue_interrupt_all(globals.msg_queue);
-       switch_queue_interrupt_all(globals.offer_queue);
-       switch_thread_rwlock_wrlock(globals.shutdown_rwlock);
+       if (globals.msg_queue) {
+               switch_queue_interrupt_all(globals.msg_queue);
+       }
+       if (globals.offer_queue) {
+               switch_queue_interrupt_all(globals.offer_queue);
+       }
+       if (globals.shutdown_rwlock) {
+               switch_thread_rwlock_wrlock(globals.shutdown_rwlock);
+       }
 }
 
 /**
@@ -5054,6 +5060,79 @@ static switch_status_t list_input(const char *line, const char *cursor, switch_c
        return list_actors(line, cursor, matches, is_input_actor);
 }
 
+/**
+ * Shutdown module on load failure or shutdown from FreeSWITCH core
+ */
+static switch_status_t do_shutdown(void)
+{
+       switch_console_del_complete_func("::rayo::list_all");
+       switch_console_del_complete_func("::rayo::list_internal");
+       switch_console_del_complete_func("::rayo::list_external");
+       switch_console_del_complete_func("::rayo::list_server");
+       switch_console_del_complete_func("::rayo::list_call");
+       switch_console_del_complete_func("::rayo::list_component");
+       switch_console_del_complete_func("::rayo::list_record");
+       switch_console_del_complete_func("::rayo::list_output");
+       switch_console_del_complete_func("::rayo::list_input");
+       switch_console_set_complete("del rayo");
+
+       /* stop XMPP streams */
+       if (globals.xmpp_context) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for XMPP threads to stop\n");
+               xmpp_stream_context_destroy(globals.xmpp_context);
+       }
+
+       /* stop threads */
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for message and offer timeout threads to stop\n");
+       stop_all_threads();
+
+       if (globals.console) {
+               RAYO_RELEASE(globals.console);
+               RAYO_DESTROY(globals.console);
+               globals.console = NULL;
+       }
+
+       if (globals.server) {
+               RAYO_RELEASE(globals.server);
+               RAYO_DESTROY(globals.server);
+               globals.server = NULL;
+       }
+
+       rayo_components_shutdown();
+
+       switch_event_unbind_callback(route_call_event);
+       switch_event_unbind_callback(on_call_end_event);
+       switch_event_unbind_callback(route_mixer_event);
+
+       if (globals.command_handlers) {
+               switch_core_hash_destroy(&globals.command_handlers);
+       }
+       if (globals.event_handlers) {
+               switch_core_hash_destroy(&globals.event_handlers);
+       }
+       if (globals.clients_roster) {
+               switch_core_hash_destroy(&globals.clients_roster);
+       }
+       if (globals.actors) {
+               switch_core_hash_destroy(&globals.actors);
+       }
+       if (globals.destroy_actors) {
+               switch_core_hash_destroy(&globals.destroy_actors);
+       }
+       if (globals.actors_by_id) {
+               switch_core_hash_destroy(&globals.actors_by_id);
+       }
+       if (globals.dial_gateways) {
+               switch_core_hash_destroy(&globals.dial_gateways);
+       }
+       if (globals.cmd_aliases) {
+               switch_core_hash_destroy(&globals.cmd_aliases);
+       }
+
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
 /**
  * Load module
  */
@@ -5116,12 +5195,19 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
 
        /* set up rayo components */
        if (rayo_components_load(module_interface, pool, RAYO_CONFIG_FILE) != SWITCH_STATUS_SUCCESS) {
-               return SWITCH_STATUS_TERM;
+               goto error;
        }
 
        /* configure / open sockets */
        if(do_config(globals.pool, RAYO_CONFIG_FILE) != SWITCH_STATUS_SUCCESS) {
-               return SWITCH_STATUS_TERM;
+               goto error;
+       }
+
+       /* create admin client */
+       globals.console = rayo_console_client_create();
+       if (!globals.console) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to create console client entity!\n");
+               goto error;
        }
 
        /* start up message threads */
@@ -5133,13 +5219,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
        }
        start_offer_timeout_thread(pool);
 
-       /* create admin client */
-       globals.console = rayo_console_client_create();
-       if (!globals.console) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to create console client entity!\n");
-               return SWITCH_STATUS_TERM;
-       }
-
        switch_console_set_complete("add rayo status");
        switch_console_set_complete("add rayo msg ::rayo::list_all");
        switch_console_set_complete("add rayo msg ::rayo::list_all chat");
@@ -5159,6 +5238,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
        switch_console_add_complete_func("::rayo::list_input", list_input);
 
        return SWITCH_STATUS_SUCCESS;
+
+ error:
+       do_shutdown();
+       return SWITCH_STATUS_TERM;
+
 }
 
 /**
@@ -5166,56 +5250,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
  */
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_rayo_shutdown)
 {
-       switch_console_del_complete_func("::rayo::list_all");
-       switch_console_del_complete_func("::rayo::list_internal");
-       switch_console_del_complete_func("::rayo::list_external");
-       switch_console_del_complete_func("::rayo::list_server");
-       switch_console_del_complete_func("::rayo::list_call");
-       switch_console_del_complete_func("::rayo::list_component");
-       switch_console_del_complete_func("::rayo::list_record");
-       switch_console_del_complete_func("::rayo::list_output");
-       switch_console_del_complete_func("::rayo::list_input");
-       switch_console_set_complete("del rayo");
-
-       /* stop XMPP streams */
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for XMPP threads to stop\n");
-       xmpp_stream_context_destroy(globals.xmpp_context);
-
-       /* stop threads */
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Waiting for message and offer timeout threads to stop\n");
-       stop_all_threads();
-
-       if (globals.console) {
-               RAYO_RELEASE(globals.console);
-               RAYO_DESTROY(globals.console);
-               globals.console = NULL;
-       }
-
-       if (globals.server) {
-               RAYO_RELEASE(globals.server);
-               RAYO_DESTROY(globals.server);
-               globals.server = NULL;
-       }
-
-       rayo_components_shutdown();
-
-       /* cleanup module */
-       switch_event_unbind_callback(route_call_event);
-       switch_event_unbind_callback(on_call_end_event);
-       switch_event_unbind_callback(route_mixer_event);
-
-       switch_core_hash_destroy(&globals.command_handlers);
-       switch_core_hash_destroy(&globals.event_handlers);
-       switch_core_hash_destroy(&globals.clients_roster);
-       switch_core_hash_destroy(&globals.actors);
-       switch_core_hash_destroy(&globals.destroy_actors);
-       switch_core_hash_destroy(&globals.actors_by_id);
-       switch_core_hash_destroy(&globals.dial_gateways);
-       switch_core_hash_destroy(&globals.cmd_aliases);
-
+       switch_status_t result = do_shutdown();
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Module shutdown\n");
-
-       return SWITCH_STATUS_SUCCESS;
+       return result;
 }
 
 /**
index fb271bd03e8ecefc0cf252f255001afd406e6cea..81a708b1a9dc0aae54c6e388c6d3da907ebda4ae 100644 (file)
@@ -390,7 +390,9 @@ void rayo_cpa_component_shutdown(void)
        switch_event_unbind_callback(on_rayo_cpa_detector_event);
        switch_event_unbind_callback(on_channel_hangup_complete_event);
        rayo_cpa_detector_shutdown();
-       switch_core_hash_destroy(&globals.subscribers);
+       if (globals.subscribers) {
+               switch_core_hash_destroy(&globals.subscribers);
+       }
 }
 
 /* For Emacs:
index 702d20bec2e8c6de914c7446f6460c5855062bf2..0905f6e547218cf826f81dd06f100aaf941cc4a0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2014, Grasshopper
+ * Copyright (C) 2014-2015, Grasshopper
  *
  * Version: MPL 1.1
  *
@@ -452,7 +452,9 @@ void rayo_cpa_detector_shutdown(void)
 {
        switch_console_set_complete("del rayo_cpa");
        switch_console_del_complete_func("::rayo_cpa::list_signal_types");
-       switch_core_hash_destroy(&globals.detectors);
+       if (globals.detectors) {
+               switch_core_hash_destroy(&globals.detectors);
+       }
        switch_event_unbind_callback(rayo_cpa_detector_event);
 }
 
index 53dcbf3540f68e973f66e585573d319394bf97cf..77855463d6e19267a31cfddef55c31ac08956813 100644 (file)
@@ -1066,7 +1066,9 @@ switch_status_t rayo_input_component_shutdown(void)
 {
        switch_event_unbind_callback(on_detected_speech_event);
 
-       srgs_parser_destroy(globals.parser);
+       if (globals.parser) {
+               srgs_parser_destroy(globals.parser);
+       }
        srgs_destroy();
        nlsml_destroy();
 
index 267f06225c41e737f287e235be39ad68acae2bf0..932b3aed47c911c294bbedf0adc39d8fb7a14d45 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * mod_rayo for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2013-2014, Grasshopper
+ * Copyright (C) 2013-2015, Grasshopper
  *
  * Version: MPL 1.1
  *
@@ -1259,7 +1259,9 @@ switch_status_t rayo_output_component_load(switch_loadable_module_interface_t **
  */
 switch_status_t rayo_output_component_shutdown(void)
 {
-       switch_core_hash_destroy(&fileman_globals.hash);
+       if (fileman_globals.hash) {
+               switch_core_hash_destroy(&fileman_globals.hash);
+       }
 
        return SWITCH_STATUS_SUCCESS;
 }