[asterisk-commits] dlee: branch dlee/ASTERISK-22296 r397866 - /team/dlee/ASTERISK-22296/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 28 14:04:16 CDT 2013
Author: dlee
Date: Wed Aug 28 14:04:14 2013
New Revision: 397866
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397866
Log:
Error logging around dlclose
Modified:
team/dlee/ASTERISK-22296/main/loader.c
Modified: team/dlee/ASTERISK-22296/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/main/loader.c?view=diff&rev=397866&r1=397865&r2=397866
==============================================================================
--- team/dlee/ASTERISK-22296/main/loader.c (original)
+++ team/dlee/ASTERISK-22296/main/loader.c Wed Aug 28 14:04:14 2013
@@ -406,8 +406,21 @@
}
#ifdef LOADABLE_MODULES
+
+/*!
+ * \brief dlclose(), with failure logging.
+ */
+static void logged_dlclose(const char *name, void *lib)
+{
+ if (dlclose(lib) != 0) {
+ ast_log(LOG_ERROR, "Failed to unload %s: %s\n",
+ name, dlerror());
+ }
+}
+
static void unload_dynamic_module(struct ast_module *mod)
{
+ char *name = ast_strdupa(ast_module_name(mod));
void *lib = mod->lib;
/* WARNING: the structure pointed to by mod is going to
@@ -415,7 +428,7 @@
dereference it */
if (lib)
- dlclose(lib);
+ logged_dlclose(name, lib);
}
static enum ast_module_load_result load_resource(const char *resource_name, unsigned int global_symbols_only, struct ast_heap *resource_heap, int required);
@@ -464,7 +477,7 @@
if (resource_being_loaded != (mod = AST_LIST_LAST(&module_list))) {
ast_log(LOG_WARNING, "Module '%s' did not register itself during load\n", resource_in);
/* no, it did not, so close it and return */
- dlclose(lib);
+ logged_dlclose(resource_in, lib);
/* note that the module's destructor will call ast_module_unregister(),
which will free the structure we allocated in resource_being_loaded */
return NULL;
@@ -475,11 +488,11 @@
/* if we are being asked only to load modules that provide global symbols,
and this one does not, then close it and return */
if (global_symbols_only && !wants_global) {
- dlclose(lib);
+ logged_dlclose(resource_in, lib);
return NULL;
}
- dlclose(lib);
+ logged_dlclose(resource_in, lib);
resource_being_loaded = NULL;
/* start the load process again */
@@ -505,6 +518,37 @@
return AST_LIST_LAST(&module_list);
}
+
+/*!
+ * \brief Check to see if the given resource is loaded.
+ *
+ * \param resource_name Name of the resource, optionally with .so.
+ * \return False (0) if module is not loaded.
+ * \return True (non-zero) if module is loaded.
+ */
+static int is_module_loaded(const char *resource_name)
+{
+ char fn[PATH_MAX] = "";
+ int missing_so;
+ void *lib;
+
+ if (strcasecmp(resource_name + strlen(resource_name) - 3, ".so")) {
+ missing_so = 1;
+ }
+
+ snprintf(fn, sizeof(fn), "%s/%s%s", ast_config_AST_MODULE_DIR,
+ resource_name, missing_so ? ".so" : "");
+
+ lib = dlopen(fn, RTLD_LAZY | RTLD_NOLOAD);
+
+ if (lib) {
+ logged_dlclose(resource_name, lib);
+ return 1;
+ }
+
+ return 0;
+}
+
#endif
void ast_module_shutdown(void)
@@ -612,6 +656,9 @@
#ifdef LOADABLE_MODULES
if (!error) {
unload_dynamic_module(mod);
+ if (is_module_loaded(resource_name)) {
+ ast_log(LOG_ERROR, "Module '%s' could not be completely unloaded\n", resource_name);
+ }
ast_test_suite_event_notify("MODULE_UNLOAD", "Message: %s", resource_name);
}
#endif
More information about the asterisk-commits
mailing list