[Nagios-checkins] SF.net SVN: nagios:[2115] nagioscore/trunk

ageric at users.sourceforge.net ageric at users.sourceforge.net
Sun Aug 26 20:11:40 UTC 2012


Revision: 2115
          http://nagios.svn.sourceforge.net/nagios/?rev=2115&view=rev
Author:   ageric
Date:     2012-08-26 20:11:40 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
Use one-time allocation of object tables

It makes very little sense to allocate memory for one object at a time
as we create them in-core from configuration when we know early on
how many objects there will be. With this patch, we pre-allocate a
continuous block of memory, just large enough to hold all objects, and
then take our new objects from that store as we go along and create
them, making error handling in the 'add' objects even more trivial
than it used to be.

We keep the 'next' pointers for now though. They're all over the
place and I assume quite a few modules use them too.

While at it, we make sure the object lists are available from the
entire code and remove their explicit declarations in randomf files
as a general cleanup.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/base/checks.c
    nagioscore/trunk/base/commands.c
    nagioscore/trunk/base/config.c
    nagioscore/trunk/base/events.c
    nagioscore/trunk/base/flapping.c
    nagioscore/trunk/base/logging.c
    nagioscore/trunk/base/nagios.c
    nagioscore/trunk/base/notifications.c
    nagioscore/trunk/base/utils.c
    nagioscore/trunk/cgi/avail.c
    nagioscore/trunk/cgi/config.c
    nagioscore/trunk/cgi/histogram.c
    nagioscore/trunk/cgi/outages.c
    nagioscore/trunk/cgi/status.c
    nagioscore/trunk/cgi/statusmap.c
    nagioscore/trunk/cgi/statuswml.c
    nagioscore/trunk/cgi/statuswrl.c
    nagioscore/trunk/cgi/summary.c
    nagioscore/trunk/cgi/tac.c
    nagioscore/trunk/cgi/trends.c
    nagioscore/trunk/common/macros.c
    nagioscore/trunk/common/objects.c
    nagioscore/trunk/include/objects.h
    nagioscore/trunk/t-tap/test_nagios_config.c
    nagioscore/trunk/t-tap/test_timeperiods.c
    nagioscore/trunk/xdata/xodtemplate.c
    nagioscore/trunk/xdata/xrddefault.c
    nagioscore/trunk/xdata/xsddefault.c

Modified: nagioscore/trunk/base/checks.c
===================================================================
--- nagioscore/trunk/base/checks.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/checks.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -82,11 +82,6 @@
 
 extern squeue_t *nagios_squeue;
 
-extern host              *host_list;
-extern service           *service_list;
-extern servicedependency *servicedependency_list;
-extern hostdependency    *hostdependency_list;
-
 extern unsigned long   next_event_id;
 extern unsigned long   next_problem_id;
 

Modified: nagioscore/trunk/base/commands.c
===================================================================
--- nagioscore/trunk/base/commands.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/commands.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -54,9 +54,6 @@
 extern command  *global_host_event_handler_ptr;
 extern command  *global_service_event_handler_ptr;
 
-extern host     *host_list;
-extern service  *service_list;
-
 /******************************************************************/
 /****************** EXTERNAL COMMAND PROCESSING *******************/
 /******************************************************************/

Modified: nagioscore/trunk/base/config.c
===================================================================
--- nagioscore/trunk/base/config.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/config.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -178,22 +178,6 @@
 extern int      date_format;
 extern char     *use_timezone;
 
-extern contact		*contact_list;
-extern contactgroup	*contactgroup_list;
-extern host             *host_list;
-extern hostgroup	*hostgroup_list;
-extern service          *service_list;
-extern servicegroup     *servicegroup_list;
-extern command          *command_list;
-extern timeperiod       *timeperiod_list;
-extern serviceescalation *serviceescalation_list;
-extern servicedependency *servicedependency_list;
-extern hostdependency   *hostdependency_list;
-extern hostescalation   *hostescalation_list;
-
-extern host		**host_hashlist;
-extern service		**service_hashlist;
-
 extern unsigned long    max_check_result_file_age;
 
 extern char             *debug_file;

Modified: nagioscore/trunk/base/events.c
===================================================================
--- nagioscore/trunk/base/events.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/events.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -75,9 +75,6 @@
 
 squeue_t *nagios_squeue = NULL; /* our scheduling queue */
 
-extern host     *host_list;
-extern service  *service_list;
-
 sched_info scheduling_info;
 extern iobroker_set *nagios_iobs;
 

Modified: nagioscore/trunk/base/flapping.c
===================================================================
--- nagioscore/trunk/base/flapping.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/flapping.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -39,9 +39,6 @@
 extern double   low_host_flap_threshold;
 extern double   high_host_flap_threshold;
 
-extern host     *host_list;
-extern service  *service_list;
-
 extern unsigned long    modified_host_process_attributes;
 extern unsigned long    modified_service_process_attributes;
 
@@ -486,8 +483,7 @@
 
 /* enables flap detection on a program wide basis */
 void enable_flap_detection_routines(void) {
-	host *temp_host = NULL;
-	service *temp_service = NULL;
+	int i;
 	unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED;
 
 	log_debug_info(DEBUGL_FUNCTIONS, 0, "enable_flap_detection_routines()\n");
@@ -512,20 +508,18 @@
 	update_program_status(FALSE);
 
 	/* check for flapping */
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next)
-		check_for_host_flapping(temp_host, FALSE, FALSE, TRUE);
-	for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next)
-		check_for_service_flapping(temp_service, FALSE, TRUE);
+	for(i = 0; i < num_objects.hosts; i++)
+		check_for_host_flapping(&host_list[i], FALSE, FALSE, TRUE);
+	for(i = 0; i < num_objects.services; i++)
+		check_for_service_flapping(&service_list[i], FALSE, TRUE);
 
-	return;
 	}
 
 
 
 /* disables flap detection on a program wide basis */
 void disable_flap_detection_routines(void) {
-	host *temp_host = NULL;
-	service *temp_service = NULL;
+	unsigned int i;
 	unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED;
 
 	log_debug_info(DEBUGL_FUNCTIONS, 0, "disable_flap_detection_routines()\n");
@@ -550,10 +544,10 @@
 	update_program_status(FALSE);
 
 	/* handle the details... */
-	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next)
-		handle_host_flap_detection_disabled(temp_host);
-	for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next)
-		handle_service_flap_detection_disabled(temp_service);
+	for(i = 0; i < num_objects.hosts; i++)
+		handle_host_flap_detection_disabled(&host_list[i]);
+	for(i = 0; i < num_objects.services; i++)
+		handle_service_flap_detection_disabled(&service_list[i]);
 
 	return;
 	}

