[icinga-checkins] icinga.org: icinga-core/master: core: revamp USE_LTDL definitions in nebmods #3817

git at icinga.org git at icinga.org
Thu Mar 21 17:12:37 CET 2013


Module: icinga-core
Branch: master
Commit: f263e3a5d50acb9adc6223d224116f49dbf014a1
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=f263e3a5d50acb9adc6223d224116f49dbf014a1

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Sun Mar 10 19:06:02 2013 +0100

core: revamp USE_LTDL definitions in nebmods #3817

fixes #3817

---

 Changelog      |    1 +
 base/nebmods.c |   71 ++++++++++++++++++-------------------------------------
 2 files changed, 24 insertions(+), 48 deletions(-)

diff --git a/Changelog b/Changelog
index a0f4a0e..fe98861 100644
--- a/Changelog
+++ b/Changelog
@@ -44,6 +44,7 @@ FIXES
 * core: fix host_check, last_check == next_check wrong in scheduling queue #2195 - MF
 * core: fix triggered downtimes for child hosts are missing after icinga restart (thx Michael Lucka) #3390 - MF
 * core: fix services with empty hostgroups aren't processed even if it has host_name specified (allow_empty_hostgroups=1) (thx Viranch Metha) #3736 - MF
+* core: revamp USE_LTDL definitions in nebmods (Andreas Ericsson) #3817 - MF
 
 * idoutils: fix many memory leaks in ido2db on dbi_result_free and others (thx Klaus Wagner) #3406 - MF
 * idoutils: fix ido2db crashes when Oracle queries fail #3324 - GB
diff --git a/base/nebmods.c b/base/nebmods.c
index 2ab53b1..da06998 100644
--- a/base/nebmods.c
+++ b/base/nebmods.c
@@ -39,8 +39,18 @@ nebcallback **neb_callback_list = NULL;
 extern char     *temp_path;
 
 
-/*#define DEBUG*/
-
+/* compat stuff for USE_LTDL */
+#ifdef USE_LTDL
+# define dlopen(p, flags) lt_dlopen(p)
+# define dlclose(p) lt_dlclose(p)
+# define dlerror(p) lt_dlerror(p)
+# define dlsym(hdl, sym) lt_dlsym(hdl, sym)
+# define RTLD_NOW 0
+# define RTLD_GLOBAL 0
+#else
+# define lt_dlinit() 0
+# define lt_dlexit() 0
+#endif
 
 /****************************************************************************/
 /****************************************************************************/
@@ -50,16 +60,10 @@ extern char     *temp_path;
 
 /* initialize module routines */
 int neb_init_modules(void) {
-#ifdef USE_LTDL
-	int result = OK;
-#endif
 
 	/* initialize library */
-#ifdef USE_LTDL
-	result = lt_dlinit();
-	if (result)
+	if (lt_dlinit())
 		return ERROR;
-#endif
 
 	return OK;
 }
@@ -67,16 +71,10 @@ int neb_init_modules(void) {
 
 /* deinitialize module routines */
 int neb_deinit_modules(void) {
-#ifdef USE_LTDL
-	int result = OK;
-#endif
 
 	/* deinitialize library */
-#ifdef USE_LTDL
-	result = lt_dlexit();
-	if (result)
+	if (lt_dlexit())
 		return ERROR;
-#endif
 
 	return OK;
 }
@@ -210,18 +208,11 @@ int neb_load_module(nebmodule *mod) {
 	   many other installation-tools do). */
 
 	/* load the module (use the temp copy we just made) */
-#ifdef USE_LTDL
-	mod->module_handle = lt_dlopen(mod->filename);
-#else
-	mod->module_handle = (void *)dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
-#endif
+	mod->module_handle = dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
+
 	if (mod->module_handle == NULL) {
 
-#ifdef USE_LTDL
-		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, lt_dlerror());
-#else
 		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, dlerror());
-#endif
 
 		return ERROR;
 	}
@@ -236,11 +227,7 @@ int neb_load_module(nebmodule *mod) {
 	}
 
 	/* find module API version */
