X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fratelimit.c;h=1ddc83187f59295fc2402a63a75fa637fbf88210;hp=1e5ed03c55dbde295d096ba679cdacaae588db07;hb=ff01d048b4c1455241c894cf7982662c9d28fd34;hpb=e99e38bbdcca3fe5956823bdb3d38544ccf93221 diff --git a/src/ratelimit.c b/src/ratelimit.c index 1e5ed03c5..1ddc83187 100644 --- a/src/ratelimit.c +++ b/src/ratelimit.c @@ -1,4 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*** This file is part of systemd. @@ -28,35 +28,29 @@ * , which is licensed GPLv2. */ bool ratelimit_test(RateLimit *r) { - usec_t timestamp; + usec_t ts; - timestamp = now(CLOCK_MONOTONIC); + ts = now(CLOCK_MONOTONIC); assert(r); assert(r->interval > 0); assert(r->burst > 0); if (r->begin <= 0 || - r->begin + r->interval < timestamp) { + r->begin + r->interval < ts) { + r->begin = ts; - if (r->n_missed > 0) - log_warning("%u events suppressed", r->n_missed); - - r->begin = timestamp; - - /* Reset counters */ - r->n_printed = 0; - r->n_missed = 0; + /* Reset counter */ + r->num = 0; goto good; } - if (r->n_printed <= r->burst) + if (r->num <= r->burst) goto good; - r->n_missed++; return false; good: - r->n_printed++; + r->num++; return true; }