[icinga-checkins] icinga.org: icinga-core/master: core: protect against poorly behaving thread-libraries (Andreas Ericsson) #1080

git at icinga.org git at icinga.org
Mon Jan 10 16:19:18 CET 2011


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Jan  5 16:20:10 2011 +0100

core: protect against poorly behaving thread-libraries (Andreas Ericsson) #1080

[--SNIP--]
calling pthread_cancel(0) will cause segfaults with some thread
libraries. It's possible that will happen if the user has a number
of config files larger than the max open file descriptor limit
(ulimit -n) and some eventbroker module leaks filedescriptors, since
we can then enter the cleanup() routine from main() before we've
spawned any threads.

Signed-off-by: Andreas Ericsson <ae at op5.se>
[--SNIP--]

fixes #1080

---

 Changelog    |    1 +
 base/utils.c |   34 +++++++++++++++++++++-------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/Changelog b/Changelog
index c242fb4..e618b06 100644
--- a/Changelog
+++ b/Changelog
@@ -47,6 +47,7 @@ FIXES
 * core: fix parsing of long plugin output for async host checks (Jochen Bern) #1046
 * core: log error reason when failing to open the status file (Andreas Ericsson) #1078
 * core: fix allocate memory once for *GROUPMEMBERS macros (Stephane Lapie) #1076
+* core: protect against poorly behaving thread-libraries (Andreas Ericsson) #1080
 
 * classic ui: change servicestatus letter color to default black, not grey #946
 * classic ui: fix waste of cpu in status summary (TomTom) #933
diff --git a/base/utils.c b/base/utils.c
index 5f4342e..dfef3d2 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -3776,24 +3776,32 @@ int init_command_file_worker_thread(void){
 int shutdown_command_file_worker_thread(void){
 	int result=0;
 
-	/* CHANGED 11/12/07 EG */
-	/* cancel/join worker thread only if we're the main (parent) process */
-
-	/* tell the worker thread to exit */
-	result=pthread_cancel(worker_threads[COMMAND_WORKER_THREAD]);
+	/* 2010-01-04 AE:
+	 * calling pthread_cancel(0) will cause segfaults with some
+	 * thread libraries. It's possible that will happen if the
+	 * user has a number of config files larger than the max
+	 * open file descriptor limit (ulimit -n) and some retarded
+	 * eventbroker module leaks filedescriptors, since we'll then
+	 * enter the cleanup() routine from main() before we've
+	 * spawned any threads.
+	 */
+	if (worker_threads[COMMAND_WORKER_THREAD]) {
+		/* tell the worker thread to exit */
+		result=pthread_cancel(worker_threads[COMMAND_WORKER_THREAD]);
 
-	/* wait for the worker thread to exit */
-	if(result==0){
-		result=pthread_join(worker_threads[COMMAND_WORKER_THREAD],NULL);
+		/* wait for the worker thread to exit */
+		if(result==0){
+			result=pthread_join(worker_threads[COMMAND_WORKER_THREAD],NULL);
 		}
 
-	/* we're being called from a fork()'ed child process - can't cancel thread, so just cleanup memory */
-	else{
-		cleanup_command_file_worker_thread(NULL);
-		}
+		/* we're being called from a fork()'ed child process - can't cancel thread, so just cleanup memory */
+		else {
+			cleanup_command_file_worker_thread(NULL);
+ 		}
+	}
 
 	return OK;
-        }
+}
 
 
 /* clean up resources used by command file worker thread */





More information about the icinga-checkins mailing list