Modified: nagioscore/trunk/base/logging.c
===================================================================
--- nagioscore/trunk/base/logging.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/logging.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -31,9 +31,6 @@
 extern char	*log_file;
 extern char	*log_archive_path;
 
-extern host     *host_list;
-extern service  *service_list;
-
 extern int	use_syslog;
 extern int      log_service_retries;
 extern int      log_initial_states;

Modified: nagioscore/trunk/base/nagios.c
===================================================================
--- nagioscore/trunk/base/nagios.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/nagios.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -231,13 +231,6 @@
 int             command_file_created = FALSE;
 
 
-extern contact	       *contact_list;
-extern contactgroup    *contactgroup_list;
-extern hostgroup       *hostgroup_list;
-extern command         *command_list;
-extern timeperiod      *timeperiod_list;
-extern serviceescalation *serviceescalation_list;
-
 notification    *notification_list;
 
 check_result    check_result_info;

Modified: nagioscore/trunk/base/notifications.c
===================================================================
--- nagioscore/trunk/base/notifications.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/notifications.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -31,8 +31,6 @@
 #include "../include/workers.h"
 
 extern notification    *notification_list;
-extern contact         *contact_list;
-
 extern time_t          program_start;
 
 extern int             interval_length;

Modified: nagioscore/trunk/base/utils.c
===================================================================
--- nagioscore/trunk/base/utils.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/base/utils.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -215,9 +215,6 @@
 
 extern int      date_format;
 
-extern host             *host_list;
-extern service          *service_list;
-extern servicegroup     *servicegroup_list;
 extern notification     *notification_list;
 
 extern squeue_t *nagios_squeue;

Modified: nagioscore/trunk/cgi/avail.c
===================================================================
--- nagioscore/trunk/cgi/avail.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/avail.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -35,12 +35,6 @@
 extern char url_images_path[MAX_FILENAME_LENGTH];
 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
 
-extern host      *host_list;
-extern hostgroup *hostgroup_list;
-extern servicegroup *servicegroup_list;
-extern service   *service_list;
-extern timeperiod *timeperiod_list;
-
 extern int       log_rotation_method;
 
 #ifndef max

Modified: nagioscore/trunk/cgi/config.c
===================================================================
--- nagioscore/trunk/cgi/config.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/config.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -37,20 +37,6 @@
 extern char   url_logo_images_path[MAX_FILENAME_LENGTH];
 extern char   url_stylesheets_path[MAX_FILENAME_LENGTH];
 
-extern host *host_list;
-extern service *service_list;
-extern hostgroup *hostgroup_list;
-extern servicegroup *servicegroup_list;
-extern contactgroup *contactgroup_list;
-extern command *command_list;
-extern timeperiod *timeperiod_list;
-extern contact *contact_list;
-extern servicedependency *servicedependency_list;
-extern serviceescalation *serviceescalation_list;
-extern hostdependency *hostdependency_list;
-extern hostescalation *hostescalation_list;
-
-
 #define DISPLAY_NONE                     0
 #define DISPLAY_HOSTS                    1
 #define DISPLAY_HOSTGROUPS               2

Modified: nagioscore/trunk/cgi/histogram.c
===================================================================
--- nagioscore/trunk/cgi/histogram.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/histogram.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -130,11 +130,6 @@
 
 extern int     log_rotation_method;
 
-extern host *host_list;
-extern service *service_list;
-
-
-
 authdata current_authdata;
 
 

Modified: nagioscore/trunk/cgi/outages.c
===================================================================
--- nagioscore/trunk/cgi/outages.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/outages.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -32,8 +32,6 @@
 extern int              refresh_rate;
 extern time_t		program_start;
 
-extern host *host_list;
-extern service *service_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 

Modified: nagioscore/trunk/cgi/status.c
===================================================================
--- nagioscore/trunk/cgi/status.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/status.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -57,10 +57,6 @@
 
 extern int enable_splunk_integration;
 
-extern host *host_list;
-extern service *service_list;
-extern hostgroup *hostgroup_list;
-extern servicegroup *servicegroup_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 

Modified: nagioscore/trunk/cgi/statusmap.c
===================================================================
--- nagioscore/trunk/cgi/statusmap.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/statusmap.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -54,9 +54,6 @@
 extern char url_logo_images_path[MAX_FILENAME_LENGTH];
 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
 
-extern host *host_list;
-extern hostgroup *hostgroup_list;
-extern service *service_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 

Modified: nagioscore/trunk/cgi/statuswml.c
===================================================================
--- nagioscore/trunk/cgi/statuswml.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/statuswml.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -32,9 +32,6 @@
 
 extern char main_config_file[MAX_FILENAME_LENGTH];
 
-extern host *host_list;
-extern hostgroup *hostgroup_list;
-extern service *service_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 

Modified: nagioscore/trunk/cgi/statuswrl.c
===================================================================
--- nagioscore/trunk/cgi/statuswrl.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/statuswrl.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -41,9 +41,6 @@
 
 extern char *statuswrl_include;
 
-extern host *host_list;
-extern service *service_list;
-
 extern int default_statuswrl_layout_method;
 
 

Modified: nagioscore/trunk/cgi/summary.c
===================================================================
--- nagioscore/trunk/cgi/summary.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/summary.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -35,12 +35,6 @@
 extern char url_images_path[MAX_FILENAME_LENGTH];
 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
 
-extern host *host_list;
-extern hostgroup *hostgroup_list;
-extern service *service_list;
-extern servicegroup *servicegroup_list;
-
-
 /* output types */
 #define HTML_OUTPUT             0
 #define CSV_OUTPUT              1

Modified: nagioscore/trunk/cgi/tac.c
===================================================================
--- nagioscore/trunk/cgi/tac.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/tac.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -59,7 +59,6 @@
 extern char *host_unreachable_sound;
 extern char *normal_sound;
 
-extern host *host_list;
 extern hoststatus *hoststatus_list;
 extern servicestatus *servicestatus_list;
 

Modified: nagioscore/trunk/cgi/trends.c
===================================================================
--- nagioscore/trunk/cgi/trends.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/cgi/trends.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -44,9 +44,6 @@
 
 extern int     log_rotation_method;
 
-extern host *host_list;
-extern service *service_list;
-
 /* archived state types */
 #define AS_CURRENT_STATE        -1   /* special case for initial assumed state */
 #define AS_NO_DATA		0

