]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
modules: change module LOAD_FAILUREs to LOAD_DECLINES
authorGeorge Joseph <gjoseph@digium.com>
Tue, 11 Apr 2017 16:07:39 +0000 (10:07 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 12 Apr 2017 21:47:56 +0000 (15:47 -0600)
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

89 files changed:
addons/cdr_mysql.c
addons/chan_mobile.c
apps/app_adsiprog.c
apps/app_agent_pool.c
apps/app_alarmreceiver.c
apps/app_authenticate.c
apps/app_cdr.c
apps/app_confbridge.c
apps/app_dahdiras.c
apps/app_forkcdr.c
apps/app_queue.c
apps/app_voicemail.c
apps/app_zapateller.c
cdr/cdr_custom.c
cel/cel_custom.c
cel/cel_odbc.c
channels/chan_alsa.c
channels/chan_dahdi.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_motif.c
channels/chan_nbs.c
channels/chan_oss.c
channels/chan_phone.c
channels/chan_pjsip.c
channels/chan_sip.c
channels/chan_skinny.c
channels/chan_unistim.c
codecs/codec_a_mu.c
codecs/codec_adpcm.c
codecs/codec_alaw.c
codecs/codec_g722.c
codecs/codec_g726.c
codecs/codec_gsm.c
codecs/codec_ilbc.c
codecs/codec_lpc10.c
codecs/codec_resample.c
codecs/codec_ulaw.c
formats/format_g723.c
formats/format_g726.c
formats/format_g729.c
formats/format_gsm.c
formats/format_h263.c
formats/format_h264.c
formats/format_ilbc.c
formats/format_jpeg.c
formats/format_ogg_vorbis.c
formats/format_pcm.c
formats/format_sln.c
formats/format_vox.c
formats/format_wav.c
formats/format_wav_gsm.c
funcs/func_cdr.c
funcs/func_holdintercept.c
funcs/func_talkdetect.c
include/asterisk/logger.h
main/asterisk.c
main/loader.c
main/logger.c
res/res_ari.c
res/res_ari_events.c
res/res_ari_model.c
res/res_calendar.c
res/res_chan_stats.c
res/res_config_sqlite.c
res/res_config_sqlite3.c
res/res_endpoint_stats.c
res/res_hep_rtcp.c
res/res_http_websocket.c
res/res_limit.c
res/res_pjsip/config_transport.c
res/res_pjsip_nat.c
res/res_pjsip_one_touch_record_info.c
res/res_pjsip_outbound_publish.c
res/res_pjsip_outbound_registration.c
res/res_pjsip_pubsub.c
res/res_pjsip_sdp_rtp.c
res/res_pjsip_send_to_voicemail.c
res/res_pjsip_t38.c
res/res_smdi.c
res/res_stasis.c
res/res_stasis_device_state.c
res/res_stasis_playback.c
res/res_stasis_recording.c
res/res_stasis_test.c
res/res_statsd.c
rest-api-templates/res_ari_resource.c.mustache
tests/test_bucket.c
tests/test_channel_feature_hooks.c

index 896bad603ba9ea1f73f9bc9c6b694969f28d0d11..26e8389a1f44564668eb552d5b947c6a0be55b16 100644 (file)
@@ -353,9 +353,20 @@ db_reconnect:
        return 0;
 }
 
+static void free_strings(void)
+{
+       struct unload_string *us;
+
+       AST_LIST_LOCK(&unload_strings);
+       while ((us = AST_LIST_REMOVE_HEAD(&unload_strings, entry))) {
+               ast_free(us->str);
+               ast_free(us);
+       }
+       AST_LIST_UNLOCK(&unload_strings);
+}
+
 static int my_unload_module(int reload)
 { 
-       struct unload_string *us;
        struct column *entry;
 
        ast_cli_unregister_multiple(cdr_mysql_status_cli, sizeof(cdr_mysql_status_cli) / sizeof(struct ast_cli_entry));
@@ -366,12 +377,7 @@ static int my_unload_module(int reload)
                records = 0;
        }
 
-       AST_LIST_LOCK(&unload_strings);
-       while ((us = AST_LIST_REMOVE_HEAD(&unload_strings, entry))) {
-               ast_free(us->str);
-               ast_free(us);
-       }
-       AST_LIST_UNLOCK(&unload_strings);
+       free_strings();
 
        if (!reload) {
                AST_RWLIST_WRLOCK(&columns);
@@ -507,13 +513,16 @@ static int my_load_module(int reload)
        } else {
                calldate_compat = 0;
        }
