[icinga-checkins] icinga.org: icinga-core/dev/core: core/idomod: add nebmodule version/ name check for idomod within core, set module info in idomod, deny to load old idomod.o #2354 #2569

git at icinga.org git at icinga.org
Mon Apr 30 17:58:51 CEST 2012


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Apr 30 16:58:11 2012 +0200

core/idomod: add nebmodule version/name check for idomod within core, set module info in idomod, deny to load old idomod.o #2354 #2569

first off, this will deny and unload modules named "idomod.o" as we have
in 1.6.x
furthermore, the newly introduced 1.7.0 idomod neb module will export
its name plus version with neb_set_module_info. this information can be
parsed from the core after calling nebmodule_init and will allow us to
check the idomod version a bit after being loaded (this might already
connect to ido2db, but we can't get any sooner there). if the idomod
version does not match the core's version, the neb module loader will
bail out. this adds more or less the same version dependency as the
packages do already. could be lowered to minimum version requirements
somehow as well, if idomod_version == icinga_version is set too hard.

refs #2354
refs #2569

---

 Changelog                    |    4 ++++
 base/nebmods.c               |   28 +++++++++++++++++++++++++---
 include/nebmodules.h         |    1 +
 module/idoutils/src/idomod.c |    7 +++++++
 4 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index 9e3ad66..5d13bb1 100644
--- a/Changelog
+++ b/Changelog
@@ -19,6 +19,7 @@ ENHANCEMENTS
 * core: allow empty host groups in service and host dependencies if allow_empty_hostgroup_assignment flag is set (Daniel Wittenberg) #2255 - MF
 * core: fix compatibility problems on solaris 10 (affects core, cgis, ido) (Carl R. Friend) #2292 - MF/RB/TD
 * core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
+* core: add nebmodule version/name check for idomod (this allows future version dependencies) #2569 - MF
 
 * classic ui: Added option for max log entries displayed in showlog.cgi #2145 - RB
 * classic ui: Added config option for status totals in status.cgi #2018 - RB
@@ -41,6 +42,7 @@ ENHANCEMENTS
 * idoutils: add is_in_effect and trigger_time to scheduleddowntime and downtimehistory tables #2539 - MF
 * idoutils: change varchar(255) to TEXT in mysql (not cs and address rfc columns) #2181 - MF
 * idoutils: enhance dbversion table with modified and created columns #2562 - MF
+* idoutils: set module info in idomod, to be checked on neb module load in future versions #2569 - MF
 
 * install: add configure option --with-temp-file=<filepath> to set temp_file for icinga.cfg #2121 - MF
 * install: add --with-plugin-dir to configure for setting the plugins path accordingly #2344 - MF
@@ -86,6 +88,7 @@ FIXES
 * core: remove deprecated code for log_external_commands_user #1619 - MF
 * core: fix scheduled_downtime_depth falsely incremented if in flexible downtime with duration < end-starttime window #2536 - MF
 * core: log error reason when failing to create the status file (Ulf Lange) #2560 - MF
+* core: deny to load idomod.o if detected in old config #2354 #2569 - MF
 
 * classic ui: Fixed status totals are wrong when searching #1524 - RB
 * classic ui: Fixed wrong URLs for status.cgi overview #2173 - RB
@@ -159,6 +162,7 @@ CHANGES
 	** nebstruct and event broker api now passing trigger_time and is_in_effect
 * core: nebcallback for downtime start now happens *after* setting "in effect" attributes #2539
 	** needed to pass is_in_effect and trigger_time to neb modules
+* core: new neb module load error: NEBMODULE_ERROR_IDO_VERSION #2569
 
 * classic ui: Added option for max log entries displayed in showlog.cgi #2145
 	** added new config option "default_num_displayed_log_entries"
diff --git a/base/nebmods.c b/base/nebmods.c
index c69f97d..0899ea0 100644
--- a/base/nebmods.c
+++ b/base/nebmods.c
@@ -184,8 +184,13 @@ int neb_load_module(nebmodule *mod) {
 		return ERROR;
 
 	/* add a compatibility check for 1.7 change of idomod.o -> idomod.so */
-	if (strstr(mod->filename, "idomod.o") != NULL)
-		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: trying to load module '%s' which has been deprecated! Check Changelog and upgrade docs!\n", mod->filename);
+	/* FIXME - drop in 1.8 */
+	if (strstr(mod->filename, "idomod.o") != NULL) {
+		logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: trying to load module '%s' which has been moved to libdir/idomod.so in Icinga 1.7!\n", mod->filename);
+		logit(NSLOG_RUNTIME_ERROR, FALSE, "Check Changelog and upgrade docs to update the broker module entry!\n");
+		neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_IDO_VERSION);
+		return ERROR;
+	}
 
 	/**********
 	   Using dlopen() is great, but a real danger as-is.  The problem with loaded modules is that if you overwrite the original file (e.g. using 'mv'),
@@ -275,7 +280,24 @@ int neb_load_module(nebmodule *mod) {
 		return ERROR;
 	}
 
-	logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' initialized successfully.\n", mod->filename);
+	/* locate the specific modules we know about (idomod, ...) and require minimum version, after calling nebmodule_init, this should be set */
+	/* check if module exports its title? */
+	if(mod->info[NEBMODULE_MODINFO_TITLE] != NULL) {
+		/* check if we are going to load idomod, which we know about */
+		if(strstr(mod->info[NEBMODULE_MODINFO_TITLE], "IDOMOD") != NULL) {
+			/* check if the version complies with the core's version, as they are tied together */
+			if(strcmp(mod->info[NEBMODULE_MODINFO_VERSION], PROGRAM_VERSION) != 0) {
+				logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Module '%s' exports version '%s' different to core version '%s'.  Module will be unloaded.\n", mod->filename, mod->info[NEBMODULE_MODINFO_VERSION], PROGRAM_VERSION);
+				neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_IDO_VERSION);
+				return ERROR;
+			}
+			logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' version '%s' from '%s' initialized successfully.\n", mod->info[NEBMODULE_MODINFO_TITLE], mod->info[NEBMODULE_MODINFO_VERSION], mod->filename);
+		} else {
+			logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' from '%s' initialized successfully.\n", mod->info[NEBMODULE_MODINFO_TITLE], mod->filename);
+		}
+	} else {
+		logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' initialized successfully.\n", mod->filename);
+	}
 
 	/* locate the de-initialization function (may or may not be present) */
 #ifdef USE_LTDL
