1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-15 Log all sql errors.

modified for MySQL 5.5. Logger service moved to the
        plugin/sql_errlog directory to be properly used later.

plugin/sql_errlog/sql_errlog.c:
  Fixes for bugs #956427 (SQL_ERROR_LOG plugin produces bogus warnings about sql-error-log-size-limit value) and #956463 (Server crashes if SQL_ERROR_LOG fails to initialize) they're also MDEV-184 and MDEV-183
    
  The sql_error_log_deinit() should be prepared for the logger_file to be NULL.
  The logger_file_size_limit upper limit wasn't properly set.
This commit is contained in:
Alexey Botchkov
2012-03-24 11:24:20 +01:00
parent 619f67b1b4
commit 5c01f1ac14
15 changed files with 45 additions and 79 deletions

View File

@ -16,6 +16,7 @@
#include <mysql/plugin_audit.h>
#include <stdio.h>
#include <time.h>
#include "service_logger.h"
/*
Disable __attribute__() on non-gcc compilers.
@ -32,6 +33,7 @@
rate 0 means the logging was disabled.
*/
static char *filename;
static unsigned int rate;
static unsigned long long size_limit;
@ -50,7 +52,7 @@ static MYSQL_SYSVAR_UINT(rate, rate, PLUGIN_VAR_RQCMDARG,
static MYSQL_SYSVAR_ULONGLONG(size_limit, size_limit,
PLUGIN_VAR_READONLY, "Log file size limit", NULL, NULL,
1000000, 100, 0, 1);
1000000, 100, ((long long) 0x7FFFFFFFFFFFFFFFLL), 1);
static MYSQL_SYSVAR_UINT(rotations, rotations,
PLUGIN_VAR_READONLY, "Number of rotations before log is removed.",
@ -104,6 +106,8 @@ static void log_sql_errors(MYSQL_THD thd __attribute__((unused)),
static int sql_error_log_init(void *p __attribute__((unused)))
{
init_logger_mutexes();
logfile= logger_open(filename, size_limit, rotations);
if (logfile == NULL) {
fprintf(stderr, "Could not create file '%s'\n",
@ -117,7 +121,8 @@ static int sql_error_log_init(void *p __attribute__((unused)))
static int sql_error_log_deinit(void *p __attribute__((unused)))
{
logger_close(logfile);
if (logfile)
logger_close(logfile);
return 0;
}
@ -139,6 +144,24 @@ static struct st_mysql_audit descriptor =
{ MYSQL_AUDIT_GENERAL_CLASSMASK }
};
mysql_declare_plugin(sql_errlog)
{
MYSQL_AUDIT_PLUGIN,
&descriptor,
"SQL_ERROR_LOG",
"Alexey Botchkov",
"Log SQL level errors to a file with rotation",
PLUGIN_LICENSE_GPL,
sql_error_log_init,
sql_error_log_deinit,
0x0100,
NULL,
vars,
NULL,
0
}
mysql_declare_plugin_end;
maria_declare_plugin(sql_errlog)
{
MYSQL_AUDIT_PLUGIN,