+       ast_free(compat);
 
        if (res < 0) {
                if (reload) {
                        AST_RWLIST_UNLOCK(&columns);
                }
                ast_config_destroy(cfg);
-               return AST_MODULE_LOAD_FAILURE;
+               free_strings();
+
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Check for any aliases */
@@ -584,7 +593,9 @@ static int my_load_module(int reload)
                        connected = 0;
                        AST_RWLIST_UNLOCK(&columns);
                        ast_config_destroy(cfg);
-                       return AST_MODULE_LOAD_FAILURE;
+                       free_strings();
+
+                       return AST_MODULE_LOAD_DECLINE;
                }
 
                if (!(result = mysql_store_result(&mysql))) {
@@ -593,7 +604,9 @@ static int my_load_module(int reload)
                        connected = 0;
                        AST_RWLIST_UNLOCK(&columns);
                        ast_config_destroy(cfg);
-                       return AST_MODULE_LOAD_FAILURE;
+                       free_strings();
+
+                       return AST_MODULE_LOAD_DECLINE;
                }
 
                while ((row = mysql_fetch_row(result))) {
@@ -659,7 +672,8 @@ static int my_load_module(int reload)
        AST_RWLIST_UNLOCK(&columns);
        ast_config_destroy(cfg);
        if (res < 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               my_unload_module(0);
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!reload) {
@@ -673,7 +687,12 @@ static int my_load_module(int reload)
                res = ast_cli_register_multiple(cdr_mysql_status_cli, sizeof(cdr_mysql_status_cli) / sizeof(struct ast_cli_entry));
        }
 
-       return res;
+       if (res) {
+               my_unload_module(0);
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int load_module(void)
index 8d13c969fa93339b3d5830bf70606a65fbed811c..ada7e27f2901cc5b93b16fad2f132b8b47c4c316 100644 (file)
@@ -4706,9 +4706,13 @@ static int load_module(void)
        ast_format_cap_append(mbl_tech.capabilities, DEVICE_FRAME_FORMAT, 0);
        /* Check if we have Bluetooth, no point loading otherwise... */
        dev_id = hci_get_route(NULL);
+
        s = hci_open_dev(dev_id);
        if (dev_id < 0 || s < 0) {
                ast_log(LOG_ERROR, "No Bluetooth devices found. Not loading module.\n");
+               ao2_ref(mbl_tech.capabilities, -1);
+               mbl_tech.capabilities = NULL;
+               hci_close_dev(s);
                return AST_MODULE_LOAD_DECLINE;
        }
 
@@ -4716,6 +4720,8 @@ static int load_module(void)
 
        if (mbl_load_config()) {
                ast_log(LOG_ERROR, "Errors reading config file %s. Not loading module.\n", MBL_CONFIG);
+               ao2_ref(mbl_tech.capabilities, -1);
+               mbl_tech.capabilities = NULL;
                return AST_MODULE_LOAD_DECLINE;
        }
 
@@ -4740,10 +4746,9 @@ static int load_module(void)
        return AST_MODULE_LOAD_SUCCESS;
 
 e_cleanup:
-       if (sdp_session)
-               sdp_close(sdp_session);
+       unload_module();
 
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Bluetooth Mobile Device Channel Driver",
index 3f3d11c257f7f69ed031271b2509d36446bce10d..1c9f37bd59624a2429eda72cc31d3f1589b9e824 100644 (file)
@@ -1607,7 +1607,7 @@ static int unload_module(void)
 static int load_module(void)
 {
        if (ast_register_application_xml(app, adsi_exec))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 68bcfdead8c5debcd87079e639a1e9ee908b4696..0ad24c6941c3c8a777ad881da98bae873838592f 100644 (file)
@@ -2655,7 +2655,7 @@ static int load_module(void)
        agents = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX,
                AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, agent_pvt_sort_cmp, agent_pvt_cmp);
        if (!agents) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Init agent holding bridge v_table. */
@@ -2679,8 +2679,9 @@ static int load_module(void)
        res |= ast_register_application_xml(app_agent_request, agent_request_exec);
 
        if (res) {
+               ast_log(LOG_ERROR, "Unable to register application. Not loading module.\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (load_config()) {
index ace4df1dc5f94fba346fa71de9bd57d5b0c42359..5b7a90c22dc877d5858ab404fabebe27c2f7440d 100644 (file)
@@ -977,7 +977,7 @@ static int load_module(void)
 {
        if (load_config(0)) {
                if (ast_register_application_xml(app, alarmreceiver_exec)) {
-                       return AST_MODULE_LOAD_FAILURE;
+                       return AST_MODULE_LOAD_DECLINE;
                }
                return AST_MODULE_LOAD_SUCCESS;
        }
index f47db45346d4b580f0678cd7cbbc44a62e830dd5..30023fcc124ed1d19fa4a79190f47cb03ea9d24d 100644 (file)
@@ -272,7 +272,7 @@ static int unload_module(void)
 static int load_module(void)
 {
        if (ast_register_application_xml(app, auth_exec))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 7862179f339ce55116d79478dfa0da5f2e039a77..196179a246ae4fabc5ddd438bb402b7421bc7b72 100644 (file)
@@ -251,7 +251,7 @@ static int load_module(void)
        int res = 0;
 
        if (!router) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        res |= STASIS_MESSAGE_TYPE_INIT(appcdr_message_type);
@@ -261,7 +261,8 @@ static int load_module(void)
                                         appcdr_callback, NULL);
 
        if (res) {
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index a7fd92a374622b2e4dedd9cc80207dfb1d1c85f8..6986fbe67e6f644ea2ee555cd62447bebc9260d9 100644 (file)
@@ -3935,7 +3935,7 @@ static int load_module(void)
        if (register_channel_tech(conf_record_get_tech())
                || register_channel_tech(conf_announce_get_tech())) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Create a container to hold the conference bridges */
@@ -3943,7 +3943,7 @@ static int load_module(void)
                conference_bridge_hash_cb, conference_bridge_cmp_cb);
        if (!conference_bridges) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Setup manager stasis subscriptions */
@@ -3968,7 +3968,7 @@ static int load_module(void)
        res |= ast_manager_register_xml("ConfbridgeSetSingleVideoSrc", EVENT_FLAG_CALL, action_confbridgesetsinglevideosrc);
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 51921a98ec7d10ccdacb3c32ff3d0ac557c6eb67..9e7ddff84b9a833c815e8e69717a855c69d8c5a8 100644 (file)
@@ -225,7 +225,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       return ((ast_register_application_xml(app, dahdiras_exec)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
+       return ((ast_register_application_xml(app, dahdiras_exec)) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS);
 }
 
 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "DAHDI ISDN Remote Access Server");
index 4ff5cd61034834bff83ef23c69c4079b1048058d..2fd77c6aef9081319147747c1a7416716ea8245a 100644 (file)
@@ -201,7 +201,7 @@ static int load_module(void)
        int res = 0;
 
        if (!router) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        res |= STASIS_MESSAGE_TYPE_INIT(forkcdr_message_type);
@@ -210,7 +210,9 @@ static int load_module(void)
                                         forkcdr_callback, NULL);
 
        if (res) {
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index f5cec1e8559fa6f7a7ba6a592ec5f6f3ecb7bb31..1fa094efeee7293d309fa3586dae35c380f8f630 100644 (file)
@@ -8876,7 +8876,7 @@ static int reload_queue_rules(int reload)
                if (!(new_rl = ast_calloc(1, sizeof(*new_rl)))) {
                        AST_LIST_UNLOCK(&rule_lists);
                        ast_config_destroy(cfg);
-                       return AST_MODULE_LOAD_FAILURE;
+                       return AST_MODULE_LOAD_DECLINE;
                } else {
                        ast_copy_string(new_rl->name, rulecat, sizeof(new_rl->name));
                        AST_LIST_INSERT_TAIL(&rule_lists, new_rl, list);
index 34c4822f021763f095c9ed1b3fc75cf0d8a6b8b5..b0185c1746ea5d528777098f50ccb2c1289186dd 100644 (file)
@@ -14976,7 +14976,7 @@ static int load_module(void)
        umask(my_umask);
 
        if (!(inprocess_container = ao2_container_alloc(573, inprocess_hash_fn, inprocess_cmp_fn))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* compute the location of the voicemail spool directory */
index 27bcf6331d226ad2bf3cd96da5f677c9000ee893..d44a2de175180359706fd1f4dcd076d6dc7cc60e 100644 (file)
@@ -134,7 +134,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       return ((ast_register_application_xml(app, zapateller_exec)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
+       return ((ast_register_application_xml(app, zapateller_exec)) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS);
 }
 
 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Block Telemarketers with Special Information Tone");
index bb63ea0c646b5569805603d50194ed35dc0826a0..9d4abbc83ad5817043cdfcd38f49ba813ca346cf 100644 (file)
@@ -205,7 +205,7 @@ static enum ast_module_load_result load_module(void)
 {
        if (AST_RWLIST_WRLOCK(&sinks)) {
                ast_log(LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        load_config();
@@ -218,7 +218,7 @@ static int reload(void)
 {
        if (AST_RWLIST_WRLOCK(&sinks)) {
                ast_log(LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        free_config();
index f75efdd4be46303af9362ef17f6642b6401dc047..09aef4e9a3c53d5cef380bcc79dbbfd751d903f4 100644 (file)
@@ -193,14 +193,15 @@ static enum ast_module_load_result load_module(void)
 {
        if (AST_RWLIST_WRLOCK(&sinks)) {
                ast_log(LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        load_config();
        AST_RWLIST_UNLOCK(&sinks);
 
        if (ast_cel_backend_register(CUSTOM_BACKEND_NAME, custom_log)) {
-               return AST_MODULE_LOAD_FAILURE;
+               free_config();
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
@@ -209,7 +210,7 @@ static int reload(void)
 {
        if (AST_RWLIST_WRLOCK(&sinks)) {
                ast_log(LOG_ERROR, "Unable to lock sink list.  Load failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        free_config();
index a10aadae95754880cbc98050b12aaac65daec01c..1ea6ea987b865266977a339d5d0159b69dbfac44 100644 (file)
@@ -803,13 +803,14 @@ static int load_module(void)
 
        if (AST_RWLIST_WRLOCK(&odbc_tables)) {
                ast_log(LOG_ERROR, "Unable to lock column list.  Load failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        load_config();
        AST_RWLIST_UNLOCK(&odbc_tables);
        if (ast_cel_backend_register(ODBC_BACKEND_NAME, odbc_log)) {
                ast_log(LOG_ERROR, "Unable to subscribe to CEL events\n");
-               return AST_MODULE_LOAD_FAILURE;
+               free_config();
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
@@ -818,7 +819,7 @@ static int reload(void)
 {
        if (AST_RWLIST_WRLOCK(&odbc_tables)) {
                ast_log(LOG_ERROR, "Unable to lock column list.  Reload failed.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        free_config();
index 5c028c3b317eb2980143471bf4317b0b911375ce..7a6f841881b06d3fb95213a87751f900964b89a8 100644 (file)
@@ -926,6 +926,26 @@ static struct ast_cli_entry cli_alsa[] = {
        AST_CLI_DEFINE(console_mute, "Disable/Enable mic input"),
 };
 
+static int unload_module(void)
+{
+       ast_channel_unregister(&alsa_tech);
+       ast_cli_unregister_multiple(cli_alsa, ARRAY_LEN(cli_alsa));
+
+       if (alsa.icard)
+               snd_pcm_close(alsa.icard);
+       if (alsa.ocard)
+               snd_pcm_close(alsa.ocard);
+       if (alsa.owner)
+               ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
+       if (alsa.owner)
+               return -1;
+
+       ao2_cleanup(alsa_tech.capabilities);
+       alsa_tech.capabilities = NULL;
+
+       return 0;
+}
+
 /*!
  * \brief Load the module
  *
@@ -996,12 +1016,16 @@ static int load_module(void)
        if (soundcard_init() < 0) {
                ast_verb(2, "No sound card detected -- console channel will be unavailable\n");
                ast_verb(2, "Turn off ALSA support by adding 'noload=chan_alsa.so' in /etc/asterisk/modules.conf\n");
+               unload_module();
+
                return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_channel_register(&alsa_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class 'Console'\n");
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_cli_register_multiple(cli_alsa, ARRAY_LEN(cli_alsa));
@@ -1009,26 +1033,6 @@ static int load_module(void)
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       ast_channel_unregister(&alsa_tech);
-       ast_cli_unregister_multiple(cli_alsa, ARRAY_LEN(cli_alsa));
-
-       if (alsa.icard)
-               snd_pcm_close(alsa.icard);
-       if (alsa.ocard)
-               snd_pcm_close(alsa.ocard);
-       if (alsa.owner)
-               ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD);
-       if (alsa.owner)
-               return -1;
-
-       ao2_cleanup(alsa_tech.capabilities);
-       alsa_tech.capabilities = NULL;
-
-       return 0;
-}
-
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "ALSA Console Channel Driver",
        .support_level = AST_MODULE_SUPPORT_EXTENDED,
        .load = load_module,
index 71dbd35f19605f80e54e7b5aa45d6afdec8e38d3..55a9dbaf468146eea890996211be1df0a00e49e4 100644 (file)
@@ -19606,11 +19606,11 @@ static int load_module(void)
 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
 
        if (STASIS_MESSAGE_TYPE_INIT(dahdichannel_type)) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(dahdi_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append(dahdi_tech.capabilities, ast_format_slin, 0);
        ast_format_cap_append(dahdi_tech.capabilities, ast_format_ulaw, 0);
@@ -19618,7 +19618,7 @@ static int load_module(void)
 
        if (dahdi_native_load(&dahdi_tech)) {
                ao2_ref(dahdi_tech.capabilities, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
 #ifdef HAVE_PRI
@@ -19636,7 +19636,7 @@ static int load_module(void)
        if (ast_cc_agent_register(&dahdi_pri_cc_agent_callbacks)
                || ast_cc_monitor_register(&dahdi_pri_cc_monitor_callbacks)) {
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 #endif /* defined(HAVE_PRI_CCSS) */
        if (sig_pri_load(
@@ -19647,7 +19647,7 @@ static int load_module(void)
 #endif /* defined(HAVE_PRI_CCSS) */
                )) {
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 #endif
 #if defined(HAVE_SS7)
@@ -19670,7 +19670,7 @@ static int load_module(void)
        if (ast_channel_register(&dahdi_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class 'DAHDI'\n");
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 #ifdef HAVE_PRI
        ast_cli_register_multiple(dahdi_pri_cli, ARRAY_LEN(dahdi_pri_cli));
index 469a172756d19a584963b01fb9621955339fe0b3..8941634b020e3bcf17987737fb8f683c8f1c007b 100644 (file)
@@ -14878,7 +14878,7 @@ container_fail:
        if (calltoken_ignores) {
                ao2_ref(calltoken_ignores, -1);
        }
-       return AST_MODULE_LOAD_FAILURE;
+       return -1;
 }
 
 
@@ -15083,12 +15083,14 @@ static int load_module(void)
        struct iax2_registry *reg = NULL;
 
        if (!(iax2_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append_by_type(iax2_tech.capabilities, AST_MEDIA_TYPE_UNKNOWN);
 
        if (load_objects()) {
-               return AST_MODULE_LOAD_FAILURE;
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        memset(iaxs, 0, sizeof(iaxs));
@@ -15099,28 +15101,36 @@ static int load_module(void)
 
        if (!(sched = ast_sched_context_create())) {
                ast_log(LOG_ERROR, "Failed to create scheduler thread\n");
-               return AST_MODULE_LOAD_FAILURE;
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_sched_start_thread(sched)) {
                ast_sched_context_destroy(sched);
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
                sched = NULL;
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(io = io_context_create())) {
                ast_log(LOG_ERROR, "Failed to create I/O context\n");
                ast_sched_context_destroy(sched);
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
                sched = NULL;
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(netsock = ast_netsock_list_alloc())) {
                ast_log(LOG_ERROR, "Failed to create netsock list\n");
                io_context_destroy(io);
                ast_sched_context_destroy(sched);
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
                sched = NULL;
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_netsock_init(netsock);
 
@@ -15129,8 +15139,10 @@ static int load_module(void)
                ast_log(LOG_ERROR, "Could not allocate outsock list.\n");
                io_context_destroy(io);
                ast_sched_context_destroy(sched);
+               ao2_ref(iax2_tech.capabilities, -1);
+               iax2_tech.capabilities = NULL;
                sched = NULL;
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_netsock_init(outsock);
 
@@ -15149,6 +15161,7 @@ static int load_module(void)
                        ast_timer_close(timer);
                        timer = NULL;
                }
+               __unload_module();
                return AST_MODULE_LOAD_DECLINE;
        }
 
@@ -15174,7 +15187,7 @@ static int load_module(void)
        if (ast_channel_register(&iax2_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class %s\n", "IAX2");
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_register_switch(&iax2_switch)) {
@@ -15184,7 +15197,7 @@ static int load_module(void)
        if (start_network_thread()) {
                ast_log(LOG_ERROR, "Unable to start network thread\n");
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        } else {
                ast_verb(2, "IAX Ready and Listening\n");
        }
index 6df5d3fd0fc7790a12f19e11e9b8ac34b62728ab..33f4f46352e6976dabcd0f0a4a6b338232bcb463 100644 (file)
@@ -4862,11 +4862,11 @@ static int reload_config(int reload)
 static int load_module(void)
 {
        if (!(global_capability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        if (!(mgcp_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
                ao2_ref(global_capability, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append(global_capability, ast_format_ulaw, 0);
        ast_format_cap_append(mgcp_tech.capabilities, ast_format_ulaw, 0);
@@ -4875,7 +4875,7 @@ static int load_module(void)
                ast_log(LOG_WARNING, "Unable to create schedule context\n");
                ao2_ref(global_capability, -1);
                ao2_ref(mgcp_tech.capabilities, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(io = io_context_create())) {
@@ -4883,7 +4883,7 @@ static int load_module(void)
                ast_sched_context_destroy(sched);
                ao2_ref(global_capability, -1);
                ao2_ref(mgcp_tech.capabilities, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (reload_config(0)) {
@@ -4899,7 +4899,7 @@ static int load_module(void)
                ast_sched_context_destroy(sched);
                ao2_ref(global_capability, -1);
                ao2_ref(mgcp_tech.capabilities, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_rtp_glue_register(&mgcp_rtp_glue);
index 0c710923f680f25a8a2cc85b8b62249be64ed482..1f449140ff79e9a61dcd1e5013c38ae5ce611a85 100644 (file)
@@ -2790,7 +2790,7 @@ end:
        ao2_cleanup(jingle_tech.capabilities);
        jingle_tech.capabilities = NULL;
 
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 /*! \brief Reload module */
index d50defeaf91b4c0a403d30cccc83d4b9242c2b09..b4a0532f1c8298dbefb203d31de0708b26c1f004 100644 (file)
@@ -259,12 +259,14 @@ static int unload_module(void)
 static int load_module(void)
 {
        if (!(nbs_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append(nbs_tech.capabilities, ast_format_slin, 0);
        /* Make sure we can register our channel type */
        if (ast_channel_register(&nbs_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
+               ao2_ref(nbs_tech.capabilities, -1);
+               nbs_tech.capabilities = NULL;
                return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
index 84a1391dad7ca886d9b3959edd3ae0df7e7fe059..87711078cfe5dee1a5b665a69fef8ee4c4e3a1f0 100644 (file)
@@ -1437,6 +1437,31 @@ error:
 #endif
 }
 
+static int unload_module(void)
+{
+       struct chan_oss_pvt *o, *next;
+
+       ast_channel_unregister(&oss_tech);
+       ast_cli_unregister_multiple(cli_oss, ARRAY_LEN(cli_oss));
+
+       o = oss_default.next;
+       while (o) {
+               close(o->sounddev);
+               if (o->owner)
+                       ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
+               if (o->owner)
+                       return -1;
+               next = o->next;
+               ast_free(o->name);
+               ast_free(o);
+               o = next;
+       }
+       ao2_cleanup(oss_tech.capabilities);
+       oss_tech.capabilities = NULL;
+
+       return 0;
+}
+
 /*!
  * \brief Load the module
  *
@@ -1474,12 +1499,12 @@ static int load_module(void)
        if (find_desc(oss_active) == NULL) {
                ast_log(LOG_NOTICE, "Device %s not found\n", oss_active);
                /* XXX we could default to 'dsp' perhaps ? */
-               /* XXX should cleanup allocated memory etc. */
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(oss_tech.capabilities = ast_format_cap_alloc(0))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append(oss_tech.capabilities, ast_format_slin, 0);
 
@@ -1496,31 +1521,5 @@ static int load_module(void)
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-
-static int unload_module(void)
-{
-       struct chan_oss_pvt *o, *next;
-
-       ast_channel_unregister(&oss_tech);
-       ast_cli_unregister_multiple(cli_oss, ARRAY_LEN(cli_oss));
-
-       o = oss_default.next;
-       while (o) {
-               close(o->sounddev);
-               if (o->owner)
-                       ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
-               if (o->owner)
-                       return -1;
-               next = o->next;
-               ast_free(o->name);
-               ast_free(o);
-               o = next;
-       }
-       ao2_cleanup(oss_tech.capabilities);
-       oss_tech.capabilities = NULL;
-
-       return 0;
-}
-
 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "OSS Console Channel Driver");
 
index b7f694f815b6a8dda99020462dbd5db8db2463d4..94116e79abdc0b38c4fa37bfb52f7ee18dc8f39b 100644 (file)
@@ -1418,7 +1418,7 @@ static int load_module(void)
        if (ast_mutex_lock(&iflock)) {
                /* It's a little silly to lock it, but we mind as well just to be sure */
                ast_log(LOG_ERROR, "Unable to lock interface list???\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        v = ast_variable_browse(cfg, "interfaces");
        while(v) {
@@ -1434,7 +1434,7 @@ static int load_module(void)
                                        ast_config_destroy(cfg);
                                        ast_mutex_unlock(&iflock);
                                        __unload_module();
-                                       return AST_MODULE_LOAD_FAILURE;
+                                       return AST_MODULE_LOAD_DECLINE;
                                }
                } else if (!strcasecmp(v->name, "silencesupression")) {
                        silencesupression = ast_true(v->value);
@@ -1510,7 +1510,7 @@ static int load_module(void)
                ast_log(LOG_ERROR, "Unable to register channel class 'Phone'\n");
                ast_config_destroy(cfg);
                __unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_config_destroy(cfg);
        /* And start the monitor for the first time */
index e51852346e1ade5a83138af2ca370ac7de608f8a..e8e366651d9fe0321c4de0c54e3b19fe06c85f00 100644 (file)
@@ -2751,7 +2751,7 @@ end:
        ast_channel_unregister(&chan_pjsip_tech);
        ast_rtp_glue_unregister(&chan_pjsip_rtp_glue);
 
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 /*! \brief Unload the PJSIP channel from Asterisk */
index 052fa9e9c4686789993a987bfa48a29a1f6f090a..a646e730a394b3fe1f1b9127de861f3122bf71c4 100644 (file)
@@ -35305,17 +35305,17 @@ static int load_module(void)
 
        if (STASIS_MESSAGE_TYPE_INIT(session_timeout_type)) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(sip_tech.capabilities = ast_format_cap_alloc(0))) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_sip_api_provider_register(&chan_sip_api_provider)) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* the fact that ao2_containers can't resize automatically is a major worry! */
@@ -35330,12 +35330,12 @@ static int load_module(void)
                || !threadt) {
                ast_log(LOG_ERROR, "Unable to create primary SIP container(s)\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(sip_cfg.caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append_by_type(sip_tech.capabilities, AST_MEDIA_TYPE_AUDIO);
 
@@ -35346,13 +35346,13 @@ static int load_module(void)
        if (!(sched = ast_sched_context_create())) {
                ast_log(LOG_ERROR, "Unable to create scheduler context\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(io = io_context_create())) {
                ast_log(LOG_ERROR, "Unable to create I/O context\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        sip_reloadreason = CHANNEL_MODULE_LOAD;
@@ -35367,7 +35367,7 @@ static int load_module(void)
        if (!(bogus_peer = temp_peer("(bogus_peer)"))) {
                ast_log(LOG_ERROR, "Unable to create bogus_peer for authentication\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        /* Make sure the auth will always fail. */
        ast_string_field_set(bogus_peer, md5secret, BOGUS_PEER_MD5SECRET);
@@ -35384,14 +35384,14 @@ static int load_module(void)
 
        if (ast_msg_tech_register(&sip_msg_tech)) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Make sure we can register our sip channel type */
        if (ast_channel_register(&sip_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
 #ifdef TEST_FRAMEWORK
index 96a206c375ed39249004d6c766c241b0957a8773..a654d0f6dbfe7bf7606802b694784a9fbae9df79 100644 (file)
@@ -8700,7 +8700,7 @@ static int load_module(void)
                ao2_ref(skinny_tech.capabilities, -1);
                ao2_ref(default_cap, -1);
                ast_log(LOG_WARNING, "Unable to create schedule context\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Make sure we can register our skinny channel type */
@@ -8708,7 +8708,7 @@ static int load_module(void)
                ao2_ref(default_cap, -1);
                ao2_ref(skinny_tech.capabilities, -1);
                ast_log(LOG_ERROR, "Unable to register channel class 'Skinny'\n");
-               return -1;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_rtp_glue_register(&skinny_rtp_glue);
@@ -8725,7 +8725,7 @@ static int load_module(void)
                ast_channel_unregister(&skinny_tech);
                ao2_ref(default_cap, -1);
                ao2_ref(skinny_tech.capabilities, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index af0f2c68883782c0cdcd788fd3cea72e63770c53..84a6383bda3d69c65e831b1eb055ad2a2cd6032c 100644 (file)
@@ -7128,7 +7128,7 @@ buff_failed:
        global_cap = NULL;
        ao2_cleanup(unistim_tech.capabilities);
        unistim_tech.capabilities = NULL;
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 static int unload_module(void)
index a831abfcfe4aa9808e42f273f23a50a7882dca76..ef41a0a4a15c14ebd4a8538608bd35ea8a7ea988 100644 (file)
@@ -143,7 +143,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index fa5d8769cb5123a6db0ba77c7d5d429577edaa0d..7c9c2c9a2c22ee3e778f1d91c61f77228114aa17 100644 (file)
@@ -348,7 +348,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 515835dd7f458933de022b3e573fca8144e20f7e..a4cb80e7f35eef2174b29a76ea57883f1d25e4d3 100644 (file)
@@ -132,7 +132,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index d368c38af19ce928b1f4a38e18f59989200f01a0..e5d9f51a5a9c6c81095f55570d0f083919749fae 100644 (file)
@@ -243,7 +243,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }       
 
        return AST_MODULE_LOAD_SUCCESS;
index 8b44cbbd941d37a4ef8e212f9cf736d573303805..e60aeb90144ea98752b8380ef921d941b8555525 100644 (file)
@@ -892,7 +892,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }       
 
        return AST_MODULE_LOAD_SUCCESS;
index f80c955a6b437cbdb9cd91b8f9d41f1e0e32ed56..fc360d08f9c16c63de108a4553cd1d562b26f281 100644 (file)
@@ -241,7 +241,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index fc713beb776eed622a152dec558eeb8bf1bc1b33..bf6a092402ba11fc92c7e9a2edc7a8efc6813a13 100644 (file)
@@ -269,7 +269,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index e6dcf8c994f4f7fefb3330b7955f9f1a8fbd611c..d632c12eda5f92d5c11f6102ec9918556e666884 100644 (file)
@@ -274,7 +274,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 1c73bf3c8edafaad1abb0da795afb0195198c523..b9269d166fea231f891d1d3b97335f55c89f20e8 100644 (file)
@@ -155,7 +155,7 @@ static int load_module(void)
 
        trans_size = ARRAY_LEN(codec_list) * (ARRAY_LEN(codec_list) - 1);
        if (!(translators = ast_calloc(1, sizeof(struct ast_translator) * trans_size))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        for (x = 0; x < ARRAY_LEN(codec_list); x++) {
@@ -182,7 +182,7 @@ static int load_module(void)
        ast_unregister_translator won't fail.*/
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index ca2f411f93b7598faac3daa303cb5187907b2ede..3075d0cc43de8941593ea93fb40c97349bd5a89d 100644 (file)
@@ -183,7 +183,7 @@ static int load_module(void)
 
        if (res) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 777cd746b9e213766e42ddda2de01feddb448a3d..9a40081ecf93725c921574b454e6b03705ba7538 100644 (file)
@@ -144,7 +144,7 @@ static int load_module(void)
        g723_1_f.format = ast_format_g723;
 
        if (ast_format_def_register(&g723_1_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 684275c2b4365da08e1b22141167a88e4d0113d8..22ed41d19dcf57553f2a757e210e8d9411426fc0 100644 (file)
@@ -223,29 +223,30 @@ static struct ast_format_def f[] = {
        {       .desc_size = 0 }        /* terminator */
 };
 
-static int load_module(void)
+static int unload_module(void)
 {
        int i;
 
        for (i = 0; f[i].desc_size ; i++) {
-               f[i].format = ast_format_g726;
-               if (ast_format_def_register(&f[i])) {   /* errors are fatal */
-                       ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
-                       return AST_MODULE_LOAD_FAILURE;
-               }
+               if (ast_format_def_unregister(f[i].name))
+                       ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
        }
-       return AST_MODULE_LOAD_SUCCESS;
+       return(0);
 }
 
-static int unload_module(void)
+static int load_module(void)
 {
        int i;
 
        for (i = 0; f[i].desc_size ; i++) {
-               if (ast_format_def_unregister(f[i].name))
-                       ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
+               f[i].format = ast_format_g726;
+               if (ast_format_def_register(&f[i])) {   /* errors are fatal */
+                       ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
+                       unload_module();
+                       return AST_MODULE_LOAD_DECLINE;
+               }
        }
-       return(0);
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Raw G.726 (16/24/32/40kbps) data",
index 69e6a2563b45463092501c7d919d8944f9a5ce3e..f9de0ec3e3f0b85b46557099bd9c9b8b42fa6d9b 100644 (file)
@@ -140,7 +140,7 @@ static int load_module(void)
 {
        g729_f.format = ast_format_g729;
        if (ast_format_def_register(&g729_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index bf82dd5c636e27fb3c62c8bac4638ede05b50ebf..c8247486f68a53ff794426b5ebb3fc5d45798422 100644 (file)
@@ -185,7 +185,7 @@ static int load_module(void)
 {
        gsm_f.format = ast_format_gsm;
        if (ast_format_def_register(&gsm_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index f02d030772bcd5d5b0fedcfd05d5c2aa364a978b..86abed5fb34473cfc06619b47dfca8ecb30dcfb3 100644 (file)
@@ -172,7 +172,7 @@ static int load_module(void)
 {
        h263_f.format = ast_format_h263;
        if (ast_format_def_register(&h263_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 633309138421f502cad0f2d04fb76de94f341458..3e8283025fc2c5d31682860218f4d8e520f08291 100644 (file)
@@ -165,7 +165,7 @@ static int load_module(void)
 {
        h264_f.format = ast_format_h264;
        if (ast_format_def_register(&h264_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index e07eedba0e25058608f91c9d6113af03daab130b..3cfa8e64939da90ad4c92661854dd406e873a13e 100644 (file)
@@ -137,7 +137,7 @@ static int load_module(void)
 {
        ilbc_f.format = ast_format_ilbc;
        if (ast_format_def_register(&ilbc_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index ed21f88f848d4a897dde9a32742a1555d81be467..fda157626566715d13f513629d001a187a00796d 100644 (file)
@@ -98,7 +98,7 @@ static int load_module(void)
 {
        jpeg_format.format = ast_format_jpeg;
        if (ast_image_register(&jpeg_format))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 0daf64cba9f637ddaf60e3726f111d628e840f7d..7414ea71912fd7ec5be28516040fa6df22571a16 100644 (file)
@@ -425,7 +425,7 @@ static int load_module(void)
 {
        vorbis_f.format = ast_format_slin;
        if (ast_format_def_register(&vorbis_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 6361cd00f400d67bf3dc9afecec2ee47f8fd344a..a493f511665441be4587a6f27b264e10ebf0f4fe 100644 (file)
@@ -502,6 +502,14 @@ static struct ast_format_def au_f = {
        .buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET,     /* this many shorts */
 };
 
+static int unload_module(void)
+{
+       return ast_format_def_unregister(pcm_f.name)
+               || ast_format_def_unregister(alaw_f.name)
+               || ast_format_def_unregister(au_f.name)
+               || ast_format_def_unregister(g722_f.name);
+}
+
 static int load_module(void)
 {
        int i;
@@ -519,19 +527,13 @@ static int load_module(void)
        if ( ast_format_def_register(&pcm_f)
                || ast_format_def_register(&alaw_f)
                || ast_format_def_register(&au_f)
-               || ast_format_def_register(&g722_f) )
-               return AST_MODULE_LOAD_FAILURE;
+               || ast_format_def_register(&g722_f) ) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       return ast_format_def_unregister(pcm_f.name)
-               || ast_format_def_unregister(alaw_f.name)
-               || ast_format_def_unregister(au_f.name)
-               || ast_format_def_unregister(g722_f.name);
-}
-
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Raw/Sun uLaw/ALaw 8KHz (PCM,PCMA,AU), G.722 16Khz",
        .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
index 68aa74d475d07a9c970fdb64dfdd8e1b8574631a..99f70fcb4adc88a2ee79e26f7c6174995ccb893d 100644 (file)
@@ -237,6 +237,19 @@ static struct ast_format_def *slin_list[] = {
        &slin192_f,
 };
 
+static int unload_module(void)
+{
+       int res = 0;
+       int i = 0;
+
+       for (i = 0; i < ARRAY_LEN(slin_list); i++) {
+               if (ast_format_def_unregister(slin_list[i]->name)) {
+                       res = -1;
+               }
+       }
+       return res;
+}
+
 static int load_module(void)
 {
        int i;
@@ -253,26 +266,14 @@ static int load_module(void)
 
        for (i = 0; i < ARRAY_LEN(slin_list); i++) {
                if (ast_format_def_register(slin_list[i])) {
-                       return AST_MODULE_LOAD_FAILURE;
+                       unload_module();
+                       return AST_MODULE_LOAD_DECLINE;
                }
        }
 
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       int res = 0;
-       int i = 0;
-
-       for (i = 0; i < ARRAY_LEN(slin_list); i++) {
-               if (ast_format_def_unregister(slin_list[i]->name)) {
-                       res |= AST_MODULE_LOAD_FAILURE;
-               }
-       }
-       return res;
-}
-
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Raw Signed Linear Audio support (SLN) 8khz-192khz",
        .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
index 5107ab9183fb5f1191efe0fa522aa805b10497ba..582b94fddca92267af06ce5e88754d750e30446b 100644 (file)
@@ -139,7 +139,7 @@ static int load_module(void)
 {
        vox_f.format = ast_format_adpcm;
        if (ast_format_def_register(&vox_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 688c3e7e410b6fb525e01915cdcb8507310675ac..06ed941b3fc85753f7b23a0128e192f153ae045b 100644 (file)
@@ -538,22 +538,24 @@ static struct ast_format_def wav_f = {
        .desc_size = sizeof(struct wav_desc),
 };
 
+static int unload_module(void)
+{
+       return ast_format_def_unregister(wav_f.name)
+               || ast_format_def_unregister(wav16_f.name);
+}
+
 static int load_module(void)
 {
        wav_f.format = ast_format_slin;
        wav16_f.format = ast_format_slin16;
        if (ast_format_def_register(&wav_f)
-               || ast_format_def_register(&wav16_f))
-               return AST_MODULE_LOAD_FAILURE;
+               || ast_format_def_register(&wav16_f)) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       return ast_format_def_unregister(wav_f.name)
-               || ast_format_def_unregister(wav16_f.name);
-}
-
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Microsoft WAV/WAV16 format (8kHz/16kHz Signed Linear)",
        .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
index d5661fbf68cd05f7396dcafb23249c0924e42bb4..240ba3bd258de7c9549919ca1104f2b0018cb76b 100644 (file)
@@ -570,7 +570,7 @@ static int load_module(void)
 {
        wav49_f.format = ast_format_gsm;
        if (ast_format_def_register(&wav49_f))
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        return AST_MODULE_LOAD_SUCCESS;
 }
 
index 8dcb2bd0b2d030edd775859169561c3ea1194ea3..785ac82f5f4be658e29607d73e83f070965999ce 100644 (file)
@@ -651,7 +651,7 @@ static int load_module(void)
        int res = 0;
 
        if (!router) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        res |= STASIS_MESSAGE_TYPE_INIT(cdr_read_message_type);
@@ -667,7 +667,8 @@ static int load_module(void)
                                         cdr_read_callback, NULL);
 
        if (res) {
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index 3e348c1cf1baa392f45be9be85a154e905dc9204..6d580c20a9fafb3a6dfded4c375ff3921d297f90 100644 (file)
@@ -230,7 +230,7 @@ static int unload_module(void)
 /*! \internal \brief Load the module */
 static int load_module(void)
 {
-       return ast_custom_function_register(&hold_intercept_function) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;
+       return ast_custom_function_register(&hold_intercept_function) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hold interception dialplan function");
index b8dd2d458302d51af809f95e985d41f6228e1c0b..6fcc3fc83df8cc91dd36f405f170f76a542e6ff8 100644 (file)
@@ -399,7 +399,7 @@ static int load_module(void)
 
        res |= ast_custom_function_register(&talk_detect_function);
 
-       return res ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;
+       return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Talk detection dialplan function");
index 9f9f671c06f00586a01f6a4a6c1b39c3c17ce51e..2f629dfbef582d0ead1a010edffb0fdb35bcd67b 100644 (file)
@@ -500,6 +500,13 @@ int ast_verb_console_get(void);
  */
 void ast_verb_console_set(int verb_level);
 
+/*!
+ * \brief Test if logger is initialized
+ *
+ * \retval true if the logger is initialized
+ */
+int ast_is_logger_initialized(void);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
index 5c1052565e6098badfb62465a7032e999bbe06cc..49db383f6d18d6ed05bbaf8301eb4577c4fa8751 100644 (file)
@@ -4400,7 +4400,11 @@ int main(int argc, char *argv[])
 static inline void check_init(int init_result, const char *name)
 {
        if (init_result) {
-               printf("%s initialization failed.\n%s", name, term_quit());
+               if (ast_is_logger_initialized()) {
+                       ast_log(LOG_ERROR, "%s initialization failed.  ASTERISK EXITING!\n%s", name, term_quit());
+               } else {
+                       fprintf(stderr, "%s initialization failed.  ASTERISK EXITING!\n%s", name, term_quit());
+               }
                ast_run_atexits(0);
                exit(init_result == -2 ? 2 : 1);
        }
index 9beaf4d33af071fa9c375edbc890441c77acd339..327bb528f66dfeeef0c4b50b1ce8586fac1829f3 100644 (file)
@@ -1245,6 +1245,7 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
                case AST_MODULE_LOAD_DECLINE:
                        break;
                case AST_MODULE_LOAD_FAILURE:
+                       ast_log(LOG_ERROR, "*** Failed to load module %s\n", mod->resource);
                        res = -1;
                        goto done;
                case AST_MODULE_LOAD_SKIP:
index 7d0d2de1e498a068b8252d49932d1ee07b5efda0..75b6ea22fe3e60f3a6b347b1d7ff2c617b0910dc 100644 (file)
@@ -1655,6 +1655,11 @@ static void logger_queue_init(void)
        }
 }
 
+int ast_is_logger_initialized(void)
+{
+       return logger_initialized;
+}
+
 /*!
  * \brief Start the ast_queue_log() logger.
  *
index 56b0a447a5c67f253daf7a4896c853fd954a0c9d..c6fbc6c50b99f791b9235b5c3259b8f83cd84bd3 100644 (file)
@@ -1108,6 +1108,27 @@ static struct ast_http_uri http_uri = {
        .no_decode_uri = 1,
 };
 
+static int unload_module(void)
+{
+       ast_ari_cli_unregister();
+
+       if (is_enabled()) {
+               ast_debug(3, "Disabling ARI\n");
+               ast_http_uri_unlink(&http_uri);
+       }
+
+       ast_ari_config_destroy();
+
+       ao2_cleanup(root_handler);
+       root_handler = NULL;
+       ast_mutex_destroy(&root_handler_lock);
+
+       ast_json_unref(oom_json);
+       oom_json = NULL;
+
+       return 0;
+}
+
 static int load_module(void)
 {
        ast_mutex_init(&root_handler_lock);
@@ -1117,7 +1138,7 @@ static int load_module(void)
                root_handler = root_handler_create();
        }
        if (!root_handler) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* oom_json may have been built during a declined load */
@@ -1127,10 +1148,12 @@ static int load_module(void)
        }
        if (!oom_json) {
                /* Ironic */
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_ari_config_init() != 0) {
+               unload_module();
                return AST_MODULE_LOAD_DECLINE;
        }
 
@@ -1142,33 +1165,13 @@ static int load_module(void)
        }
 
        if (ast_ari_cli_register() != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       ast_ari_cli_unregister();
-
-       if (is_enabled()) {
-               ast_debug(3, "Disabling ARI\n");
-               ast_http_uri_unlink(&http_uri);
-       }
-
-       ast_ari_config_destroy();
-
-       ao2_cleanup(root_handler);
-       root_handler = NULL;
-       ast_mutex_destroy(&root_handler_lock);
-
-       ast_json_unref(oom_json);
-       oom_json = NULL;
-
-       return 0;
-}
-
 static int reload_module(void)
 {
        char was_enabled = is_enabled();
index 19b6fad753bf0aeb8ef3852fc3cb06b463cf5d6c..f6817b1a39afad3b12935ac1b32a1b967499045d 100644 (file)
@@ -419,6 +419,15 @@ static struct stasis_rest_handlers events = {
        .children = { &events_user, }
 };
 
+static int unload_module(void)
+{
+       ast_ari_remove_handler(&events);
+       ao2_cleanup(events.ws_server);
+       events.ws_server = NULL;
+       stasis_app_unref();
+       return 0;
+}
+
 static int load_module(void)
 {
        int res = 0;
@@ -430,31 +439,27 @@ static int load_module(void)
 
        events.ws_server = ast_websocket_server_create();
        if (!events.ws_server) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        protocol = ast_websocket_sub_protocol_alloc("ari");
        if (!protocol) {
                ao2_ref(events.ws_server, -1);
                events.ws_server = NULL;
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        protocol->session_attempted = ast_ari_events_event_websocket_ws_attempted_cb;
        protocol->session_established = ast_ari_events_event_websocket_ws_established_cb;
        res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);
        stasis_app_ref();
        res |= ast_ari_add_handler(&events);
-       return res;
-}
 
-static int unload_module(void)
-{
-       ast_ari_remove_handler(&events);
-       ao2_cleanup(events.ws_server);
-       events.ws_server = NULL;
-       ast_ari_websocket_events_event_websocket_dtor();
-       stasis_app_unref();
-       return 0;
+       if (res) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - WebSocket resource",
index 14265cdce97e10ae7aab109bd12fff908ab08331..59a205b8131ffe655794538265b16cdd3843d1bb 100644 (file)
@@ -192,7 +192,7 @@ static int load_module(void)
                REG_EXTENDED | REG_ICASE | REG_NOSUB);
 
        if (res != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index 6f6f711b3eb67bba5e714c62ff303ffabde446b1..d0f48fb02a0274c1d6a67df5c55769fd02be59f2 100644 (file)
@@ -1882,7 +1882,7 @@ static int load_module(void)
 {
        if (!(calendars = ao2_container_alloc(CALENDAR_BUCKETS, calendar_hash_fn, calendar_cmp_fn))) {
                ast_log(LOG_ERROR, "Unable to allocate calendars container!\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (load_config(0)) {
@@ -1896,7 +1896,9 @@ static int load_module(void)
 
        if (!(sched = ast_sched_context_create())) {
                ast_log(LOG_ERROR, "Unable to create sched context\n");
-               return AST_MODULE_LOAD_FAILURE;
+               ast_config_destroy(calendar_config);
+               calendar_config = NULL;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_pthread_create_background(&refresh_thread, NULL, do_refresh, NULL) < 0) {
index dfca39a8bf59d873363622a0a15c3fd28abf60bf..2db4bd545e636c0dc120adee200561f86951b646 100644 (file)
@@ -150,13 +150,22 @@ static void default_route(void *data, struct stasis_subscription *sub,
        }
 }
 
+static int unload_module(void)
+{
+       stasis_unsubscribe_and_join(sub);
+       sub = NULL;
+       stasis_message_router_unsubscribe_and_join(router);
+       router = NULL;
+       return 0;
+}
+
 static int load_module(void)
 {
        /* You can create a message router to route messages by type */
        router = stasis_message_router_create(
                ast_channel_topic_all_cached());
        if (!router) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        stasis_message_router_add(router, stasis_cache_update_type(),
                updates, NULL);
@@ -165,20 +174,12 @@ static int load_module(void)
        /* Or a subscription to receive all of the messages from a topic */
        sub = stasis_subscribe(ast_channel_topic_all(), statsmaker, NULL);
        if (!sub) {
-               return AST_MODULE_LOAD_FAILURE;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
 
-static int unload_module(void)
-{
-       stasis_unsubscribe_and_join(sub);
-       sub = NULL;
-       stasis_message_router_unsubscribe_and_join(router);
-       router = NULL;
-       return 0;
-}
-
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Example of how to use Stasis",
        .support_level = AST_MODULE_SUPPORT_EXTENDED,
        .load = load_module,
index d1169478058815ee6069661704df3b88ca6213c9..2d3c98bf92b17dd1574758af9fbe542418d74389 100644 (file)
@@ -1681,7 +1681,7 @@ static int load_module(void)
                ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
                sqlite_freemem(errormsg);
                unload_module();
-               return 1;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        sqlite_freemem(errormsg);
@@ -1701,7 +1701,7 @@ static int load_module(void)
                if (!query) {
                        ast_log(LOG_ERROR, "Unable to allocate SQL query\n");
                        unload_module();
-                       return 1;
+                       return AST_MODULE_LOAD_DECLINE;
                }
 
                ast_debug(1, "SQL query: %s\n", query);
@@ -1720,7 +1720,7 @@ static int load_module(void)
                                ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
                                sqlite_freemem(errormsg);
                                unload_module();
-                               return 1;
+                               return AST_MODULE_LOAD_DECLINE;
                        }
 
                        sqlite_freemem(errormsg);
@@ -1730,7 +1730,7 @@ static int load_module(void)
                        if (!query) {
                                ast_log(LOG_ERROR, "Unable to allocate SQL query\n");
                                unload_module();
-                               return 1;
+                               return AST_MODULE_LOAD_DECLINE;
                        }
 
                        ast_debug(1, "SQL query: %s\n", query);
@@ -1745,7 +1745,7 @@ static int load_module(void)
                                ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
                                sqlite_freemem(errormsg);
                                unload_module();
-                               return 1;
+                               return AST_MODULE_LOAD_DECLINE;
                        }
                }
                sqlite_freemem(errormsg);
@@ -1755,7 +1755,7 @@ static int load_module(void)
 
                if (error) {
                        unload_module();
-                       return 1;
+                       return AST_MODULE_LOAD_DECLINE;
                }
 
                cdr_registered = 1;
@@ -1765,12 +1765,12 @@ static int load_module(void)
 
        if (error) {
                unload_module();
-               return 1;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        cli_status_registered = 1;
 
-       return 0;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Realtime SQLite configuration",
index 0d553b8444477049caa12639a358ebb56d4c3321..11acf640b401948a8535ab331e2cf39394b56bcf 100644 (file)
@@ -1361,18 +1361,18 @@ static int load_module(void)
        discover_sqlite3_caps();
 
        if (!((databases = ao2_container_alloc(DB_BUCKETS, db_hash_fn, db_cmp_fn)))) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (parse_config(0)) {
                ao2_ref(databases, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(ast_config_engine_register(&sqlite3_config_engine))) {
                ast_log(LOG_ERROR, "The config API must have changed, this shouldn't happen.\n");
                ao2_ref(databases, -1);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 28e47d0d6f2f2e23b04486c5073b81f7a7ce9aca..2e7742f568f976203c09ea6187cd93a093deb156 100644 (file)
@@ -120,7 +120,7 @@ static int load_module(void)
 
        router = stasis_message_router_create(ast_endpoint_topic_all_cached());
        if (!router) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        stasis_message_router_add(router, stasis_cache_update_type(), cache_update_cb, NULL);
 
index 03db181596606a1b5e37a296d7448267f6cef0b0..fb80184b9a3486a69f83e44aba172d4e377c8e0a 100644 (file)
@@ -157,7 +157,7 @@ static int load_module(void)
        stasis_rtp_subscription = stasis_subscribe(ast_rtp_topic(),
                rtp_topic_handler, NULL);
        if (!stasis_rtp_subscription) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 8476e26312b64e647708668b1af8fc0e23a128c2..9f5d931d6ae277d4192c86f3158bf76f9ed01241 100644 (file)
@@ -1451,7 +1451,7 @@ static int load_module(void)
 {
        websocketuri.data = websocket_server_internal_create();
        if (!websocketuri.data) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_http_uri_link(&websocketuri);
        websocket_add_protocol_internal("echo", websocket_echo_callback);
index d844efe8c95ed665b7d5cd1e8eea7219bb3780a3..6973d7fa96478851d48026a6d312cba99d56d47d 100644 (file)
@@ -211,7 +211,7 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS;
+       return ast_cli_register(&cli_ulimit) ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Resource limits");
index d180296f420a91cfef07ef19da3a696a686d5a78..62bc9d67db258f7c36b5c47d021c4276ab838c22 100644 (file)
@@ -1348,7 +1348,7 @@ int ast_sip_initialize_sorcery_transport(void)
        transport_states = ao2_container_alloc(DEFAULT_STATE_BUCKETS, internal_state_hash, internal_state_cmp);
        if (!transport_states) {
                ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return -1;
        }
 
        ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
index a26180bc0b8ed6f825f5373d33300b5db2497ce2..9205622d7ad4fc09afe337021bb635314e96f72a 100644 (file)
@@ -361,13 +361,13 @@ static int load_module(void)
 
        if (ast_sip_register_service(&nat_module)) {
                ast_log(LOG_ERROR, "Could not register NAT module for incoming and outgoing requests\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_sip_session_register_supplement(&nat_supplement)) {
                ast_log(LOG_ERROR, "Could not register NAT session supplement for incoming and outgoing INVITE requests\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 2d53fd48ee0760cd4844c40cd715f283820c8e80..ec5f9be3e7cdacce04ff1583bbc100a2ab4f0234 100644 (file)
@@ -112,7 +112,7 @@ static int load_module(void)
 
        if (ast_sip_session_register_supplement(&info_supplement)) {
                ast_log(LOG_ERROR, "Unable to register One Touch Recording supplement\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index a19a9bb2441757cc9b6855ec2a376086a8215082..c413cb0e13c1de5240806d4539f25e26cf015776 100644 (file)
@@ -1631,7 +1631,7 @@ static int load_module(void)
 
        shutdown_group = ast_serializer_shutdown_group_alloc();
        if (!shutdown_group) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_sorcery_apply_config(ast_sip_get_sorcery(), "res_pjsip_outbound_publish");
index 704239bd01ae1e1bde00538b46a1c810bf30b624..8a840ff05ebb014824fcf92bc68b6f100316038d 100644 (file)
@@ -2082,7 +2082,7 @@ static int load_module(void)
 
        shutdown_group = ast_serializer_shutdown_group_alloc();
        if (!shutdown_group) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Create outbound registration states container. */
@@ -2091,7 +2091,7 @@ static int load_module(void)
        if (!new_states) {
                ast_log(LOG_ERROR, "Unable to allocate registration states container\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ao2_global_obj_replace_unref(current_states, new_states);
        ao2_ref(new_states, -1);
@@ -2135,7 +2135,7 @@ static int load_module(void)
                        &registration_observer)) {
                ast_log(LOG_ERROR, "Unable to register observers.\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        /* Register how this module identifies endpoints. */
@@ -2146,7 +2146,7 @@ static int load_module(void)
        if (!cli_formatter) {
                ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        cli_formatter->name = "registration";
        cli_formatter->print_header = cli_print_header;
index f0467627ea5820fc6f6728bb7576f211dda5c6b8..a1f3f246257e4cde0a08d6e40031fdfcb9d9077e 100644 (file)
@@ -5225,13 +5225,13 @@ static int load_module(void)
 
        if (!(sched = ast_sched_context_create())) {
                ast_log(LOG_ERROR, "Could not create scheduler for publication expiration\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (ast_sched_start_thread(sched)) {
                ast_log(LOG_ERROR, "Could not start scheduler thread for publication expiration\n");
                ast_sched_context_destroy(sched);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_ALLOW, NULL, 1, &str_PUBLISH);
@@ -5239,7 +5239,7 @@ static int load_module(void)
        if (ast_sip_register_service(&pubsub_module)) {
                ast_log(LOG_ERROR, "Could not register pubsub service\n");
                ast_sched_context_destroy(sched);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_sorcery_apply_config(sorcery, "res_pjsip_pubsub");
@@ -5249,7 +5249,7 @@ static int load_module(void)
                ast_log(LOG_ERROR, "Could not register subscription persistence object support\n");
                ast_sip_unregister_service(&pubsub_module);
                ast_sched_context_destroy(sched);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_sorcery_object_field_register(sorcery, "subscription_persistence", "packet", "", OPT_CHAR_ARRAY_T, 0,
                CHARFLDSET(struct subscription_persistence, packet));
@@ -5277,7 +5277,7 @@ static int load_module(void)
        if (apply_list_configuration(sorcery)) {
                ast_sip_unregister_service(&pubsub_module);
                ast_sched_context_destroy(sched);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        ast_sorcery_apply_default(sorcery, "inbound-publication", "config", "pjsip.conf,criteria=type=inbound-publication");
@@ -5286,7 +5286,7 @@ static int load_module(void)
                ast_log(LOG_ERROR, "Could not register subscription persistence object support\n");
                ast_sip_unregister_service(&pubsub_module);
                ast_sched_context_destroy(sched);
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_sorcery_object_field_register(sorcery, "inbound-publication", "type", "", OPT_NOOP_T, 0, 0);
        ast_sorcery_object_field_register_custom(sorcery, "inbound-publication", "endpoint", "",
index ddcdb8aaa722368037197472a3745c72d8e07ba0..6f94b0f4ac118a3774e52e16cad4c0b28965f76f 100644 (file)
@@ -1646,7 +1646,7 @@ static int load_module(void)
 end:
        unload_module();
 
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP SDP RTP/AVP stream handler",
index bd70bcfd70fc06e78ff6b502c31ed92a146d0136..1cd28ceac8f83df50b54bffab60ca8afe4241e85 100644 (file)
@@ -219,7 +219,7 @@ static int load_module(void)
 
        if (ast_sip_session_register_supplement(&refer_supplement)) {
                ast_log(LOG_ERROR, "Unable to register Send to Voicemail supplement\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 1206e5a885f3b47742d94be90bd063720efa494a..346f82462ec738daabc39ab0e3ea8b7a532f92e2 100644 (file)
@@ -940,7 +940,7 @@ static int load_module(void)
 end:
        unload_module();
 
-       return AST_MODULE_LOAD_FAILURE;
+       return AST_MODULE_LOAD_DECLINE;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP T.38 UDPTL Support",
index 770ac62d2d2b3f0a8ca02f58eb6e9f2b82dde303..225a491a5879daffe9b31c7f4a278bfba67d38ba 100644 (file)
@@ -1128,7 +1128,7 @@ static int smdi_load(int reload)
        if (!AST_LIST_EMPTY(&mwi_monitor.mailbox_mappings) && mwi_monitor.thread == AST_PTHREADT_NULL
                && ast_pthread_create_background(&mwi_monitor.thread, NULL, mwi_monitor_handler, NULL)) {
                ast_log(LOG_ERROR, "Failed to start MWI monitoring thread.  This module will not operate.\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return -1;
        }
 
        if (ao2_container_count(new_ifaces)) {
@@ -1371,7 +1371,7 @@ static int load_module(void)
        res = smdi_load(0);
        if (res < 0) {
                _unload_module(1);
-               return res;
+               return AST_MODULE_LOAD_DECLINE;
        } else if (res == 1) {
                _unload_module(1);
                ast_log(LOG_NOTICE, "No SMDI interfaces are available to listen on, not starting SMDI listener.\n");
index 72a85e3d7cfc432d7dd053c4bf583c88ff76f1ec..c68aa8a9ae2d29971dd6419e4192efb0d5732a8b 100644 (file)
@@ -2113,12 +2113,12 @@ static int load_module(void)
                37, bridges_channel_hash_fn, bridges_channel_sort_fn, NULL);
        if (!apps_registry || !app_controls || !app_bridges || !app_bridges_moh || !app_bridges_playback) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (messaging_init()) {
                unload_module();
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        bridge_stasis_init();
index f695ed5eec96fd020d50e4c0f29a8d95b5a87fe1..8356283587946441623860c4b16d2b1adcae1afe 100644 (file)
@@ -455,13 +455,14 @@ static int load_module(void)
        populate_cache();
        if (ast_devstate_prov_add(DEVICE_STATE_PROVIDER_STASIS,
                                  stasis_device_state_cb)) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        if (!(device_state_subscriptions = ao2_container_alloc(
                      DEVICE_STATE_BUCKETS, device_state_subscriptions_hash,
                      device_state_subscriptions_cmp))) {
-               return AST_MODULE_LOAD_FAILURE;
+               ast_devstate_prov_del(DEVICE_STATE_PROVIDER_STASIS);
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        stasis_app_register_event_source(&device_state_event_source);
index cfddb3af56dcf5cae298fc5aa17be24dfcc91934..f909a695f5ec0ad6ab17b83172474909b1d97597 100644 (file)
@@ -733,13 +733,14 @@ static int load_module(void)
 
        r = STASIS_MESSAGE_TYPE_INIT(stasis_app_playback_snapshot_type);
        if (r != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        playbacks = ao2_container_alloc(PLAYBACK_BUCKETS, playback_hash,
                playback_cmp);
        if (!playbacks) {
-               return AST_MODULE_LOAD_FAILURE;
+               STASIS_MESSAGE_TYPE_CLEANUP(stasis_app_playback_snapshot_type);
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index af5c41e877c3bb8c5566e9c51c7edeb28add9db6..62d1c53995e5734094ce8199493e6b8090b213b8 100644 (file)
@@ -633,13 +633,14 @@ static int load_module(void)
 
        r = STASIS_MESSAGE_TYPE_INIT(stasis_app_recording_snapshot_type);
        if (r != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        recordings = ao2_container_alloc(RECORDING_BUCKETS, recording_hash,
                recording_cmp);
        if (!recordings) {
-               return AST_MODULE_LOAD_FAILURE;
+               STASIS_MESSAGE_TYPE_CLEANUP(stasis_app_recording_snapshot_type);
+               return AST_MODULE_LOAD_DECLINE;
        }
        return AST_MODULE_LOAD_SUCCESS;
 }
index efdbc4b529fb2e6bb12222193a5d9dba1e0e0c7c..1b75218fa42e8aaef0251d3ba9b1121c708403cf 100644 (file)
@@ -274,7 +274,7 @@ static int unload_module(void)
 static int load_module(void)
 {
        if (STASIS_MESSAGE_TYPE_INIT(stasis_test_message_type) != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index f3a64e0f8ef95c1dedcd6429f0f3163def194ea2..8f56cf892be4c43d0b98d16a2c7aec18c34c4024 100644 (file)
@@ -351,7 +351,8 @@ static int load_module(void)
        }
 
        if (statsd_init() != 0) {
-               return AST_MODULE_LOAD_FAILURE;
+               aco_info_destroy(&cfg_info);
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        return AST_MODULE_LOAD_SUCCESS;
index 6e96b5867e47ca2a4a81276efad39dab87146e9b..f58adcd9ee08714c7a457152e27ca9e392b180db 100644 (file)
@@ -258,6 +258,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;
@@ -272,14 +285,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;
@@ -291,21 +304,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}}}",
index eb8fc902886bd6c30d6dee14cd7ad4763b7e082a..94edc91887d9bec968aeb5b9c81869b90412997d 100644 (file)
@@ -1014,7 +1014,7 @@ static int load_module(void)
        if (ast_bucket_scheme_register("test", &bucket_test_wizard, &bucket_file_test_wizard,
                ast_bucket_file_temporary_create, ast_bucket_file_temporary_destroy)) {
                ast_log(LOG_ERROR, "Failed to register Bucket test wizard scheme implementation\n");
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
 
        AST_TEST_REGISTER(bucket_scheme_register);
index 94037e2fa50c6b4bdc81fe06f4d650fb761777ec..5ff72c1f49b3827ef18a3b05853623bd7e3d94d3 100644 (file)
@@ -347,7 +347,7 @@ static int load_module(void)
 {
        test_features_chan_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
        if (!test_features_chan_tech.capabilities) {
-               return AST_MODULE_LOAD_FAILURE;
+               return AST_MODULE_LOAD_DECLINE;
        }
        ast_format_cap_append(test_features_chan_tech.capabilities, TEST_CHANNEL_FORMAT, 0);
        ast_channel_register(&test_features_chan_tech);