diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2010-01-15 15:38:56 +1100 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2010-01-15 15:38:56 +1100 |
commit | a1d60b1511c710a093bf4c76a69b789288b1bd7d (patch) | |
tree | e436460545a915b7a06d198327b0f34861079f08 /ctdb/common/ctdb_logging.c | |
parent | f066939a62c72dde8858c53c7e38e3dd3892e7c8 (diff) | |
download | samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.tar.gz samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.tar.xz samba-a1d60b1511c710a093bf4c76a69b789288b1bd7d.zip |
Make the size of the in memory ringbuffer for keeping the recent log messages
configureable using --log-ringbuf-size=<num-entries>.
Add an entry in the sysconfig file to set this persistently.
(This used to be ctdb commit c79c2da69bc352f509e7fca4b9172a4b7f23c0f8)
Diffstat (limited to 'ctdb/common/ctdb_logging.c')
-rw-r--r-- | ctdb/common/ctdb_logging.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index 64507f4a20f..ea4d2716302 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -24,7 +24,8 @@ #include "../include/ctdb_private.h" #include "../include/ctdb.h" -#define MAX_LOG_ENTRIES 500000 +int log_ringbuf_size; + #define MAX_LOG_SIZE 128 static int first_entry; @@ -37,7 +38,7 @@ struct ctdb_log_entry { }; -static struct ctdb_log_entry log_entries[MAX_LOG_ENTRIES]; +static struct ctdb_log_entry *log_entries; /* * this function logs all messages for all levels to a ringbuffer @@ -46,6 +47,14 @@ static void log_ringbuffer_v(const char *format, va_list ap) { int ret; + if (log_entries == NULL && log_ringbuf_size != 0) { + /* Hope this works. We cant log anything if it doesnt anyway */ + log_entries = malloc(sizeof(struct ctdb_log_entry) * log_ringbuf_size); + } + if (log_entries == NULL) { + return; + } + log_entries[last_entry].message[0] = '\0'; ret = vsnprintf(&log_entries[last_entry].message[0], MAX_LOG_SIZE, format, ap); @@ -57,13 +66,13 @@ static void log_ringbuffer_v(const char *format, va_list ap) log_entries[last_entry].t = timeval_current(); last_entry++; - if (last_entry >= MAX_LOG_ENTRIES) { + if (last_entry >= log_ringbuf_size) { last_entry = 0; } if (first_entry == last_entry) { first_entry++; } - if (first_entry >= MAX_LOG_ENTRIES) { + if (first_entry >= log_ringbuf_size) { first_entry = 0; } } @@ -100,9 +109,13 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr struct tm *tm; char tbuf[100]; + if (log_entries == NULL) { + break; + } + if (log_entries[tmp_entry].level > log_addr->level) { tmp_entry++; - if (tmp_entry >= MAX_LOG_ENTRIES) { + if (tmp_entry >= log_ringbuf_size) { tmp_entry = 0; } continue; @@ -116,7 +129,7 @@ static void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr } tmp_entry++; - if (tmp_entry >= MAX_LOG_ENTRIES) { + if (tmp_entry >= log_ringbuf_size) { tmp_entry = 0; } } |