Modified: nagioscore/trunk/common/macros.c
===================================================================
--- nagioscore/trunk/common/macros.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/common/macros.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -39,10 +39,6 @@
 
 extern char     *illegal_output_chars;
 
-extern host             *host_list;
-extern service          *service_list;
-extern servicegroup     *servicegroup_list;
-
 char *macro_x_names[MACRO_X_COUNT]; /* the macro names */
 char *macro_user[MAX_USER_MACROS]; /* $USERx$ macros */
 

Modified: nagioscore/trunk/common/objects.c
===================================================================
--- nagioscore/trunk/common/objects.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/common/objects.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -45,20 +45,21 @@
  * Dependencies are attached to the dependent end of the object chain.
  */
 dkhash_table *object_hash_tables[NUM_OBJECT_SKIPLISTS];
-host            *host_list = NULL, *host_list_tail = NULL;
-service         *service_list = NULL, *service_list_tail = NULL;
-contact		*contact_list = NULL, *contact_list_tail = NULL;
-contactgroup	*contactgroup_list = NULL, *contactgroup_list_tail = NULL;
-hostgroup	*hostgroup_list = NULL, *hostgroup_list_tail = NULL;
-servicegroup    *servicegroup_list = NULL, *servicegroup_list_tail = NULL;
-command         *command_list = NULL, *command_list_tail = NULL;
-timeperiod      *timeperiod_list = NULL, *timeperiod_list_tail = NULL;
-serviceescalation *serviceescalation_list = NULL, *serviceescalation_list_tail = NULL;
-servicedependency *servicedependency_list = NULL, *servicedependency_list_tail = NULL;
-hostdependency  *hostdependency_list = NULL, *hostdependency_list_tail = NULL;
-hostescalation  *hostescalation_list = NULL, *hostescalation_list_tail = NULL;
 
+command *command_list = NULL;
+timeperiod *timeperiod_list = NULL;
+host *host_list = NULL;
+service *service_list = NULL;
+contact *contact_list = NULL;
+hostgroup *hostgroup_list = NULL;
+servicegroup *servicegroup_list = NULL;
+contactgroup *contactgroup_list = NULL;
+hostescalation *hostescalation_list = NULL;
+hostdependency *hostdependency_list = NULL;
+serviceescalation *serviceescalation_list = NULL;
+servicedependency *servicedependency_list = NULL;
 
+
 struct object_count num_objects;
 
 #ifdef NSCORE
@@ -139,6 +140,23 @@
 /**************** OBJECT ADDITION FUNCTIONS ***********************/
 /******************************************************************/
 
+static int create_object_table(const char *name, unsigned int elems, unsigned int size, void **ptr)
+{
+	void *ret;
+	if (!elems)
+		return OK;
+	ret = calloc(elems, size);
+	if (!ret) {
+		logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Failed to allocate %s table with %u elements\n", name, elems);
+		return ERROR;
+		}
+	*ptr = ret;
+	return OK;
+}
+
+#define mktable(name, id) \
+	create_object_table(#name, ocount[id], sizeof(name), (void **)&name##_list)
+
 /* ocount is an array with NUM_OBJECT_TYPES members */
 int create_object_tables(unsigned int *ocount)
 {
@@ -154,8 +172,39 @@
 		}
 	}
 
+	/*
+	 * errors here will always lead to an early exit, so there's no need
+	 * to free() successful allocs when later ones fail
+	 */
+	if (mktable(timeperiod, TIMEPERIOD_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(command, COMMAND_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(host, HOST_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(service, SERVICE_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(contact, CONTACT_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(hostgroup, HOSTGROUP_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(servicegroup, SERVICEGROUP_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(contactgroup, CONTACTGROUP_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(hostescalation, HOSTESCALATION_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(hostdependency, HOSTDEPENDENCY_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(serviceescalation, SERVICEESCALATION_SKIPLIST) != OK)
+		return ERROR;
+	if (mktable(servicedependency, SERVICEDEPENDENCY_SKIPLIST) != OK)
+		return ERROR;
+
+	return OK;
 }
 
+
 /* add a new timeperiod to the list in memory */
 timeperiod *add_timeperiod(char *name, char *alias) {
 	timeperiod *new_timeperiod = NULL;
@@ -167,13 +216,11 @@
 		return NULL;
 		}
 
-	/* allocate memory for the new timeperiod */
-	if((new_timeperiod = calloc(1, sizeof(timeperiod))) == NULL)
-		return NULL;
+	new_timeperiod = &timeperiod_list[num_objects.timeperiods];
 
 	/* copy string vars */
 	if((new_timeperiod->name = (char *)strdup(name)) == NULL)
-		result = ERROR;
+		return NULL;
 	if((new_timeperiod->alias = (char *)strdup(alias)) == NULL)
 		result = ERROR;
 
@@ -199,22 +246,12 @@
 	if(result == ERROR) {
 		my_free(new_timeperiod->alias);
 		my_free(new_timeperiod->name);
-		my_free(new_timeperiod);
 		return NULL;
 		}
 
-	/* timeperiods are registered alphabetically, so add new items to tail of list */
-	if(timeperiod_list == NULL) {
-		timeperiod_list = new_timeperiod;
-		timeperiod_list_tail = timeperiod_list;
-		}
-	else {
-		timeperiod_list_tail->next = new_timeperiod;
-		timeperiod_list_tail = new_timeperiod;
-		}
-
 	new_timeperiod->id = num_objects.timeperiods++;
-
+	if(new_timeperiod->id)
+		timeperiod_list[new_timeperiod->id - 1].next = new_timeperiod;
 	return new_timeperiod;
 	}
 
@@ -386,9 +423,7 @@
 		return NULL;
 		}
 
-	/* allocate memory for a new host */
-	if((new_host = (host *)calloc(1, sizeof(host))) == NULL)
-		return NULL;
+	new_host = &host_list[num_objects.hosts];
 
 	/* duplicate string vars */
 	if((new_host->name = (char *)strdup(name)) == NULL)
@@ -594,22 +629,12 @@
 		my_free(new_host->alias);
 		my_free(new_host->display_name);
 		my_free(new_host->name);
-		my_free(new_host);
 		return NULL;
 		}
 
-	/* hosts are sorted alphabetically, so add new items to tail of list */
-	if(host_list == NULL) {
-		host_list = new_host;
-		host_list_tail = host_list;
-		}
-	else {
-		host_list_tail->next = new_host;
-		host_list_tail = new_host;
-		}
-
 	new_host->id = num_objects.hosts++;
-
+	if(new_host->id)
+		host_list[new_host->id - 1].next = new_host;
 	return new_host;
 	}
 
@@ -764,9 +789,7 @@
 		return NULL;
 		}
 
-	/* allocate memory */
-	if((new_hostgroup = (hostgroup *)calloc(1, sizeof(hostgroup))) == NULL)
-		return NULL;
+	new_hostgroup = &hostgroup_list[num_objects.hostgroups];
 
 	/* duplicate vars */
 	if((new_hostgroup->group_name = (char *)strdup(name)) == NULL)
@@ -808,21 +831,12 @@
 	if(result == ERROR) {
 		my_free(new_hostgroup->alias);
 		my_free(new_hostgroup->group_name);
-		my_free(new_hostgroup);
 		return NULL;
 		}
 
-	/* hostgroups are sorted alphabetically, so add new items to tail of list */
-	if(hostgroup_list == NULL) {
-		hostgroup_list = new_hostgroup;
-		hostgroup_list_tail = hostgroup_list;
-		}
-	else {
-		hostgroup_list_tail->next = new_hostgroup;
-		hostgroup_list_tail = new_hostgroup;
-		}
-
 	new_hostgroup->id = num_objects.hostgroups++;
+	if(new_hostgroup->id)
+		hostgroup_list[new_hostgroup->id - 1].next = new_hostgroup;
 	return new_hostgroup;
 	}
 
@@ -893,9 +907,7 @@
 		return NULL;
 		}
 
-	/* allocate memory */
-	if((new_servicegroup = (servicegroup *)calloc(1, sizeof(servicegroup))) == NULL)
-		return NULL;
+	new_servicegroup = &servicegroup_list[num_objects.servicegroups];
 
 	/* duplicate vars */
 	if((new_servicegroup->group_name = (char *)strdup(name)) == NULL)
@@ -941,17 +953,9 @@
 		return NULL;
 		}
 
-	/* servicegroups are sorted alphabetically, so add new items to tail of list */
-	if(servicegroup_list == NULL) {
-		servicegroup_list = new_servicegroup;
-		servicegroup_list_tail = servicegroup_list;
-		}
-	else {
-		servicegroup_list_tail->next = new_servicegroup;
-		servicegroup_list_tail = new_servicegroup;
-		}
-
 	new_servicegroup->id = num_objects.servicegroups++;
+	if(new_servicegroup->id)
+		servicegroup_list[new_servicegroup->id - 1].next = new_servicegroup;
 	return new_servicegroup;
 	}
 
