]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ratelimit: add ratelimit_configured() helper
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Oct 2020 16:40:35 +0000 (18:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 9 Oct 2020 06:58:59 +0000 (08:58 +0200)
This helper alone doesn't make too much sense, but it's preparatory work
for #17274, and I guess it can't hurt to land it early, it does make the
ratelimit code a tiny bit prettier after all.

src/basic/ratelimit.c
src/basic/ratelimit.h

index 4e04e04426256a869102bb60da0490f1ec19bdc7..2e94eed843c60d6d747413482d90c5ab399fbb9d 100644 (file)
@@ -13,7 +13,7 @@ bool ratelimit_below(RateLimit *r) {
 
         assert(r);
 
-        if (r->interval <= 0 || r->burst <= 0)
+        if (!ratelimit_configured(r))
                 return true;
 
         ts = now(CLOCK_MONOTONIC);
index 79e33b6a62ea87bf3db26e7d51120542f10c9397..9d409b04b3bb33fd81f5f28b516b05d5ebd84be2 100644 (file)
@@ -17,4 +17,8 @@ static inline void ratelimit_reset(RateLimit *rl) {
         rl->num = rl->begin = 0;
 }
 
+static inline bool ratelimit_configured(RateLimit *rl) {
+        return rl->interval > 0 && rl->burst > 0;
+}
+
 bool ratelimit_below(RateLimit *r);