diff --git a/include/nebmodules.h b/include/nebmodules.h
index 7df5426..719360e 100644
--- a/include/nebmodules.h
+++ b/include/nebmodules.h
@@ -64,6 +64,7 @@
 #define NEBMODULE_ERROR_NO_INIT     3    /* _module_init() function was not found in module */
 #define NEBMODULE_ERROR_BAD_INIT    4    /* _module_init() function returned a bad code */
 #define NEBMODULE_ERROR_API_VERSION 5    /* module version is incompatible with current api */
+#define NEBMODULE_ERROR_IDO_VERSION 6    /* ido module version is incompatible with current core */
 
 
 
diff --git a/module/idoutils/src/idomod.c b/module/idoutils/src/idomod.c
index 56c6be9..07593c4 100644
--- a/module/idoutils/src/idomod.c
+++ b/module/idoutils/src/idomod.c
@@ -101,6 +101,13 @@ int nebmodule_init(int flags, char *args, void *handle) {
 	/* save our handle */
 	idomod_module_handle = handle;
 
+	/* set some info for the core to be checked */
+	neb_set_module_info(idomod_module_handle, NEBMODULE_MODINFO_TITLE, IDOMOD_NAME);
+	neb_set_module_info(idomod_module_handle, NEBMODULE_MODINFO_AUTHOR, "Ethan Galstad, Icinga Development Team");
+	neb_set_module_info(idomod_module_handle, NEBMODULE_MODINFO_VERSION, IDO_VERSION);
+	neb_set_module_info(idomod_module_handle, NEBMODULE_MODINFO_LICENSE, "GPL v2");
+	neb_set_module_info(idomod_module_handle, NEBMODULE_MODINFO_DESC, "Icinga Data Out Module, sends data to socket for ido2db");
+
 	/* log module info to the Icinga log file */
 	snprintf(temp_buffer, sizeof(temp_buffer) - 1, "idomod: %s %s (%s) %s", IDOMOD_NAME, IDO_VERSION, IDO_DATE, IDO_COPYRIGHT);
 	temp_buffer[sizeof(temp_buffer)-1] = '\x0';





More information about the icinga-checkins mailing list