summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-03-05 10:36:51 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2021-03-05 10:36:51 +0200
commit8bab5bb332aec671febbfc1b9c30c2b269c1d7d4 (patch)
tree67f1dfddcba6458408565eb9065234a325156d66 /mysys
parent82efe4a15a985c3902e80eb7e1a70841c08d9f2e (diff)
parent5bd994b0d56d11bf62717a84172c49ca9ed37de4 (diff)
downloadmariadb-git-8bab5bb332aec671febbfc1b9c30c2b269c1d7d4.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'mysys')
-rw-r--r--mysys/file_logger.c55
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;