chiark / gitweb /
ratelimit: fix off-by-one
authorMichael Olbrich <m.olbrich@pengutronix.de>
Wed, 13 Feb 2013 07:00:46 +0000 (08:00 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 13 Feb 2013 13:45:13 +0000 (08:45 -0500)
The current code might make sense during startup for service restart
limiting:
With burst=1 after starting num is 1, so the next ('first') restart is
still accepted ( 1 <= 1). However, once interval has expired, num is 1
after the first restart, so the second restart is also accepted.

This change is also useful in combination with watchdogs:
With burst=1 and a very large interval the system can be restarted on
the first failure.

src/shared/ratelimit.c

index 1054d52f979ee8e493c52875a40d68b37994cc8e..01b62b7b384e25799b1d90a697290039e2a3cbd9 100644 (file)
@@ -46,7 +46,7 @@ bool ratelimit_test(RateLimit *r) {
                 goto good;
         }
 
-        if (r->num <= r->burst)
+        if (r->num < r->burst)
                 goto good;
 
         return false;