[icinga-checkins] icinga.org: icinga-core/rbartels/cgis: fix delay sorting of comments/ downtimes (Ton Voon)

git at icinga.org git at icinga.org
Sat Sep 4 12:32:54 CEST 2010


Module: icinga-core
Branch: rbartels/cgis
Commit: 2e9b5fa5cc4c38b5eb5ec868d5eaf62ffdd92e59
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=2e9b5fa5cc4c38b5eb5ec868d5eaf62ffdd92e59

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Aug 30 14:08:54 2010 +0200

fix delay sorting of comments/downtimes (Ton Voon)

refs #753

---

 Changelog         |    1 +
 common/comments.c |   31 ++++++++++++++-----------------
 common/downtime.c |   31 ++++++++++++++++---------------
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/Changelog b/Changelog
index 9ec2081..8c6c791 100644
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ FIXES
 * core: fix for event execution loop re-scheduling host checks instead of executing them if service checks are disabled (Ethan Galstad)
 
 * classic ui: update jquery for multiple cmds dropdown, resolve conflicts with pnp
+* classic ui: fix delay sorting of comments/downtimes (Ton Voon)
 
 
 1.0.3 - 18/08/2010
diff --git a/common/comments.c b/common/comments.c
index 8bae476..cd433b7 100644
--- a/common/comments.c
+++ b/common/comments.c
@@ -1,6 +1,6 @@
 /*****************************************************************************
  *
- * COMMENTS.C - Comment functions for Nagios
+ * COMMENTS.C - Comment functions for Icinga
  *
  * Copyright (c) 1999-2008 Ethan Galstad (egalstad at nagios.org)
  * Copyright (c) 2009-2010 Icinga Development Team (http://www.icinga.org)
@@ -45,7 +45,6 @@
 
 comment     *comment_list=NULL;
 int	    defer_comment_sorting = 0;
-static int  unsorted_comments = 0;
 comment     **comment_hashlist=NULL;
 
 
@@ -218,10 +217,6 @@ int delete_comment(int type, unsigned long comment_id){
 		else
 			last_comment->next=next_comment;
 
-		/* if sorting is defered then decrease the amount of unsorted comments by one */
-		if (defer_comment_sorting)
-			unsorted_comments--;
-
 		/* free memory */
 		my_free(this_comment->host_name);
 		my_free(this_comment->service_description);
@@ -509,7 +504,6 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
 	if(defer_comment_sorting){
 		new_comment->next=comment_list;
 		comment_list=new_comment;
-		unsorted_comments++;
 		}
 	else{
 		/* add new comment to comment list, sorted by comment id */
@@ -553,34 +547,37 @@ static int comment_compar(const void *p1, const void *p2){
 	}
 
 int sort_comments(void){
-	comment **array, *last_comment;
-	int i = 0;
+	comment **array, *temp_comment;
+	unsigned long i=0, unsorted_comments=0;
 
 	if(!defer_comment_sorting)
 		return OK;
 	defer_comment_sorting=0;
 
+	temp_comment = comment_list;
+	while(temp_comment!=NULL) {
+		temp_comment = temp_comment->next;
+		unsorted_comments++;
+		}
+
 	if(!unsorted_comments)
 		return OK;
 
 	if(!(array=malloc(sizeof(*array)*unsorted_comments)))
 		return ERROR;
-	while(comment_list && i<unsorted_comments){
+	while(comment_list){
 		array[i++]=comment_list;
 		comment_list=comment_list->next;
 	}
-	if (comment_list || i<unsorted_comments)
-		return ERROR;
 
 	qsort((void *)array, i, sizeof(*array), comment_compar);
-	comment_list = last_comment = array[0];
+	comment_list = temp_comment = array[0];
 	for (i=1; i<unsorted_comments;i++){
-		last_comment->next = array[i];
-		last_comment = last_comment->next;
+		temp_comment->next = array[i];
+		temp_comment = temp_comment->next;
 		}
-	last_comment->next = NULL;
+	temp_comment->next = NULL;
 	my_free(array);
-	unsorted_comments = 0;
 	return OK;
 	}
 
diff --git a/common/downtime.c b/common/downtime.c
index 9432875..85eb871 100644
--- a/common/downtime.c
+++ b/common/downtime.c
@@ -47,7 +47,6 @@
 
 scheduled_downtime *scheduled_downtime_list=NULL;
 int		   defer_downtime_sorting = 0;
-static int	   unsorted_downtime = 0;
 
 #ifdef NSCORE
 extern timed_event *event_list_high;
@@ -924,7 +923,6 @@ int add_downtime(int downtime_type, char *host_name, char *svc_description, time
 	if(defer_downtime_sorting){
 		new_downtime->next=scheduled_downtime_list;
 		scheduled_downtime_list=new_downtime;
-		unsorted_downtime++;
 	}
 	else{
 		/* add new downtime to downtime list, sorted by start time */
@@ -967,34 +965,37 @@ static int downtime_compar(const void *p1, const void *p2){
 	}
 
 int sort_downtime(void){
-	scheduled_downtime **array, *last_downtime;
-	int i = 0;
+	scheduled_downtime **array, *temp_downtime;
+	unsigned long i=0, unsorted_downtimes=0;
 
 	if(!defer_downtime_sorting)
 		return OK;
 	defer_downtime_sorting=0;
 
-	if(!unsorted_downtime)
+	temp_downtime = scheduled_downtime_list;
+	while(temp_downtime!=NULL) {
+		temp_downtime = temp_downtime->next;
+		unsorted_downtimes++;
+		}
+
+	if(!unsorted_downtimes)
 		return OK;
 
-	if(!(array=malloc(sizeof(*array)*unsorted_downtime)))
+	if(!(array=malloc(sizeof(*array)*unsorted_downtimes)))
 		return ERROR;
-	while(scheduled_downtime_list && i<unsorted_downtime){
+	while(scheduled_downtime_list){
 		array[i++]=scheduled_downtime_list;
 		scheduled_downtime_list=scheduled_downtime_list->next;
 	}
-	if (scheduled_downtime_list || i<unsorted_downtime)
-		return ERROR;
 
 	qsort((void *)array, i, sizeof(*array), downtime_compar);
-	scheduled_downtime_list = last_downtime = array[0];
-	for (i=1; i<unsorted_downtime;i++){
-		last_downtime->next = array[i];
-		last_downtime = last_downtime->next;
+	scheduled_downtime_list = temp_downtime = array[0];
+	for (i=1; i<unsorted_downtimes;i++){
+		temp_downtime->next = array[i];
+		temp_downtime = temp_downtime->next;
 		}
-	last_downtime->next = NULL;
+	temp_downtime->next = NULL;
 	my_free(array);
-	unsorted_downtime = 0;
 	return OK;
 	}
 





More information about the icinga-checkins mailing list