[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: core: fix passive check result handling, don't copy strings

git at icinga.org git at icinga.org
Tue Aug 7 18:40:56 CEST 2012


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Tue Aug  7 18:34:25 2012 +0200

core: fix passive check result handling, don't copy strings

refs #2687

---

 base/commands.c |   64 ++++++++++++-------------------------------------------
 1 files changed, 14 insertions(+), 50 deletions(-)

diff --git a/base/commands.c b/base/commands.c
index 083350c..d1c9cce 100644
--- a/base/commands.c
+++ b/base/commands.c
@@ -2139,26 +2139,15 @@ int process_passive_service_check(time_t check_time, char *host_name, char *svc_
 		return ERROR;
 
 	/* initialize vars */
-	init_check_result(&cr);
-	cr.object_check_type = SERVICE_CHECK;
-
-	/* save string vars */
-	if ((cr.host_name = (char *)strdup(real_host_name)) == NULL)
-		result = ERROR;
-	if ((cr.service_description = (char *)strdup(svc_description)) == NULL)
-		result = ERROR;
-	if ((cr.output = (char *)strdup(output)) == NULL)
-		result = ERROR;
-
-	/* handle errors */
-	if (result == ERROR) {
-		my_free(cr.output);
-		my_free(cr.service_description);
-		my_free(cr.host_name);
-		return ERROR;
-	}
+	memset(&cr, 0, sizeof(cr));
+	cr.exited_ok = 1;
+	cr.check_type = SERVICE_CHECK_PASSIVE;
+	cr.host_name = real_host_name;
+	cr.service_description = svc_description;
+	cr.output = output;
+	cr.start_time.tv_sec = cr.finish_time.tv_sec = check_time;
 
-	/* save the return code */
+	/* save the return code and make sure it's sane */
 	cr.return_code = return_code;
 
 	/* make sure the return code is within bounds */
@@ -2166,9 +2155,6 @@ int process_passive_service_check(time_t check_time, char *host_name, char *svc_
 	if (cr.return_code < 0 || cr.return_code > 3)
 		cr.return_code = STATE_UNKNOWN;
 
-	/* passive checks have same start/end time */
-	cr.start_time.tv_sec = cr.finish_time.tv_sec = check_time;
-
 	/* calculate latency */
 	gettimeofday(&tv, NULL);
 	cr.latency = (double)((double)(tv.tv_sec - check_time) + (double)(tv.tv_usec / 1000.0) / 1000.0);
@@ -2176,15 +2162,11 @@ int process_passive_service_check(time_t check_time, char *host_name, char *svc_
 		cr.latency = 0.0;
 
 	/*
-	 * passive checks can be treaded as normal check,
+	 * passive checks can be treated as normal checks,
 	 * passing the check_result struct over
 	 */
 
-	/* make the check handler happy */
-	cr.exited_ok = 1;
-	handle_async_service_check_result(temp_service, &cr);
-
-	return OK;
+	return handle_async_service_check_result(temp_service, &cr);
 }
 
 
@@ -2272,31 +2254,14 @@ int process_passive_host_check(time_t check_time, char *host_name, int return_co
 		return ERROR;
 
 	/* initialize vars */
-	init_check_result(&cr);
-	cr.object_check_type = HOST_CHECK;
-
-	/* save string vars */
-	if ((cr.host_name = (char *)strdup(real_host_name)) == NULL)
-		result = ERROR;
-	if ((cr.output = (char *)strdup(output)) == NULL)
-		result = ERROR;
-
-	/* handle errors */
-	if (result == ERROR) {
-		my_free(cr.output);
-		my_free(cr.service_description);
-		my_free(cr.host_name);
-		return ERROR;
-	}
+	memset(&cr, 0, sizeof(cr));
+	cr.host_name = real_host_name;
+	cr.exited_ok = 1;
+	cr.check_type = HOST_CHECK_PASSIVE;
 
 	/* save the return code */
 	cr.return_code = return_code;
 
-	/* make sure the return code is within bounds */
-	/* FIXME fix hardcoded return codes for states */
-	if (cr.return_code < 0 || cr.return_code > 3)
-		cr.return_code = STATE_UNKNOWN;
-
 	/* passive checks have same start/end time */
 	cr.start_time.tv_sec = cr.finish_time.tv_sec = check_time;
 
@@ -2312,7 +2277,6 @@ int process_passive_host_check(time_t check_time, char *host_name, int return_co
          */
 
 	/* make the check handler happy */
-	cr.exited_ok = 1;
 	handle_async_host_check_result_3x(temp_host, &cr);
 
 	return OK;





More information about the icinga-checkins mailing list