Rename ratelimit_test to ratelimit_below
When I see "test", I have to think three times what the return value
means. With "below" this is immediately clear. ratelimit_below(&limit)
sounds almost like English and is imho immediately obvious.
(I also considered ratelimit_ok, but this strongly implies that being under the
limit is somehow better. Most of the times this is true, but then we use the
ratelimit to detect triple-c-a-d, and "ok" doesn't fit so well there.)
C.f. a1bcaa07
.
This commit is contained in:
parent
22dd8d350c
commit
7994ac1d85
|
@ -13,7 +13,7 @@
|
|||
/* 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);
|
||||
|
|
|
@ -43,4 +43,4 @@ typedef struct RateLimit {
|
|||
_r->begin = 0; \
|
||||
} while (false)
|
||||
|
||||
bool ratelimit_test(RateLimit *r);
|
||||
bool ratelimit_below(RateLimit *r);
|
||||
|
|
|
@ -845,7 +845,7 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
|
|||
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;
|
||||
|
|
|
@ -2337,7 +2337,7 @@ static void manager_handle_ctrl_alt_del(Manager *m) {
|
|||
* 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,
|
||||
|
@ -2632,7 +2632,7 @@ int manager_loop(Manager *m) {
|
|||
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);
|
||||
|
|
|
@ -2245,7 +2245,7 @@ static void socket_enter_running(Socket *s, int cfd) {
|
|||
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);
|
||||
|
|
|
@ -1695,7 +1695,7 @@ void unit_status_emit_starting_stopping_reloading(Unit *u, JobType t) {
|
|||
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;
|
||||
}
|
||||
|
@ -1988,7 +1988,7 @@ static void unit_check_unneeded(Unit *u) {
|
|||
/* 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;
|
||||
}
|
||||
|
@ -2038,7 +2038,7 @@ static void unit_check_binds_to(Unit *u) {
|
|||
/* 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;
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ static void raw_export_report_progress(RawExport *e) {
|
|||
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);
|
||||
|
|
|
@ -134,7 +134,7 @@ static void tar_export_report_progress(TarExport *e) {
|
|||
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);
|
||||
|
|
|
@ -149,7 +149,7 @@ static void raw_import_report_progress(RawImport *i) {
|
|||
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);
|
||||
|
|
|
@ -156,7 +156,7 @@ static void tar_import_report_progress(TarImport *i) {
|
|||
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);
|
||||
|
|
|
@ -221,7 +221,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) {
|
|||
if (DNS_PACKET_QDCOUNT(p) > 1)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (!ratelimit_test(&s->ratelimit))
|
||||
if (!ratelimit_below(&s->ratelimit))
|
||||
return -EBUSY;
|
||||
|
||||
family = s->family;
|
||||
|
@ -246,7 +246,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) {
|
|||
case DNS_PROTOCOL_MDNS:
|
||||
assert(fd < 0);
|
||||
|
||||
if (!ratelimit_test(&s->ratelimit))
|
||||
if (!ratelimit_below(&s->ratelimit))
|
||||
return -EBUSY;
|
||||
|
||||
family = s->family;
|
||||
|
@ -759,7 +759,7 @@ void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p) {
|
|||
} else {
|
||||
int fd;
|
||||
|
||||
if (!ratelimit_test(&s->ratelimit))
|
||||
if (!ratelimit_below(&s->ratelimit))
|
||||
return;
|
||||
|
||||
if (p->family == AF_INET)
|
||||
|
|
|
@ -251,7 +251,7 @@ static int mdns_scope_process_query(DnsScope *s, DnsPacket *p) {
|
|||
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);
|
||||
|
|
|
@ -11,24 +11,24 @@
|
|||
#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;
|
||||
}
|
||||
|
|
|
@ -804,7 +804,7 @@ int manager_connect(Manager *m) {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue