summaryrefslogtreecommitdiffstats
path: root/sysdep/unix/log.c
diff options
context:
space:
mode:
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 08711e1..eb08309 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