-#ifdef USE_LTDL
-	module_version_ptr = (int *)lt_dlsym(mod->module_handle, "__neb_api_version");
-#else
 	module_version_ptr = (int *)dlsym(mod->module_handle, "__neb_api_version");
-#endif
 
 	/* mark the module as being loaded */
 	mod->is_currently_loaded = TRUE;
@@ -256,11 +243,7 @@ int neb_load_module(nebmodule *mod) {
 	}
 
 	/* locate the initialization function */
-#ifdef USE_LTDL
-	mod->init_func = lt_dlsym(mod->module_handle, "nebmodule_init");
-#else
 	mod->init_func = (void *)dlsym(mod->module_handle, "nebmodule_init");
-#endif
 
 	/* if the init function could not be located, unload the module */
 	if (mod->init_func == NULL) {
@@ -306,11 +289,7 @@ int neb_load_module(nebmodule *mod) {
 	}
 
 	/* locate the de-initialization function (may or may not be present) */
-#ifdef USE_LTDL
-	mod->deinit_func = lt_dlsym(mod->module_handle, "nebmodule_deinit");
-#else
-	mod->deinit_func = (void *)dlsym(mod->module_handle, "nebmodule_deinit");
-#endif
+	mod->deinit_func = dlsym(mod->module_handle, "nebmodule_deinit");
 
 	log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' loaded with return code of '%d'\n", mod->filename, result);
 	if (mod->deinit_func != NULL)
@@ -370,11 +349,7 @@ int neb_unload_module(nebmodule *mod, int flags, int reason) {
 	neb_deregister_module_callbacks(mod);
 
 	/* unload the module */
-#ifdef USE_LTDL
-	result = lt_dlclose(mod->module_handle);
-#else
 	result = dlclose(mod->module_handle);
-#endif
 
 	/* mark the module as being unloaded */
 	mod->is_currently_loaded = FALSE;
@@ -408,7 +383,7 @@ int neb_set_module_info(void *handle, int type, char *data) {
 
 	/* find the module */
 	for (temp_module = neb_module_list; temp_module != NULL; temp_module = temp_module->next) {
-		if ((void *)temp_module->module_handle == (void *)handle)
+		if (temp_module->module_handle == handle)
 			break;
 	}
 	if (temp_module == NULL)
@@ -454,7 +429,7 @@ int neb_register_callback(int callback_type, void *mod_handle, int priority, int
 
 	/* make sure module handle is valid */
 	for (temp_module = neb_module_list; temp_module; temp_module = temp_module->next) {
-		if ((void *)temp_module->module_handle == (void *)mod_handle)
+		if (temp_module->module_handle == mod_handle)
 			break;
 	}
 	if (temp_module == NULL)
@@ -466,8 +441,8 @@ int neb_register_callback(int callback_type, void *mod_handle, int priority, int
 		return NEBERROR_NOMEM;
 
 	new_callback->priority = priority;
-	new_callback->module_handle = (void *)mod_handle;
-	new_callback->callback_func = (void *)callback_func;
+	new_callback->module_handle = mod_handle;
+	new_callback->callback_func = callback_func;
 
 	/* add new function to callback list, sorted by priority (first come, first served for same priority) */
 	new_callback->next = NULL;
@@ -512,7 +487,7 @@ int neb_deregister_module_callbacks(nebmodule *mod) {
 	for (callback_type = 0; callback_type < NEBCALLBACK_NUMITEMS; callback_type++) {
 		for (temp_callback = neb_callback_list[callback_type]; temp_callback != NULL; temp_callback = next_callback) {
 			next_callback = temp_callback->next;
-			if ((void *)temp_callback->module_handle == (void *)mod->module_handle)
+			if (temp_callback->module_handle == mod->module_handle)
 				neb_deregister_callback(callback_type, (int(*)(int, void*))temp_callback->callback_func);
 		}
 
@@ -543,7 +518,7 @@ int neb_deregister_callback(int callback_type, int (*callback_func)(int, void *)
 		next_callback = temp_callback->next;
 
 		/* we found it */
-		if (temp_callback->callback_func == (void *)callback_func)
+		if (temp_callback->callback_func == callback_func)
 			break;
 
 		last_callback = temp_callback;





More information about the icinga-checkins mailing list