@@ -1048,11 +1052,9 @@
 		return NULL;
 		}
 
-	/* allocate memory for a new contact */
-	if((new_contact = (contact *)calloc(1, sizeof(contact))) == NULL)
-		return NULL;
 
-	/* duplicate vars, but assign what we can */
+	new_contact = &contact_list[num_objects.contacts];
+
 	new_contact->host_notification_period = htp ? htp->name : NULL;
 	new_contact->service_notification_period = stp ? stp->name : NULL;
 #ifndef NSCGI
@@ -1138,17 +1140,9 @@
 		return NULL;
 		}
 
-	/* contacts are sorted alphabetically, so add new items to tail of list */
-	if(contact_list == NULL) {
-		contact_list = new_contact;
-		contact_list_tail = contact_list;
-		}
-	else {
-		contact_list_tail->next = new_contact;
-		contact_list_tail = new_contact;
-		}
-
 	new_contact->id = num_objects.contacts++;
+	if(new_contact->id)
+		contact_list[new_contact->id - 1].next = new_contact;
 	return new_contact;
 	}
 
@@ -1243,9 +1237,7 @@
 		return NULL;
 		}
 
-	/* allocate memory for a new contactgroup entry */
-	if((new_contactgroup = calloc(1, sizeof(contactgroup))) == NULL)
-		return NULL;
+	new_contactgroup = &contactgroup_list[num_objects.contactgroups];
 
 	/* duplicate vars */
 	if((new_contactgroup->group_name = (char *)strdup(name)) == NULL)
@@ -1275,21 +1267,12 @@
 	if(result == ERROR) {
 		my_free(new_contactgroup->alias);
 		my_free(new_contactgroup->group_name);
-		my_free(new_contactgroup);
 		return NULL;
 		}
 
-	/* contactgroups are sorted alphabetically, so add new items to tail of list */
-	if(contactgroup_list == NULL) {
-		contactgroup_list = new_contactgroup;
-		contactgroup_list_tail = contactgroup_list;
-		}
-	else {
-		contactgroup_list_tail->next = new_contactgroup;
-		contactgroup_list_tail = new_contactgroup;
-		}
-
 	new_contactgroup->id = num_objects.contactgroups++;
+	if(new_contactgroup->id)
+		contactgroup_list[new_contactgroup->id - 1].next = new_contactgroup;
 	return new_contactgroup;
 	}
 
@@ -1373,8 +1356,7 @@
 		}
 
 	/* allocate memory */
-	if((new_service = (service *)calloc(1, sizeof(service))) == NULL)
-		return NULL;
+	new_service = &service_list[num_objects.services];
 
 	/* duplicate vars, but assign what we can */
 #ifndef NSCGI
@@ -1539,17 +1521,10 @@
 		}
 
 	add_service_link_to_host(h, new_service);
-	/* services are sorted alphabetically, so add new items to tail of list */
-	if(service_list == NULL) {
-		service_list = new_service;
-		service_list_tail = service_list;
-		}
-	else {
-		service_list_tail->next = new_service;
-		service_list_tail = new_service;
-		}
 
 	new_service->id = num_objects.services++;
+	if(new_service->id)
+		service_list[new_service->id - 1].next = new_service;
 	return new_service;
 	}
 
@@ -1611,12 +1586,11 @@
 		}
 
 	/* allocate memory for the new command */
-	if((new_command = (command *)calloc(1, sizeof(command))) == NULL)
-		return NULL;
+	new_command = &command_list[num_objects.commands];
 
 	/* duplicate vars */
 	if((new_command->name = (char *)strdup(name)) == NULL)
-		result = ERROR;
+		return NULL;
 	if((new_command->command_line = (char *)strdup(value)) == NULL)
 		result = ERROR;
 
@@ -1642,21 +1616,12 @@
 	if(result == ERROR) {
 		my_free(new_command->command_line);
 		my_free(new_command->name);
-		my_free(new_command);
 		return NULL;
 		}
 
