/* Modelled after Linux' lib/ratelimit.c by Dave Young
* <hidave.darkstar@gmail.com>, which is licensed GPLv2. */
-bool ratelimit_test(RateLimit *r) {
+bool ratelimit_below(RateLimit *r) {
usec_t ts;
assert(r);
_r->begin = 0; \
} while (false)
-bool ratelimit_test(RateLimit *r);
+bool ratelimit_below(RateLimit *r);
if (revents != EPOLLIN) {
static RATELIMIT_DEFINE(limit, 10*USEC_PER_SEC, 5);
- if (ratelimit_test(&limit))
+ if (ratelimit_below(&limit))
log_warning("Failed to get udev event");
if (!(revents & EPOLLIN))
return 0;
* 7 times within 2s, we reboot/shutdown immediately,
* unless it was disabled in system.conf */
- if (ratelimit_test(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE)
+ if (ratelimit_below(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE)
manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY);
else
emergency_action(m, m->cad_burst_action, NULL,
if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m))
watchdog_ping();
- if (!ratelimit_test(&rl)) {
+ if (!ratelimit_below(&rl)) {
/* Yay, something is going seriously wrong, pause a little */
log_warning("Looping too fast. Throttling execution a little.");
sleep(1);
return;
}
- if (!ratelimit_test(&s->trigger_limit)) {
+ if (!ratelimit_below(&s->trigger_limit)) {
safe_close(cfd);
log_unit_warning(UNIT(s), "Trigger limit hit, refusing further activation.");
socket_enter_stop_pre(s, SOCKET_FAILURE_TRIGGER_LIMIT_HIT);
int unit_start_limit_test(Unit *u) {
assert(u);
- if (ratelimit_test(&u->start_limit)) {
+ if (ratelimit_below(&u->start_limit)) {
u->start_limit_hit = false;
return 0;
}
/* If stopping a unit fails continuously we might enter a stop
* loop here, hence stop acting on the service being
* unnecessary after a while. */
- if (!ratelimit_test(&u->auto_stop_ratelimit)) {
+ if (!ratelimit_below(&u->auto_stop_ratelimit)) {
log_unit_warning(u, "Unit not needed anymore, but not stopping since we tried this too often recently.");
return;
}
/* If stopping a unit fails continuously we might enter a stop
* loop here, hence stop acting on the service being
* unnecessary after a while. */
- if (!ratelimit_test(&u->auto_stop_ratelimit)) {
+ if (!ratelimit_below(&u->auto_stop_ratelimit)) {
log_unit_warning(u, "Unit is bound to inactive unit %s, but not stopping since we tried this too often recently.", other->id);
return;
}
if (percent == e->last_percent)
return;
- if (!ratelimit_test(&e->progress_rate_limit))
+ if (!ratelimit_below(&e->progress_rate_limit))
return;
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
if (percent == e->last_percent)
return;
- if (!ratelimit_test(&e->progress_rate_limit))
+ if (!ratelimit_below(&e->progress_rate_limit))
return;
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
if (percent == i->last_percent)
return;
- if (!ratelimit_test(&i->progress_rate_limit))
+ if (!ratelimit_below(&i->progress_rate_limit))
return;
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
if (percent == i->last_percent)
return;
- if (!ratelimit_test(&i->progress_rate_limit))
+ if (!ratelimit_below(&i->progress_rate_limit))
return;
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
if (DNS_PACKET_QDCOUNT(p) > 1)
return -EOPNOTSUPP;
- if (!ratelimit_test(&s->ratelimit))
+ if (!ratelimit_below(&s->ratelimit))
return -EBUSY;
family = s->family;
case DNS_PROTOCOL_MDNS:
assert(fd < 0);
- if (!ratelimit_test(&s->ratelimit))
+ if (!ratelimit_below(&s->ratelimit))
return -EBUSY;
family = s->family;
} else {
int fd;
- if (!ratelimit_test(&s->ratelimit))
+ if (!ratelimit_below(&s->ratelimit))
return;
if (p->family == AF_INET)
if (r < 0)
return log_debug_errno(r, "Failed to build reply packet: %m");
- if (!ratelimit_test(&s->ratelimit))
+ if (!ratelimit_below(&s->ratelimit))
return 0;
r = dns_scope_emit_udp(s, -1, reply);
#include "ratelimit.h"
#include "time-util.h"
-static void test_ratelimit_test(void) {
+static void test_ratelimit_below(void) {
int i;
RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
for (i = 0; i < 10; i++)
- assert_se(ratelimit_test(&ratelimit));
- assert_se(!ratelimit_test(&ratelimit));
+ assert_se(ratelimit_below(&ratelimit));
+ assert_se(!ratelimit_below(&ratelimit));
sleep(1);
for (i = 0; i < 10; i++)
- assert_se(ratelimit_test(&ratelimit));
+ assert_se(ratelimit_below(&ratelimit));
RATELIMIT_INIT(ratelimit, 0, 10);
for (i = 0; i < 10000; i++)
- assert_se(ratelimit_test(&ratelimit));
+ assert_se(ratelimit_below(&ratelimit));
}
int main(int argc, char *argv[]) {
- test_ratelimit_test();
+ test_ratelimit_below();
return 0;
}
manager_disconnect(m);
m->event_retry = sd_event_source_unref(m->event_retry);
- if (!ratelimit_test(&m->ratelimit)) {
+ if (!ratelimit_below(&m->ratelimit)) {
log_debug("Slowing down attempts to contact servers.");
r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + RETRY_USEC, 0, manager_retry_connect, m);