[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: fix checking of the open(2) system call (David Glick)

git at icinga.org git at icinga.org
Wed May 12 22:11:47 CEST 2010


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed May 12 20:54:14 2010 +0200

fix checking of the open(2) system call (David Glick)

Applied by Andreas Ericsson

[--snip--]
open() can validly return 0 on success if filedescriptor 0
happens to be available but there were three checks that
thought opening the file had failed when open() didn't
return greater than zero.

This could (and did) lead to file descriptor leaks, finally
rendering Nagios completely unable to process further checks
as it failed miserably when trying to move check result files
out of the queue.
[--snip--]

nice patch, works fine on Icinga.

fixes #406

---

 Changelog     |    1 +
 THANKS        |    1 +
 base/checks.c |    4 ++--
 base/utils.c  |    2 +-
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index a23fb5c..5848f68 100644
--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,7 @@ FIXES
 * core: macros: Protect against typos in macro names (Andreas Ericsson)
 * core: macros: Add NOTIFICATIONISESCALATED to the list of macro names (Marc Powell)
 * core: comments: Remove one comment at a time from hashlist (Hiren Patel)
+* core: fix checking of the open(2) system call (David Glick)
 
 * idoutils: Host DB inserts use string 'NULL\n' instead of NULL (William Preston)
 * idoutils: ndo2db_get_object_id fails to return existing IDs (William Preston)
diff --git a/THANKS b/THANKS
index b2e9dc9..05a9b1d 100644
--- a/THANKS
+++ b/THANKS
@@ -100,6 +100,7 @@ in various ways.  If we missed your name, let us know.
 * Robert Gash
 * Hugo Gayosso
 * Subhendu Ghosh
+* David Glick
 * Mark Goldfinch
 * Jeffrey Goldschrafe
 * Jan Grant
diff --git a/base/checks.c b/base/checks.c
index c5b3cf1..94d8f3a 100644
--- a/base/checks.c
+++ b/base/checks.c
@@ -479,7 +479,7 @@ int run_async_service_check(service *svc, int check_options, double latency, int
 	old_umask=umask(new_umask);
 	asprintf(&output_file,"%s/checkXXXXXX",temp_path);
 	check_result_info.output_file_fd=mkstemp(output_file);
-	if(check_result_info.output_file_fd>0)
+	if(check_result_info.output_file_fd>=0)
 		check_result_info.output_file_fp=fdopen(check_result_info.output_file_fd,"w");
 	else{
 		check_result_info.output_file_fp=NULL;
@@ -2952,7 +2952,7 @@ int run_async_host_check_3x(host *hst, int check_options, double latency, int sc
 	old_umask=umask(new_umask);
 	asprintf(&output_file,"%s/checkXXXXXX",temp_path);
 	check_result_info.output_file_fd=mkstemp(output_file);
-	if(check_result_info.output_file_fd>0)
+	if(check_result_info.output_file_fd>=0)
 		check_result_info.output_file_fp=fdopen(check_result_info.output_file_fd,"w");
 	else{
 		check_result_info.output_file_fp=NULL;
diff --git a/base/utils.c b/base/utils.c
index 4ebbf33..5e4d209 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -2123,7 +2123,7 @@ int move_check_result_to_queue(char *checkresult_file){
 	output_file_fd=mkstemp(output_file);
 
 	/* file created okay */
-	if(output_file_fd>0){
+	if(output_file_fd>=0){
 
 		log_debug_info(DEBUGL_CHECKS,2,"Moving temp check result file '%s' to queue file '%s'...\n",checkresult_file,output_file);
 





More information about the icinga-checkins mailing list