-	/* commands are sorted alphabetically, so add new items to tail of list */
-	if(command_list == NULL) {
-		command_list = new_command;
-		command_list_tail = command_list;
-		}
-	else {
-		command_list_tail->next = new_command;
-		command_list_tail = new_command;
-		}
-
 	new_command->id = num_objects.commands++;
+	if(new_command->id)
+		command_list[new_command->id - 1].next = new_command;
 	return new_command;
 	}
 
@@ -1688,10 +1653,11 @@
 	if((new_serviceescalation = calloc(1, sizeof(serviceescalation))) == NULL)
 		return NULL;
 
+	new_serviceescalation = &serviceescalation_list[num_objects.serviceescalations];
+
 	if(add_object_to_objectlist(&svc->escalation_list, new_serviceescalation) != OK) {
 		logit(NSLOG_CONFIG_ERROR, TRUE, "Could not add escalation to service '%s' on host '%s'\n",
 			  svc->host_name, svc->description);
-		my_free(new_serviceescalation);
 		return NULL;
 		}
 
@@ -1713,17 +1679,9 @@
 	new_serviceescalation->escalate_on_unknown = (escalate_on_unknown > 0) ? TRUE : FALSE;
 	new_serviceescalation->escalate_on_critical = (escalate_on_critical > 0) ? TRUE : FALSE;
 
-	/* service escalations are sorted alphabetically, so add new items to tail of list */
-	if(serviceescalation_list == NULL) {
-		serviceescalation_list = new_serviceescalation;
-		serviceescalation_list_tail = serviceescalation_list;
-		}
-	else {
-		serviceescalation_list_tail->next = new_serviceescalation;
-		serviceescalation_list_tail = new_serviceescalation;
-		}
-
 	new_serviceescalation->id = num_objects.serviceescalations++;
+	if(new_serviceescalation->id)
+		serviceescalation_list[new_serviceescalation->id - 1].next = new_serviceescalation;
 	return new_serviceescalation;
 	}
 
@@ -1777,7 +1735,6 @@
 	servicedependency *new_servicedependency = NULL;
 	service *parent, *child;
 	timeperiod *tp = NULL;
-	int result = OK;
 
 	/* make sure we have what we need */
 	parent = find_service(host_name, service_description);
@@ -1799,8 +1756,7 @@
 		}
 
 	/* allocate memory for a new service dependency entry */
-	if((new_servicedependency = (servicedependency *)calloc(1, sizeof(servicedependency))) == NULL)
-		return NULL;
+	new_servicedependency = &servicedependency_list[num_objects.servicedependencies];
 
 #ifndef NSCGI
 	/*
@@ -1810,11 +1766,11 @@
 	 */
 	if(dependency_type == NOTIFICATION_DEPENDENCY) {
 		if(add_object_to_objectlist(&child->notify_deps, new_servicedependency) != OK)
-			result = ERROR;
+			return NULL;
 		}
 	else {
 		if(add_object_to_objectlist(&child->exec_deps, new_servicedependency) != OK)
-			result = ERROR;
+			return NULL;
 		}
 	new_servicedependency->dependent_service_ptr = child;
 	new_servicedependency->master_service_ptr = parent;
@@ -1837,23 +1793,9 @@
 	new_servicedependency->fail_on_critical = (fail_on_critical == 1) ? TRUE : FALSE;
 	new_servicedependency->fail_on_pending = (fail_on_pending == 1) ? TRUE : FALSE;
 
-	/* handle errors */
-	if(result == ERROR) {
-		my_free(new_servicedependency);
-		return NULL;
-		}
-
-	/* service dependencies are sorted alphabetically, so add new items to tail of list */
-	if(servicedependency_list == NULL) {
-		servicedependency_list = new_servicedependency;
-		servicedependency_list_tail = servicedependency_list;
-		}
-	else {
-		servicedependency_list_tail->next = new_servicedependency;
-		servicedependency_list_tail = new_servicedependency;
-		}
-
 	new_servicedependency->id = num_objects.servicedependencies++;
+	if(new_servicedependency->id)
+		servicedependency_list[new_servicedependency->id - 1].next = new_servicedependency;
 	return new_servicedependency;
 	}
 
@@ -1884,9 +1826,7 @@
 		return NULL ;
 	}
 
-	/* allocate memory for a new host dependency entry */
-	if((new_hostdependency = (hostdependency *)calloc(1, sizeof(hostdependency))) == NULL)
-		return NULL;
+	new_hostdependency = &hostdependency_list[num_objects.hostdependencies];
 
 #ifndef NSCGI
 	if(dependency_type == NOTIFICATION_DEPENDENCY) {
@@ -1922,17 +1862,9 @@
 		return NULL;
 		}
 
-	/* host dependencies are sorted alphabetically, so add new items to tail of list */
-	if(hostdependency_list == NULL) {
-		hostdependency_list = new_hostdependency;
-		hostdependency_list_tail = hostdependency_list;
-		}
-	else {
-		hostdependency_list_tail->next = new_hostdependency;
-		hostdependency_list_tail = new_hostdependency;
-		}
-
 	new_hostdependency->id = num_objects.hostdependencies++;
+	if(new_hostdependency->id)
+		hostdependency_list[new_hostdependency->id - 1].next = new_hostdependency;
 	return new_hostdependency;
 	}
 
@@ -1958,14 +1890,12 @@
 			  escalation_period, host_name);
 		return NULL;
 		}
-	/* allocate memory for a new host escalation entry */
-	if((new_hostescalation = calloc(1, sizeof(hostescalation))) == NULL)
-		return NULL;
 
+	new_hostescalation = &hostescalation_list[num_objects.hostescalations];
+
 	/* add the escalation to its host */
 	if (add_object_to_objectlist(&h->escalation_list, new_hostescalation) != OK) {
 		logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not add hostescalation to host '%s'\n", host_name);
-		my_free(new_hostescalation);
 		return NULL;
 		}
 
@@ -1982,17 +1912,9 @@
 	new_hostescalation->escalate_on_down = (escalate_on_down > 0) ? TRUE : FALSE;
 	new_hostescalation->escalate_on_unreachable = (escalate_on_unreachable > 0) ? TRUE : FALSE;
 
-	/* host escalations are sorted alphabetically, so add new items to tail of list */
-	if(hostescalation_list == NULL) {
-		hostescalation_list = new_hostescalation;
-		hostescalation_list_tail = hostescalation_list;
-		}
-	else {
-		hostescalation_list_tail->next = new_hostescalation;
-		hostescalation_list_tail = new_hostescalation;
-		}
-
 	new_hostescalation->id = num_objects.hostescalations++;
