[icinga-checkins] icinga.org: icinga-core/dev/ido: idoutils: do not pass host and port if not set in the config, letting mysql|pgsql drivers autoselect the socket #2698

git at icinga.org git at icinga.org
Thu Jun 21 11:07:33 CEST 2012


Module: icinga-core
Branch: dev/ido
Commit: 5fc9642f9c139eb9d0604dfaacd4ed3ee4f5f2da
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=5fc9642f9c139eb9d0604dfaacd4ed3ee4f5f2da

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Thu Jun 21 10:06:46 2012 +0200

idoutils: do not pass host and port if not set in the config, letting mysql|pgsql drivers autoselect the socket #2698

the libdbi drivers behave differently if you do not pass host and port,
instead falling back to automated socket detection. in order to do that
successfully, it is required not to set the host if NULL provided, and
checking if the port is other than the default 0 which is internally
used this being an integer.

once one or both is not set, the libdbi will not pass this to the loaded
driver for either mysql or pglsq, and the inner logic of libmysqlclient
or libpq will do the trick for you.

still, you can set the dbsocket option prior to those changes, and
define the local db socket yourself, not letting the db driver guess
where it was built-in (which is of course normally true, when using
packages).

thanks to Alexander Wirt for reporting and testing on the Debian
packages.

refs #2698

---

 Changelog                |    7 +++++++
 module/idoutils/src/db.c |   24 ++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/Changelog b/Changelog
index 3f1bc89..e9bb03c 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,13 @@ Icinga 1.7.x Change Log
 
 Thanks to all contributers, testers and developers. Please read AUTHORS and THANKS for a detailed list :-)
 
+1.8.0 - XX/10/2012
+
+FIXES
+
+* idoutils: do not pass host and port if not set in the config, letting mysql|pgsql drivers autoselect the socket #2698 - MF
+
+
 1.7.1 - 18/06/2012
 
 FIXES
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index e5c5371..fa18f34 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -497,8 +497,28 @@ int ido2db_db_connect(ido2db_idi *idi) {
 		return IDO_ERROR;
 	}
 
-	dbi_conn_set_option(idi->dbinfo.dbi_conn, "host", ido2db_db_settings.host);
-	dbi_conn_set_option_numeric(idi->dbinfo.dbi_conn, "port", (int)ido2db_db_settings.port);
+	/* decide wether to set host and port, or not ... drivers will use socket otherwise */
+        switch (idi->dbinfo.server_type) {
+        case IDO2DB_DBSERVER_MYSQL:
+		if (ido2db_db_settings.host != NULL)
+			dbi_conn_set_option(idi->dbinfo.dbi_conn, "host", ido2db_db_settings.host);
+		if (ido2db_db_settings.port != 0)
+			dbi_conn_set_option_numeric(idi->dbinfo.dbi_conn, "port", (int)ido2db_db_settings.port);
+                break;
+        case IDO2DB_DBSERVER_PGSQL:
+		if (ido2db_db_settings.host != NULL)
+			dbi_conn_set_option(idi->dbinfo.dbi_conn, "host", ido2db_db_settings.host);
+		if (ido2db_db_settings.port != 0)
+			dbi_conn_set_option_numeric(idi->dbinfo.dbi_conn, "port", (int)ido2db_db_settings.port);
+                break;
+        default:
+		if (ido2db_db_settings.host != NULL)
+			dbi_conn_set_option(idi->dbinfo.dbi_conn, "host", ido2db_db_settings.host);
+		if (ido2db_db_settings.port != 0)
+			dbi_conn_set_option_numeric(idi->dbinfo.dbi_conn, "port", (int)ido2db_db_settings.port);
+                break;
+        }
+
 	dbi_conn_set_option(idi->dbinfo.dbi_conn, "username", ido2db_db_settings.username);
 	dbi_conn_set_option(idi->dbinfo.dbi_conn, "password", ido2db_db_settings.password);
 	dbi_conn_set_option(idi->dbinfo.dbi_conn, "dbname", ido2db_db_settings.dbname);





More information about the icinga-checkins mailing list