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

git at icinga.org git at icinga.org
Tue Aug 7 20:23:39 CEST 2012


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

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 726c32d..69c6ab2 100644
--- a/base/commands.c
+++ b/base/commands.c
@@ -2063,26 +2063,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 */
@@ -2090,9 +2079,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);
@@ -2100,15 +2086,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);
 }
 
 
@@ -2196,31 +2178,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;
 
@@ -2236,7 +2201,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