diff options
author | Monty <monty@mariadb.org> | 2021-02-25 11:55:08 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2021-02-25 13:23:59 +0200 |
commit | 1d80e8e4f31b2e361241973467070975f6d80136 (patch) | |
tree | 42d42516ea4b6a77dd34b5f10a6ab732c5dbc323 /mysys | |
parent | 4473d174308eeb14757fc986da39b8f4d391ce03 (diff) | |
download | mariadb-git-1d80e8e4f31b2e361241973467070975f6d80136.tar.gz |
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.
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/file_logger.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/mysys/file_logger.c b/mysys/file_logger.c index 71394be7afc..476ed44089e 100644 --- a/mysys/file_logger.c +++ b/mysys/file_logger.c @@ -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; |