From 078125bdec0b00a8f2a46e0b6ced35c0ccf36e5d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 2 Dec 2014 08:42:21 +0100 Subject: [PATCH] Implement socket_path attribute for the IdoMysqlConnection class fixes #7901 --- doc/7-configuring-icinga-2.md | 1 + lib/db_ido_mysql/idomysqlconnection.cpp | 8 +++++--- lib/db_ido_mysql/idomysqlconnection.ti | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/7-configuring-icinga-2.md b/doc/7-configuring-icinga-2.md index 63eac3350..877bc62f7 100644 --- a/doc/7-configuring-icinga-2.md +++ b/doc/7-configuring-icinga-2.md @@ -1409,6 +1409,7 @@ Attributes: ----------------|---------------- host |**Optional.** MySQL database host address. Defaults to "localhost". port |**Optional.** MySQL database port. Defaults to 3306. + socket_path |**Optional.** MySQL socket path. user |**Optional.** MySQL database user with read/write permission to the icinga database. Defaults to "icinga". password |**Optional.** MySQL database user's password. Defaults to "icinga". database |**Optional.** MySQL database name. Defaults to "icinga". diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 68da0bb9e..49345b503 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -179,17 +179,19 @@ void IdoMysqlConnection::Reconnect(void) ClearIDCache(); - String ihost, iuser, ipasswd, idb; - const char *host, *user , *passwd, *db; + String ihost, isocket_path, iuser, ipasswd, idb; + const char *host, *socket_path, *user , *passwd, *db; long port; ihost = GetHost(); + isocket_path = GetSocketPath(); iuser = GetUser(); ipasswd = GetPassword(); idb = GetDatabase(); host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL; port = GetPort(); + socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL; user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL; passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL; db = (!idb.IsEmpty()) ? idb.CStr() : NULL; @@ -202,7 +204,7 @@ void IdoMysqlConnection::Reconnect(void) BOOST_THROW_EXCEPTION(std::bad_alloc()); } - if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, NULL, CLIENT_FOUND_ROWS)) { + if (!mysql_real_connect(&m_Connection, host, user, passwd, db, port, socket_path, CLIENT_FOUND_ROWS)) { Log(LogCritical, "IdoMysqlConnection") << "Connection to database '" << db << "' with user '" << user << "' on '" << host << ":" << port << "' failed: \"" << mysql_error(&m_Connection) << "\""; diff --git a/lib/db_ido_mysql/idomysqlconnection.ti b/lib/db_ido_mysql/idomysqlconnection.ti index 5cfa2ad46..e90dd6a93 100644 --- a/lib/db_ido_mysql/idomysqlconnection.ti +++ b/lib/db_ido_mysql/idomysqlconnection.ti @@ -30,6 +30,7 @@ class IdoMysqlConnection : DbConnection [config] int port { default {{{ return 3306; }}} }; + [config] String socket_path; [config] String user { default {{{ return "icinga"; }}} };