[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: idoutils: fix ido2db forking if database connection failed, now immediately disconnecting the client

git at icinga.org git at icinga.org
Fri Sep 17 14:21:56 CEST 2010


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Thu Sep 16 13:38:51 2010 +0200

idoutils: fix ido2db forking if database connection failed, now immediately disconnecting the client

check https://dev.icinga.org/issues/773#note-3 for detailed info.

fixes #773

---

 Changelog                    |    2 ++
 module/idoutils/src/ido2db.c |   28 +++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/Changelog b/Changelog
index 93d838d..e0c5737 100644
--- a/Changelog
+++ b/Changelog
@@ -30,6 +30,8 @@ FIXES
 * classic ui: removed double header in tac.c
 * classic ui: changed size of checkbox column to 16
 
+* idoutils: fix ido2db forking if database connection failed, now immediately disconnecting the client
+
 
 1.0.3 - 18/08/2010
 
diff --git a/module/idoutils/src/ido2db.c b/module/idoutils/src/ido2db.c
index a0beb67..35ea8cd 100644
--- a/module/idoutils/src/ido2db.c
+++ b/module/idoutils/src/ido2db.c
@@ -1190,7 +1190,33 @@ int ido2db_handle_client_connection(int sd){
 
 	/* initialize database connection */
 	ido2db_db_init(&idi);
-	ido2db_db_connect(&idi);
+
+	/* check if connection to database was successful */
+	if(ido2db_db_connect(&idi)==IDO_ERROR) {
+		if(idi.dbinfo.connected!=IDO_TRUE) {
+
+			/* we did not get a db connection and the client should be disconnected */
+			syslog(LOG_USER | LOG_INFO,"Error: database connection failed, forced client disconnect...\n");
+			ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_client_connection() idi.dbinfo.connected is '%d'\n", idi.dbinfo.connected);
+
+			/* kill sub threads */
+			pthread_kill(thread_pool[0], SIGINT);
+			pthread_cancel(thread_pool[0]);
+
+		        /* free memory allocated to dynamic buffer */
+			ido_dbuf_free(&dbuf);
+
+		        /* reset db credentials */
+		        ido2db_db_deinit(&idi);
+
+		        /* free memory */
+		        ido2db_free_input_memory(&idi);
+		        ido2db_free_connection_memory(&idi);
+
+			/* return error signalling that child is terminating */
+			return IDO_ERROR;
+		}
+	}
 
 #ifdef HAVE_SSL
 	if(use_ssl==IDO_TRUE){





More information about the icinga-checkins mailing list