Index: channels/chan_unicall.c =================================================================== --- channels/chan_unicall.c (revision 349) +++ channels/chan_unicall.c (working copy) @@ -3988,6 +3988,75 @@ {"UC", "destroy", "channel", NULL}, unicall_destroy_channel, "Destroy a channel", destroy_channel_usage, NULL }; +static int __unload_module(void) +{ + struct unicall_pvt *p; + struct unicall_pvt *pl; + +ast_log(LOG_WARNING, "Hello computer!\n"); + + /* First, take us out of the channel loop */ + ast_channel_unregister(&unicall_tech); + ast_cli_unregister(&cli_show_channels); + ast_cli_unregister(&cli_show_channel); + ast_cli_unregister(&cli_destroy_channel); + + if (ast_mutex_lock(&iflock)) + { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + /*endif*/ + /* Hangup all interfaces if they have an owner */ + for (p = iflist; p; p = p->next) + { + if (p->owner) + ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); + /*endif*/ + } + /*endfor*/ + iflist = NULL; + ast_mutex_unlock(&iflock); + if (ast_mutex_lock(&monlock)) + { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + /*endif*/ + if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) + { + pthread_cancel(monitor_thread); + pthread_kill(monitor_thread, SIGURG); + pthread_join(monitor_thread, NULL); + } + /*endif*/ + monitor_thread = AST_PTHREADT_STOP; + ast_mutex_unlock(&monlock); + + if (ast_mutex_lock(&iflock)) + { + ast_log(LOG_WARNING, "Unable to lock the monitor\n"); + return -1; + } + /*endif*/ + /* Destroy all the interfaces and free their memory */ + for (p = iflist; p; ) + { + /* Close the zapata thingy */ + if (p->subs[SUB_REAL].fd >= 0) + unicall_close(p->subs[SUB_REAL].fd); + /*endif*/ + pl = p; + p = p->next; + /* Free associated memory */ + free(pl); + } + /*endfor*/ + iflist = NULL; + ast_mutex_unlock(&iflock); + return 0; +} + static int setup_unicall(int reload) { struct unicall_pvt *tmp; @@ -4034,7 +4103,7 @@ ast_log(LOG_ERROR, "Signalling must be specified before any channels are.\n"); ast_config_destroy(cfg); ast_mutex_unlock(&iflock); - unload_module(); + __unload_module(); return -1; } /*endif*/ @@ -4061,7 +4130,7 @@ ast_log(LOG_ERROR, "Syntax error parsing '%s' at '%s'\n", v->value, chan); ast_config_destroy(cfg); ast_mutex_unlock(&iflock); - unload_module(); + __unload_module(); return -1; } /*endif*/ @@ -4081,7 +4150,7 @@ ast_log(LOG_ERROR, "Unable to register channel '%s'\n", v->value); ast_config_destroy(cfg); ast_mutex_unlock(&iflock); - unload_module(); + __unload_module(); return -1; } /*endif*/ @@ -4253,7 +4322,7 @@ { ast_log(LOG_ERROR, "Unable to read supervisory tone set %s\n", super_tones); ast_config_destroy(cfg); - unload_module(); + __unload_module(); return -1; } /*endif*/ @@ -4264,7 +4333,7 @@ { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); ast_config_destroy(cfg); - unload_module(); + __unload_module(); return -1; } /*endif*/ @@ -4295,68 +4364,7 @@ int unload_module(void) { - struct unicall_pvt *p; - struct unicall_pvt *pl; - - /* First, take us out of the channel loop */ - ast_channel_unregister(&unicall_tech); - ast_cli_unregister(&cli_show_channels); - ast_cli_unregister(&cli_show_channel); - ast_cli_unregister(&cli_destroy_channel); - if (ast_mutex_lock(&iflock)) - { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - /*endif*/ - /* Hangup all interfaces if they have an owner */ - for (p = iflist; p; p = p->next) - { - if (p->owner) - ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); - /*endif*/ - } - /*endfor*/ - iflist = NULL; - ast_mutex_unlock(&iflock); - if (ast_mutex_lock(&monlock)) - { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - /*endif*/ - if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) - { - pthread_cancel(monitor_thread); - pthread_kill(monitor_thread, SIGURG); - pthread_join(monitor_thread, NULL); - } - /*endif*/ - monitor_thread = AST_PTHREADT_STOP; - ast_mutex_unlock(&monlock); - - if (ast_mutex_lock(&iflock)) - { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - /*endif*/ - /* Destroy all the interfaces and free their memory */ - for (p = iflist; p; ) - { - /* Close the zapata thingy */ - if (p->subs[SUB_REAL].fd >= 0) - unicall_close(p->subs[SUB_REAL].fd); - /*endif*/ - pl = p; - p = p->next; - /* Free associated memory */ - free(pl); - } - /*endfor*/ - iflist = NULL; - ast_mutex_unlock(&iflock); - return 0; + return __unload_module(); } static int unicall_send_text(struct ast_channel *c, const char *text)