提交 70228936 authored 作者: Anthony Minessale's avatar Anthony Minessale

improve unload stuff

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9353 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 600ce5fd
...@@ -376,16 +376,30 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load) ...@@ -376,16 +376,30 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
switch_log_bind_logger(mod_logfile_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE); switch_log_bind_logger(mod_logfile_logger, SWITCH_LOG_DEBUG, SWITCH_FALSE);
return SWITCH_STATUS_NOUNLOAD; return SWITCH_STATUS_SUCCESS;
} }
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown) SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_logfile_shutdown)
{ {
/* TODO: Need to finish processing pending log messages before we close the file handle */ switch_hash_index_t *hi;
const void *var;
void *val;
//switch_file_close(globals->log_afd); switch_log_unbind_logger(mod_logfile_logger);
switch_event_unbind(&globals.node); switch_event_unbind(&globals.node);
for (hi = switch_hash_first(NULL, profile_hash); hi; hi = switch_hash_next(hi)) {
logfile_profile_t *profile;
switch_hash_this(hi, &var, NULL, &val);
if ((profile = (logfile_profile_t *) val)) {
switch_file_close(profile->log_afd);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Closing %s\n", profile->logfile);
printf("WTF\n");
}
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
...@@ -445,7 +445,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) ...@@ -445,7 +445,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
for (hi = switch_hash_first(NULL, CUSTOM_HASH); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, CUSTOM_HASH); hi; hi = switch_hash_next(hi)) {
switch_event_subclass_t *subclass; switch_event_subclass_t *subclass;
switch_hash_this(hi, &var, NULL, &val);; switch_hash_this(hi, &var, NULL, &val);
if ((subclass = (switch_event_subclass_t *) val)) { if ((subclass = (switch_event_subclass_t *) val)) {
FREE(subclass->name); FREE(subclass->name);
FREE(subclass->owner); FREE(subclass->owner);
......
...@@ -51,6 +51,7 @@ struct switch_loadable_module { ...@@ -51,6 +51,7 @@ struct switch_loadable_module {
switch_module_runtime_t switch_module_runtime; switch_module_runtime_t switch_module_runtime;
switch_module_shutdown_t switch_module_shutdown; switch_module_shutdown_t switch_module_shutdown;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_status_t status;
}; };
struct switch_loadable_module_container { struct switch_loadable_module_container {
...@@ -73,7 +74,7 @@ struct switch_loadable_module_container { ...@@ -73,7 +74,7 @@ struct switch_loadable_module_container {
}; };
static struct switch_loadable_module_container loadable_modules; static struct switch_loadable_module_container loadable_modules;
static void do_shutdown(switch_loadable_module_t *module); static void do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload);
static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj) static void *switch_loadable_module_exec(switch_thread_t *thread, void *obj)
{ {
...@@ -867,7 +868,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir, ...@@ -867,7 +868,7 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_unload_module(char *dir,
status = SWITCH_STATUS_NOUNLOAD; status = SWITCH_STATUS_NOUNLOAD;
goto end; goto end;
} else { } else {
do_shutdown(module); do_shutdown(module, SWITCH_TRUE, SWITCH_TRUE);
} }
switch_core_hash_delete(loadable_modules.module_hash, fname); switch_core_hash_delete(loadable_modules.module_hash, fname);
} else { } else {
...@@ -1106,14 +1107,21 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init() ...@@ -1106,14 +1107,21 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static void do_shutdown(switch_loadable_module_t *module) static void do_shutdown(switch_loadable_module_t *module, switch_bool_t shutdown, switch_bool_t unload)
{ {
switch_assert(module != NULL); switch_assert(module != NULL);
if (shutdown) {
switch_loadable_module_unprocess(module); switch_loadable_module_unprocess(module);
if (module->switch_module_shutdown) { if (module->switch_module_shutdown) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping: %s\n", module->module_interface->module_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping: %s\n", module->module_interface->module_name);
if (module->switch_module_shutdown() == SWITCH_STATUS_UNLOAD) { module->status = module->switch_module_shutdown();
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s has no shutdown routine\n", module->module_interface->module_name);
}
}
if (unload && module->status != SWITCH_STATUS_NOUNLOAD) {
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s unloaded.\n", module->module_interface->module_name); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s unloaded.\n", module->module_interface->module_name);
switch_dso_unload(module->lib); switch_dso_unload(module->lib);
...@@ -1122,12 +1130,8 @@ static void do_shutdown(switch_loadable_module_t *module) ...@@ -1122,12 +1130,8 @@ static void do_shutdown(switch_loadable_module_t *module)
module = NULL; module = NULL;
switch_core_destroy_memory_pool(&pool); switch_core_destroy_memory_pool(&pool);
} }
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s shutdown.\n", module->module_interface->module_name);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s has no shutdown routine\n", module->module_interface->module_name);
} }
} }
SWITCH_DECLARE(void) switch_loadable_module_shutdown(void) SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
...@@ -1139,7 +1143,17 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void) ...@@ -1139,7 +1143,17 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void)
for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); switch_hash_this(hi, NULL, NULL, &val);
module = (switch_loadable_module_t *) val; module = (switch_loadable_module_t *) val;
do_shutdown(module); if (!module->perm) {
do_shutdown(module, SWITCH_TRUE, SWITCH_FALSE);
}
}
for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
module = (switch_loadable_module_t *) val;
if (!module->perm) {
do_shutdown(module, SWITCH_FALSE, SWITCH_TRUE);
}
} }
switch_core_hash_destroy(&loadable_modules.module_hash); switch_core_hash_destroy(&loadable_modules.module_hash);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论