+	if(new_hostescalation->id)
+		hostescalation_list[new_hostescalation->id - 1].next = new_hostescalation;
 	return new_hostescalation;
 	}
 
@@ -2602,48 +2524,24 @@
 
 /* free all allocated memory for objects */
 int free_object_data(void) {
-	timeperiod *this_timeperiod = NULL;
-	timeperiod *next_timeperiod = NULL;
 	daterange *this_daterange = NULL;
 	daterange *next_daterange = NULL;
 	timerange *this_timerange = NULL;
 	timerange *next_timerange = NULL;
 	timeperiodexclusion *this_timeperiodexclusion = NULL;
 	timeperiodexclusion *next_timeperiodexclusion = NULL;
-	host *this_host = NULL;
-	host *next_host = NULL;
 	hostsmember *this_hostsmember = NULL;
 	hostsmember *next_hostsmember = NULL;
-	hostgroup *this_hostgroup = NULL;
-	hostgroup *next_hostgroup = NULL;
-	servicegroup *this_servicegroup = NULL;
-	servicegroup *next_servicegroup = NULL;
 	servicesmember *this_servicesmember = NULL;
 	servicesmember *next_servicesmember = NULL;
-	contact	*this_contact = NULL;
-	contact *next_contact = NULL;
-	contactgroup *this_contactgroup = NULL;
-	contactgroup *next_contactgroup = NULL;
 	contactsmember *this_contactsmember = NULL;
 	contactsmember *next_contactsmember = NULL;
 	contactgroupsmember *this_contactgroupsmember = NULL;
 	contactgroupsmember *next_contactgroupsmember = NULL;
 	customvariablesmember *this_customvariablesmember = NULL;
 	customvariablesmember *next_customvariablesmember = NULL;
-	service *this_service = NULL;
-	service *next_service = NULL;
-	command *this_command = NULL;
-	command *next_command = NULL;
 	commandsmember *this_commandsmember = NULL;
 	commandsmember *next_commandsmember = NULL;
-	serviceescalation *this_serviceescalation = NULL;
-	serviceescalation *next_serviceescalation = NULL;
-	servicedependency *this_servicedependency = NULL;
-	servicedependency *next_servicedependency = NULL;
-	hostdependency *this_hostdependency = NULL;
-	hostdependency *next_hostdependency = NULL;
-	hostescalation *this_hostescalation = NULL;
-	hostescalation *next_hostescalation = NULL;
 	register int x = 0;
 	register int i = 0;
 
@@ -2659,8 +2557,8 @@
 	}
 
 	/**** free memory for the timeperiod list ****/
