summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-04-11 10:07:39 -0600
committerGeorge Joseph <gjoseph@digium.com>2017-04-12 15:47:56 -0600
commitcc668bd522fceb9cb6cd0d69f5e29c28f1835b2a (patch)
treef4ea57201c41cde4cf2a326d400eed2e41179b52 /channels
parent0986618c94cbe0e2d95354f867c6cc966758a025 (diff)
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
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_alsa.c46
-rw-r--r--channels/chan_dahdi.c12
-rw-r--r--channels/chan_iax2.c33
-rw-r--r--channels/chan_mgcp.c10
-rw-r--r--channels/chan_motif.c2
-rw-r--r--channels/chan_nbs.c4
-rw-r--r--channels/chan_oss.c57
-rw-r--r--channels/chan_phone.c6
-rw-r--r--channels/chan_pjsip.c2
-rw-r--r--channels/chan_sip.c20
-rw-r--r--channels/chan_skinny.c6
-rw-r--r--channels/chan_unistim.c2
12 files changed, 109 insertions, 91 deletions
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c
index 5c028c3b3..7a6f84188 100644
--- a/channels/chan_alsa.c
+++ b/channels/chan_alsa.c
@@ -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,
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 71dbd35f1..55a9dbaf4 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -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));
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 469a17275..8941634b0 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -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");
}
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 6df5d3fd0..33f4f4635 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -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);
diff --git a/channels/chan_motif.c b/channels/chan_motif.c
index 0c710923f..1f449140f 100644
--- a/channels/chan_motif.c
+++ b/channels/chan_motif.c
@@ -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 */
diff --git a/channels/chan_nbs.c b/channels/chan_nbs.c
index d50defeaf..b4a0532f1 100644
--- a/channels/chan_nbs.c
+++ b/channels/chan_nbs.c
@@ -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;
diff --git a/channels/chan_oss.c b/channels/chan_oss.c
index 84a1391da..87711078c 100644
--- a/channels/chan_oss.c
+++ b/channels/chan_oss.c
@@ -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");
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index b7f694f81..94116e79a 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -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 */
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index e51852346..e8e366651 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -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 */
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 052fa9e9c..a646e730a 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -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
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index 96a206c37..a654d0f6d 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -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;
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index af0f2c688..84a6383bd 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -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)