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=5adf1ae10d39606eb11216282cb30ec70e1e410a;hb=fa734f4da837abe6c893e75c95be78527db72c0f;hpb=d6c9574fb558d9e304699b1cc7522c3b133adfc9 diff --git a/src/ratelimit.c b/src/ratelimit.c index 5adf1ae10..93157c7a2 100644 --- a/src/ratelimit.c +++ b/src/ratelimit.c @@ -30,33 +30,28 @@ bool ratelimit_test(RateLimit *r) { usec_t ts; - ts = now(CLOCK_MONOTONIC); - assert(r); - assert(r->interval > 0); - assert(r->burst > 0); - if (r->begin <= 0 || - r->begin + r->interval < ts) { + 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); + 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; }