[PATCH] downtime: Fix crash when using distributable downtime commands
Robin Sonefors
robin.sonefors at op5.com
Thu Feb 21 13:49:22 CET 2013
The function that implements the distributable downtime commands kept a
pointer to the next downtime, which is a rubbish idea when the
unschedule_downtime deletes any triggered_by downtimes, and scheduled
downtimes triggered by this one typically start at the first element
right after this one.
To get nagios to crash using the old code, get a configuration with a
few hosts, make all of them depend on one single host, schedule and
propagate a triggered host downtime on the parent, and then unschedule
the downtime on the parent using, for example,
DEL_DOWNTIME_BY_HOST_NAME.
This prevents the crash by first locating any matching downtimes and
copying the information about the downtime type and id to a separate
downtime list, and only then try to unschedule anything. This might lead
to unschedule_downtime having to look for downtimes that no longer
exist, which is slow, but it should only really happen for
DEL_DOWNTIME_BY_START_TIME_COMMENT. I can see no easy way around this
without breaking API and/or ABI.
Signed-off-by: Robin Sonefors <robin.sonefors at op5.com>
---
common/downtime.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/common/downtime.c b/common/downtime.c
index f5eb004..1e35c3d 100644
--- a/common/downtime.c
+++ b/common/downtime.c
@@ -898,7 +898,9 @@ Returns number deleted
int delete_downtime_by_hostname_service_description_start_time_comment(char *hostname, char *service_description, time_t start_time, char *comment) {
scheduled_downtime *temp_downtime;
scheduled_downtime *next_downtime;
+ void *downtime_cpy;
int deleted = 0;
+ objectlist *matches = NULL, *tmp_match = NULL;
/* Do not allow deletion of everything - must have at least 1 filter on */
if(hostname == NULL && service_description == NULL && start_time == 0 && comment == NULL)
@@ -925,10 +927,20 @@ int delete_downtime_by_hostname_service_description_start_time_comment(char *hos
continue;
}
- unschedule_downtime(temp_downtime->type, temp_downtime->downtime_id);
+ downtime_cpy = malloc(sizeof(scheduled_downtime));
+ memcpy(downtime_cpy, temp_downtime, sizeof(scheduled_downtime));
+ prepend_object_to_objectlist(&matches, downtime_cpy);
deleted++;
}
+ for(tmp_match = matches; tmp_match != NULL; tmp_match = tmp_match->next) {
+ temp_downtime = (scheduled_downtime *)tmp_match->object_ptr;
+ unschedule_downtime(temp_downtime->type, temp_downtime->downtime_id);
+ my_free(temp_downtime);
+ }
+
+ free_objectlist(&matches);
+
return deleted;
}
--
1.7.11.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
More information about the Developers
mailing list