diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-11 11:16:52 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-05-13 22:08:30 +0200 |
commit | 7994ac1d851b39ee87181fbdbfe413f83f65260a (patch) | |
tree | 2ff5d4c638a5e42d624afff22b81ead090e76237 /src | |
parent | 22dd8d350c635fb2ccd4641d19cf43f73cae4f6d (diff) | |
download | systemd-7994ac1d851b39ee87181fbdbfe413f83f65260a.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/ratelimit.c | 2 | ||||
-rw-r--r-- | src/basic/ratelimit.h | 2 | ||||
-rw-r--r-- | src/core/device.c | 2 | ||||
-rw-r--r-- | src/core/manager.c | 4 | ||||
-rw-r--r-- | src/core/socket.c | 2 | ||||
-rw-r--r-- | src/core/unit.c | 6 | ||||
-rw-r--r-- | src/import/export-raw.c | 2 | ||||
-rw-r--r-- | src/import/export-tar.c | 2 | ||||
-rw-r--r-- | src/import/import-raw.c | 2 | ||||
-rw-r--r-- | src/import/import-tar.c | 2 | ||||
-rw-r--r-- | src/resolve/resolved-dns-scope.c | 6 | ||||
-rw-r--r-- | src/resolve/resolved-mdns.c | 2 | ||||
-rw-r--r-- | src/test/test-ratelimit.c | 12 | ||||
-rw-r--r-- | src/timesync/timesyncd-manager.c | 2 |
14 files changed, 24 insertions, 24 deletions
diff --git a/src/basic/ratelimit.c b/src/basic/ratelimit.c index 6598b1a812..6804364f30 100644 --- a/src/basic/ratelimit.c +++ b/src/basic/ratelimit.c @@ -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); diff --git a/src/basic/ratelimit.h b/src/basic/ratelimit.h index 6abab8f290..5a9aeb6486 100644 --- a/src/basic/ratelimit.h +++ b/src/basic/ratelimit.h @@ -43,4 +43,4 @@ typedef struct RateLimit { _r->begin = 0; \ } while (false) -bool ratelimit_test(RateLimit *r); +bool ratelimit_below(RateLimit *r); diff --git a/src/core/device.c b/src/core/device.c index 0bf329c3d2..5a54743282 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -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; diff --git a/src/core/manager.c b/src/core/manager.c index 6412fee476..d0d83ee69b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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); diff --git a/src/core/socket.c b/src/core/socket.c index 15a7c13149..45c49eac49 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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); diff --git a/src/core/unit.c b/src/core/unit.c index 5b7beca369..86660d17dc 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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; } diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 2ae146fd32..c9070acf20 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -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); diff --git a/src/import/export-tar.c b/src/import/export-tar.c index 72c48c68d7..4c60854972 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -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); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 6b79d8f170..02ff289c1a 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -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); diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 81b96662d3..2e748c629d 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -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); diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 395dd2c5f4..763789c450 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -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) diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c index e27b0f4b70..f54a204c93 100644 --- a/src/resolve/resolved-mdns.c +++ b/src/resolve/resolved-mdns.c @@ -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); diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c index 3871452232..7001e82178 100644 --- a/src/test/test-ratelimit.c +++ b/src/test/test-ratelimit.c @@ -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; } diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 4f639577ad..f76f07e655 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -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); |