summaryrefslogtreecommitdiff
path: root/sysdep/unix/log.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-02-26 14:23:54 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2009-02-26 14:23:54 +0100
commitcb5303927188de9504a6e18aedec299956a22b6f (patch)
tree0d8ac146c9d84b85e382fb994d9e10688c2e3e36 /sysdep/unix/log.c
parenta9dc5e1ef2fd08c53bceb54690f6dac83ddf0c81 (diff)
Rate limit for most abundant log messages
Diffstat (limited to 'sysdep/unix/log.c')
-rw-r--r--sysdep/unix/log.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 08711e17..eb083099 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -30,6 +30,9 @@ static FILE *dbgf = NULL;
static list *current_log_list;
static list init_log_list;
+bird_clock_t rate_limit_time = 5;
+int rate_limit_count = 5;
+
#ifdef HAVE_SYSLOG
#include <sys/syslog.h>
@@ -126,6 +129,35 @@ log_msg(char *msg, ...)
va_end(args);
}
+void
+log_rl(struct rate_limit *rl, char *msg, ...)
+{
+ int class = 1;
+ va_list args;
+
+ bird_clock_t delta = now - rl->timestamp;
+ if ((0 <= delta) && (delta < rate_limit_time))
+ {
+ rl->count++;
+ }
+ else
+ {
+ rl->timestamp = now;
+ rl->count = 1;
+ }
+
+ if (rl->count > rate_limit_count)
+ return;
+
+ va_start(args, msg);
+ if (*msg >= 1 && *msg <= 8)
+ class = *msg++;
+ vlog(class, msg, args);
+ if (rl->count == rate_limit_count)
+ vlog(class, "...", args);
+ va_end(args);
+}
+
/**
* bug - report an internal error
* @msg: a printf-like error message