From 747beb1ed159f89a3b58742e4257740b3d6d6bba Mon Sep 17 00:00:00 2001 From: George Joseph Date: Tue, 11 Apr 2017 10:07:39 -0600 Subject: modules: change module LOAD_FAILUREs to LOAD_DECLINES In all non-pbx modules, AST_MODULE_LOAD_FAILURE has been changed to AST_MODULE_LOAD_DECLINE. This prevents asterisk from exiting if a module can't be loaded. If the user wishes to retain the FAILURE behavior for a specific module, they can use the "require" or "preload-require" keyword in modules.conf. A new API was added to logger: ast_is_logger_initialized(). This allows asterisk.c/check_init() to print to the error log once the logger subsystem is ready instead of just to stdout. If something does fail before the logger is initialized, we now print to stderr instead of stdout. Change-Id: I5f4b50623d9b5a6cb7c5624a8c5c1274c13b2b25 --- rest-api-templates/res_ari_resource.c.mustache | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'rest-api-templates') diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache index c28a62cd9..ca4e2f192 100644 --- a/rest-api-templates/res_ari_resource.c.mustache +++ b/rest-api-templates/res_ari_resource.c.mustache @@ -256,6 +256,19 @@ fin: __attribute__((unused)) {{> rest_handler}} {{/root_path}} +static int unload_module(void) +{ + ast_ari_remove_handler(&{{root_full_name}}); +{{#apis}} +{{#has_websocket}} + ao2_cleanup({{full_name}}.ws_server); + {{full_name}}.ws_server = NULL; +{{/has_websocket}} +{{/apis}} + stasis_app_unref(); + return 0; +} + static int load_module(void) { int res = 0; @@ -270,14 +283,14 @@ static int load_module(void) {{full_name}}.ws_server = ast_websocket_server_create(); if (!{{full_name}}.ws_server) { - return AST_MODULE_LOAD_FAILURE; + return AST_MODULE_LOAD_DECLINE; } protocol = ast_websocket_sub_protocol_alloc("{{websocket_protocol}}"); if (!protocol) { ao2_ref({{full_name}}.ws_server, -1); {{full_name}}.ws_server = NULL; - return AST_MODULE_LOAD_FAILURE; + return AST_MODULE_LOAD_DECLINE; } protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb; protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb; @@ -289,21 +302,12 @@ static int load_module(void) {{/apis}} stasis_app_ref(); res |= ast_ari_add_handler(&{{root_full_name}}); - return res; -} + if (res) { + unload_module(); + return AST_MODULE_LOAD_DECLINE; + } -static int unload_module(void) -{ - ast_ari_remove_handler(&{{root_full_name}}); -{{#apis}} -{{#has_websocket}} - ao2_cleanup({{full_name}}.ws_server); - {{full_name}}.ws_server = NULL; - ast_ari_websocket_events_event_websocket_dtor(); -{{/has_websocket}} -{{/apis}} - stasis_app_unref(); - return 0; + return AST_MODULE_LOAD_SUCCESS; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - {{{description}}}", -- cgit v1.2.3