From 60074c051897aed7df38ff68b9d2fe3c9649e75a Mon Sep 17 00:00:00 2001 From: Guy Lichtman Date: Sun, 9 Nov 2014 12:05:39 +0200 Subject: [PATCH] Protection for case where tcp port or unix socket is not set and plugin tries to set default socket name at startup. The tcp port or unix socket may not be set when they are not passed either on the command line or configured in my.cnf. In this case the plugin init function is called before mysql has set the default values for these. --- src/audit_handler.cc | 12 +++++++++++- src/audit_plugin.cc | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/audit_handler.cc b/src/audit_handler.cc index aef2499..ccadc27 100644 --- a/src/audit_handler.cc +++ b/src/audit_handler.cc @@ -215,6 +215,16 @@ int Audit_file_handler::open(const char * io_dest, bool log_errors) //no locks. called by handler_start and when it is time to retry bool Audit_io_handler::handler_start_internal() { + if(!m_io_dest || strlen(m_io_dest) == 0) + { + if(m_log_io_errors) + { + sql_print_error( + "%s %s: io destination not set. Not connecting.", + AUDIT_LOG_PREFIX, m_io_type); + } + return false; + } if (open(m_io_dest, m_log_io_errors) != 0) { //open failed @@ -319,7 +329,7 @@ ssize_t Audit_socket_handler::write(const char * data, size_t size) } int Audit_socket_handler::open(const char * io_dest, bool log_errors) -{ +{ //open the socket int sock = socket(AF_UNIX,SOCK_STREAM,0); if (sock < 0) diff --git a/src/audit_plugin.cc b/src/audit_plugin.cc index 5359d3b..95ae36a 100644 --- a/src/audit_plugin.cc +++ b/src/audit_plugin.cc @@ -1223,7 +1223,7 @@ static void json_socket_name_update(THD *thd, struct st_mysql_sys_var *var, void { strncpy( json_socket_name_buff , str, buff_len); } - if(strlen(json_socket_name_buff) == 0) //set default + if(strlen(json_socket_name_buff) == 0 && (mysqld_port > 0 || mysqld_unix_port)) //set default { const char * name_prefix = "/tmp/mysql.audit_";