X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fratelimit.c;h=93157c7a2e071cb177676909e04cab3be11d54ed;hp=1e5ed03c55dbde295d096ba679cdacaae588db07;hb=fa734f4da837abe6c893e75c95be78527db72c0f;hpb=e99e38bbdcca3fe5956823bdb3d38544ccf93221 diff --git a/src/ratelimit.c b/src/ratelimit.c index 1e5ed03c5..93157c7a2 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,30 @@ * , which is licensed GPLv2. */ bool ratelimit_test(RateLimit *r) { - usec_t timestamp; - - timestamp = now(CLOCK_MONOTONIC); + usec_t ts; assert(r); - assert(r->interval > 0); - assert(r->burst > 0); - if (r->begin <= 0 || - r->begin + r->interval < timestamp) { + if (r->interval <= 0 || r->burst <= 0) + return true; - if (r->n_missed > 0) - log_warning("%u events suppressed", r->n_missed); + ts = now(CLOCK_MONOTONIC); - r->begin = timestamp; + if (r->begin <= 0 || + r->begin + r->interval < ts) { + r->begin = ts; - /* 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; }