MENT-1098 Crash during update on 10.4.17 after upgrade from 10.4.10

The reason for the crash was that there was not a write lock to
protect against file rotations in the server_audit plugin after an
audit plugin patch to changed audit mutexes to read & write locks.

The fixes are:
* Moving server_audit.c to use read & write locks (which improves
  performance).
* Added functionality in file_logger.c to not do file rotations until
  it is allowed by the caller (done without any interface changes for
  the logging service).
* Move checking of file size limit to server_audit.c and if it is time to
  do a rotation change the read lock to a write lock and tell file_logger
  that it is now allowed to rotate the log files.
This commit is contained in:
Monty
2021-02-25 11:55:08 +02:00
parent 4473d17430
commit 1d80e8e4f3
2 changed files with 97 additions and 62 deletions

View File

@ -150,23 +150,34 @@ exit:
}
/*
Return 1 if we should rotate the log
*/
my_bool logger_time_to_rotate(LOGGER_HANDLE *log)
{
my_off_t filesize;
if (log->rotations > 0 &&
(filesize= my_tell(log->file, MYF(0))) != (my_off_t) -1 &&
((ulonglong) filesize >= log->size_limit))
return 1;
return 0;
}
int logger_vprintf(LOGGER_HANDLE *log, const char* fmt, va_list ap)
{
int result;
my_off_t filesize;
char cvtbuf[1024];
size_t n_bytes;
flogger_mutex_lock(&log->lock);
if (log->rotations > 0)
if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 ||
((unsigned long long)filesize >= log->size_limit &&
do_rotate(log)))
{
result= -1;
errno= my_errno;
goto exit; /* Log rotation needed but failed */
}
if (logger_time_to_rotate(log) && do_rotate(log))
{
result= -1;
errno= my_errno;
goto exit; /* Log rotation needed but failed */
}
n_bytes= my_vsnprintf(cvtbuf, sizeof(cvtbuf), fmt, ap);
if (n_bytes >= sizeof(cvtbuf))
@ -180,21 +191,18 @@ exit:
}
int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size)
static int logger_write_r(LOGGER_HANDLE *log, my_bool allow_rotations,
const char *buffer, size_t size)
{
int result;
my_off_t filesize;
flogger_mutex_lock(&log->lock);
if (log->rotations > 0)
if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 ||
((unsigned long long)filesize >= log->size_limit &&
do_rotate(log)))
{
result= -1;
errno= my_errno;
goto exit; /* Log rotation needed but failed */
}
if (allow_rotations && logger_time_to_rotate(log) && do_rotate(log))
{
result= -1;
errno= my_errno;
goto exit; /* Log rotation needed but failed */
}
result= (int)my_write(log->file, (uchar *) buffer, size, MYF(0));
@ -204,6 +212,11 @@ exit:
}
int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size)
{
return logger_write_r(log, TRUE, buffer, size);
}
int logger_rotate(LOGGER_HANDLE *log)
{
int result;