-	this_timeperiod = timeperiod_list;
-	while(this_timeperiod != NULL) {
+	for (i = 0; i < num_objects.timeperiods; i++) {
+		timeperiod *this_timeperiod = &timeperiod_list[i];
 
 		/* free the exception time ranges contained in this timeperiod */
 		for(x = 0; x < DATERANGE_TYPES; x++) {
@@ -2691,23 +2589,18 @@
 			my_free(this_timeperiodexclusion);
 			}
 
-		next_timeperiod = this_timeperiod->next;
 		my_free(this_timeperiod->name);
 		my_free(this_timeperiod->alias);
-		my_free(this_timeperiod);
-		this_timeperiod = next_timeperiod;
 		}
 
 	/* reset pointers */
-	timeperiod_list = NULL;
+	my_free(timeperiod_list);
 
 
 	/**** free memory for the host list ****/
-	this_host = host_list;
-	while(this_host != NULL) {
+	for (i = 0; i < num_objects.hosts; i++) {
+		host *this_host = &host_list[i];
 
-		next_host = this_host->next;
-
 		/* free memory for parent hosts */
 		this_hostsmember = this_host->parent_hosts;
 		while(this_hostsmember != NULL) {
@@ -2783,17 +2676,15 @@
 		my_free(this_host->icon_image_alt);
 		my_free(this_host->vrml_image);
 		my_free(this_host->statusmap_image);
-		my_free(this_host);
-		this_host = next_host;
 		}
 
 	/* reset pointers */
-	host_list = NULL;
+	my_free(host_list);
 
 
 	/**** free memory for the host group list ****/
-	this_hostgroup = hostgroup_list;
-	while(this_hostgroup != NULL) {
+	for (i = 0; i < num_objects.hostgroups; i++) {
+		hostgroup *this_hostgroup = &hostgroup_list[i];
 
 		/* free memory for the group members */
 		this_hostsmember = this_hostgroup->members;
@@ -2804,23 +2695,19 @@
 			this_hostsmember = next_hostsmember;
 			}
 
-		next_hostgroup = this_hostgroup->next;
 		my_free(this_hostgroup->group_name);
 		my_free(this_hostgroup->alias);
 		my_free(this_hostgroup->notes);
 		my_free(this_hostgroup->notes_url);
 		my_free(this_hostgroup->action_url);
-		my_free(this_hostgroup);
-		this_hostgroup = next_hostgroup;
 		}
 
 	/* reset pointers */
-	hostgroup_list = NULL;
+	my_free(hostgroup_list);
 
-
 	/**** free memory for the service group list ****/
-	this_servicegroup = servicegroup_list;
-	while(this_servicegroup != NULL) {
+	for (i = 0; i < num_objects.servicegroups; i++) {
+		servicegroup *this_servicegroup = &servicegroup_list[i];
 
 		/* free memory for the group members */
 		this_servicesmember = this_servicegroup->members;
@@ -2832,23 +2719,19 @@
 			this_servicesmember = next_servicesmember;
 			}
 
-		next_servicegroup = this_servicegroup->next;
 		my_free(this_servicegroup->group_name);
 		my_free(this_servicegroup->alias);
 		my_free(this_servicegroup->notes);
 		my_free(this_servicegroup->notes_url);
 		my_free(this_servicegroup->action_url);
-		my_free(this_servicegroup);
-		this_servicegroup = next_servicegroup;
 		}
 
 	/* reset pointers */
-	servicegroup_list = NULL;
+	my_free(servicegroup_list);
 
-
 	/**** free memory for the contact list ****/
-	this_contact = contact_list;
-	while(this_contact != NULL) {
+	for (i = 0; i < num_objects.contacts; i++) {
+		contact *this_contact = &contact_list[i];
 
 		/* free memory for the host notification commands */
 		this_commandsmember = this_contact->host_notification_commands;
@@ -2880,7 +2763,6 @@
 			this_customvariablesmember = next_customvariablesmember;
 			}
 
-		next_contact = this_contact->next;
 		my_free(this_contact->name);
 		my_free(this_contact->alias);
 		my_free(this_contact->email);
@@ -2891,18 +2773,15 @@
 #ifdef NSCORE
 		free_objectlist(&this_contact->contactgroups_ptr);
 #endif
-
-		my_free(this_contact);
-		this_contact = next_contact;
 		}
 
 	/* reset pointers */
-	contact_list = NULL;
+	my_free(contact_list);
 
 
 	/**** free memory for the contact group list ****/
-	this_contactgroup = contactgroup_list;
-	while(this_contactgroup != NULL) {
+	for (i = 0; i < num_objects.contactgroups; i++) {
+		contactgroup *this_contactgroup = &contactgroup_list[i];
 
 		/* free memory for the group members */
 		this_contactsmember = this_contactgroup->members;
@@ -2913,23 +2792,18 @@
 			this_contactsmember = next_contactsmember;
 			}
 
-		next_contactgroup = this_contactgroup->next;
 		my_free(this_contactgroup->group_name);
 		my_free(this_contactgroup->alias);
-		my_free(this_contactgroup);
-		this_contactgroup = next_contactgroup;
 		}
 
 	/* reset pointers */
-	contactgroup_list = NULL;
+	my_free(contactgroup_list);
 
 
 	/**** free memory for the service list ****/
-	this_service = service_list;
-	while(this_service != NULL) {
+	for (i = 0; i < num_objects.services; i++) {
+		service *this_service = &service_list[i];
 
-		next_service = this_service->next;
-
 		/* free memory for contact groups */
 		this_contactgroupsmember = this_service->contact_groups;
 		while(this_contactgroupsmember != NULL) {
@@ -2980,31 +2854,26 @@
 		my_free(this_service->action_url);
 		my_free(this_service->icon_image);
 		my_free(this_service->icon_image_alt);
-		my_free(this_service);
-		this_service = next_service;
 		}
 
 	/* reset pointers */
-	service_list = NULL;
+	my_free(service_list);
 
 
-	/**** free memory for the command list ****/
-	this_command = command_list;
-	while(this_command != NULL) {
-		next_command = this_command->next;
+	/**** free command memory ****/
+	for (i = 0; i < num_objects.commands; i++) {
+		command *this_command = &command_list[i];
 		my_free(this_command->name);
 		my_free(this_command->command_line);
-		my_free(this_command);
-		this_command = next_command;
 		}
 
 	/* reset pointers */
-	command_list = NULL;
+	my_free(command_list);
 
 
-	/**** free memory for the service escalation list ****/
-	this_serviceescalation = serviceescalation_list;
-	while(this_serviceescalation != NULL) {
+	/**** free service escalation memory ****/
+	for (i = 0; i < num_objects.serviceescalations; i++) {
+		serviceescalation *this_serviceescalation = &serviceescalation_list[i];
 
 		/* free memory for the contact group members */
 		this_contactgroupsmember = this_serviceescalation->contact_groups;
@@ -3021,43 +2890,24 @@
 			my_free(this_contactsmember);
 			this_contactsmember = next_contactsmember;
 			}
-
-		next_serviceescalation = this_serviceescalation->next;
-		my_free(this_serviceescalation);
-		this_serviceescalation = next_serviceescalation;
 		}
 
 	/* reset pointers */
-	serviceescalation_list = NULL;
+	my_free(serviceescalation_list);
 
 
-	/**** free memory for the service dependency list ****/
-	this_servicedependency = servicedependency_list;
-	while(this_servicedependency != NULL) {
-		next_servicedependency = this_servicedependency->next;
-		my_free(this_servicedependency);
-		this_servicedependency = next_servicedependency;
-		}
+	/**** free service dependency memory ****/
+	my_free(servicedependency_list);
 
-	/* reset pointers */
-	servicedependency_list = NULL;
 
+	/**** free host dependency memory ****/
+	my_free(hostdependency_list);
 
-	/**** free memory for the host dependency list ****/
-	this_hostdependency = hostdependency_list;
-	while(this_hostdependency != NULL) {
-		next_hostdependency = this_hostdependency->next;
-		this_hostdependency = next_hostdependency;
-		}
 
-	/* reset pointers */
-	hostdependency_list = NULL;
+	/**** free host escalation memory ****/
+	for (i = 0; i < num_objects.hostescalations; i++) {
+		hostescalation *this_hostescalation = &hostescalation_list[i];
 
-
-	/**** free memory for the host escalation list ****/
-	this_hostescalation = hostescalation_list;
-	while(this_hostescalation != NULL) {
-
 		/* free memory for the contact group members */
 		this_contactgroupsmember = this_hostescalation->contact_groups;
 		while(this_contactgroupsmember != NULL) {
@@ -3073,21 +2923,13 @@
 			my_free(this_contactsmember);
 			this_contactsmember = next_contactsmember;
 			}
-
-		next_hostescalation = this_hostescalation->next;
-		my_free(this_hostescalation);
-		this_hostescalation = next_hostescalation;
 		}
 
 	/* reset pointers */
-	hostescalation_list = NULL;
+	my_free(hostescalation_list);
 
-	/* free object skiplists */
-	free_object_skiplists();
-
 	/* we no longer have any objects */
 	memset(&num_objects, 0, sizeof(num_objects));
 
 	return OK;
 	}
-

Modified: nagioscore/trunk/include/objects.h
===================================================================
--- nagioscore/trunk/include/objects.h	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/include/objects.h	2012-08-26 20:11:40 UTC (rev 2115)
@@ -608,6 +608,18 @@
 	struct hostdependency_struct *next;
 	} hostdependency;
 
+extern command *command_list;
+extern timeperiod *timeperiod_list;
+extern host *host_list;
+extern service *service_list;
+extern contact *contact_list;
+extern hostgroup *hostgroup_list;
+extern servicegroup *servicegroup_list;
+extern contactgroup *contactgroup_list;
+extern hostescalation *hostescalation_list;
+extern hostdependency *hostdependency_list;
+extern serviceescalation *serviceescalation_list;
+extern servicedependency *servicedependency_list;
 
 
 /********************* FUNCTIONS **********************/

Modified: nagioscore/trunk/t-tap/test_nagios_config.c
===================================================================
--- nagioscore/trunk/t-tap/test_nagios_config.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/t-tap/test_nagios_config.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -223,13 +223,6 @@
 unsigned long   update_uid = 0L;
 
 
-extern contact	       *contact_list;
-extern contactgroup    *contactgroup_list;
-extern hostgroup       *hostgroup_list;
-extern command         *command_list;
-extern timeperiod      *timeperiod_list;
-extern serviceescalation *serviceescalation_list;
-extern host 		*host_list;
 extern char	*xrddefault_retention_file;
 
 notification    *notification_list;

Modified: nagioscore/trunk/t-tap/test_timeperiods.c
===================================================================
--- nagioscore/trunk/t-tap/test_timeperiods.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/t-tap/test_timeperiods.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -223,14 +223,6 @@
 unsigned long   update_uid = 0L;
 
 
-extern contact	       *contact_list;
-extern contactgroup    *contactgroup_list;
-extern hostgroup       *hostgroup_list;
-extern command         *command_list;
-extern timeperiod      *timeperiod_list;
-extern serviceescalation *serviceescalation_list;
-extern host 		*host_list;
-
 notification    *notification_list;
 
 check_result    check_result_info;

Modified: nagioscore/trunk/xdata/xodtemplate.c
===================================================================
--- nagioscore/trunk/xdata/xodtemplate.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/xdata/xodtemplate.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -122,6 +122,9 @@
 
 extern int allow_empty_hostgroup_assignment;
 
+/* add up execution and notification dependencies */
+static unsigned int host_deps, service_deps;
+
 /*
  * Macro magic used to determine if a service is assigned
  * via hostgroup_name or host_name. Those assigned via host_name
@@ -1853,6 +1856,7 @@
 						}
 					}
 				temp_servicedependency->have_execution_dependency_options = TRUE;
+				service_deps++;
 				}
 			else if(!strcmp(variable, "notification_failure_options") || !strcmp(variable, "notification_failure_criteria")) {
 				for(temp_ptr = strtok(value, ", "); temp_ptr; temp_ptr = strtok(NULL, ", ")) {
@@ -1886,6 +1890,7 @@
 						}
 					}
 				temp_servicedependency->have_notification_dependency_options = TRUE;
+				service_deps++;
 				}
 			else if(!strcmp(variable, "register"))
 				temp_servicedependency->register_object = (atoi(value) > 0) ? TRUE : FALSE;
@@ -3265,6 +3270,7 @@
 						}
 					}
 				temp_hostdependency->have_notification_dependency_options = TRUE;
+				host_deps++;
 				}
 			else if(!strcmp(variable, "execution_failure_options") || !strcmp(variable, "execution_failure_criteria")) {
 				for(temp_ptr = strtok(value, ", "); temp_ptr; temp_ptr = strtok(NULL, ", ")) {
@@ -3294,6 +3300,7 @@
 						}
 					}
 				temp_hostdependency->have_execution_dependency_options = TRUE;
+				host_deps++;
 				}
 			else if(!strcmp(variable, "register"))
 				temp_hostdependency->register_object = (atoi(value) > 0) ? TRUE : FALSE;
@@ -8371,9 +8378,29 @@
 /**************** OBJECT REGISTRATION FUNCTIONS *******************/
 /******************************************************************/
 
-/* registers object definitions */
+/*
+ * registers object definitions
+ * The order goes like this:
+ *   Timeperiods
+ *   Commands
+ *   Contactgroups
+ *   Hostgroups
+ *   Servicegroups
+ *   Contacts
+ *   Hosts
+ *   Services
+ *   Servicedependencies
+ *   Serviceescalations
+ *   Hostdependencies
+ *   Hostescalations
+ *
+ * Why are contactgroups done before contacts? A reasonable assumption
+ * would be that contacts should be flattened and added to the checked
+ * objects directly rather than forcing us to fiddle with that crap
+ * during runtime.
+ */
 int xodtemplate_register_objects(void) {
-	int result = OK;
+	int i, result = OK;
 	xodtemplate_timeperiod *temp_timeperiod = NULL;
 	xodtemplate_command *temp_command = NULL;
 	xodtemplate_contactgroup *temp_contactgroup = NULL;
@@ -8387,7 +8414,25 @@
 	xodtemplate_hostdependency *temp_hostdependency = NULL;
 	xodtemplate_hostescalation *temp_hostescalation = NULL;
 	void *ptr = NULL;
+	unsigned int ocount[NUM_OBJECT_SKIPLISTS];
 
+
+	for (i = 0; i < ARRAY_SIZE(ocount); i++) {
+		ocount[i] = (unsigned int)skiplist_num_items(xobject_skiplists[i]);
+	}
+
+	/*
+	 * dependencies may be duplicated still, so it's good we counted
+	 * earlier and know exactly how much space we'll need
+	 */
+	ocount[SERVICEDEPENDENCY_SKIPLIST] = service_deps;
+	ocount[HOSTDEPENDENCY_SKIPLIST] = host_deps;
+
+	if (create_object_tables(ocount) != OK) {
+		logit(NSLOG_CONFIG_ERROR, TRUE, "Failed to create object tables\n");
+		return ERROR;
+	}
+
 	/* register timeperiods */
 	ptr = NULL;
 	for(temp_timeperiod = (xodtemplate_timeperiod *)skiplist_get_first(xobject_skiplists[TIMEPERIOD_SKIPLIST], &ptr); temp_timeperiod != NULL; temp_timeperiod = (xodtemplate_timeperiod *)skiplist_get_next(&ptr)) {

Modified: nagioscore/trunk/xdata/xrddefault.c
===================================================================
--- nagioscore/trunk/xdata/xrddefault.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/xdata/xrddefault.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -38,9 +38,6 @@
 
 #include "xrddefault.h"
 
-extern host           *host_list;
-extern service        *service_list;
-extern contact        *contact_list;
 extern comment        *comment_list;
 extern scheduled_downtime *scheduled_downtime_list;
 

Modified: nagioscore/trunk/xdata/xsddefault.c
===================================================================
--- nagioscore/trunk/xdata/xsddefault.c	2012-08-26 20:10:28 UTC (rev 2114)
+++ nagioscore/trunk/xdata/xsddefault.c	2012-08-26 20:11:40 UTC (rev 2115)
@@ -92,14 +92,9 @@
 extern char           *last_program_version;
 extern char           *new_program_version;
 
-extern host *host_list;
-extern service *service_list;
-extern contact *contact_list;
 extern comment *comment_list;
 extern scheduled_downtime *scheduled_downtime_list;
 
-extern skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
-
 extern unsigned long  next_comment_id;
 extern unsigned long  next_downtime_id;
 extern unsigned long  next_event_id;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list