]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Rename ratelimit_test to ratelimit_below
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 May 2018 09:16:52 +0000 (11:16 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 13 May 2018 20:08:30 +0000 (22:08 +0200)
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.

14 files changed:
src/basic/ratelimit.c
src/basic/ratelimit.h
src/core/device.c
src/core/manager.c
src/core/socket.c
src/core/unit.c
src/import/export-raw.c
src/import/export-tar.c
src/import/import-raw.c
src/import/import-tar.c
src/resolve/resolved-dns-scope.c
src/resolve/resolved-mdns.c
src/test/test-ratelimit.c
src/timesync/timesyncd-manager.c

index 6598b1a812e6a4363a93d2fa02778ccd1bb56b96..6804364f302bd178e09447ac768c426d18e2433a 100644 (file)
@@ -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);
index 6abab8f2909ee34f47a27fd3230bcbf6ec4ebe29..5a9aeb6486305a3810a0909f38c7546365183f2c 100644 (file)
@@ -43,4 +43,4 @@ typedef struct RateLimit {
                 _r->begin = 0;                           \
         } while (false)
 
-bool ratelimit_test(RateLimit *r);
+bool ratelimit_below(RateLimit *r);
index 0bf329c3d244f17704c2ebdde483189839c774d5..5a547432826e39798b11b9a1cd23bc6f706dd192 100644 (file)
@@ -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;
index 6412fee4764e215e85b6a6841c1a825fe541d1fc..d0d83ee69b17fd8865ea67b4750775b423f2776d 100644 (file)
@@ -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);
index 15a7c13149df31215238f465930c56ffe54aceec..45c49eac49da1196fd0208577889adaf0442e813 100644 (file)
@@ -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);
index 5b7beca369e1756c1478734b53137979a312b0d5..86660d17dc3d820ef96a7b14ebad1fd2d88190b9 100644 (file)
@@ -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;
         }
index 2ae146fd324538d90c282bfff8dc49178bef3205..c9070acf2020da48c9b90ffe901cfc600aac9fd2 100644 (file)
@@ -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);
index 72c48c68d7eafabdf1eeea8135b35d4a3c308841..4c60854972f94e56c7da4ae94c76acb935d98b61 100644 (file)
@@ -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);
index 6b79d8f170252b2be0060d7f0a8b4d8f590a0872..02ff289c1a877ee3306ba7c9fc9ac96fcfee0d92 100644 (file)
@@ -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);
index 81b96662d334bea6e17b2ce172a0f868c01fa2c9..2e748c629d1ab9cb609489710347de500e51e991 100644 (file)
@@ -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);
index 395dd2c5f4f80efb8f1d0cca3ea977d08b880026..763789c450f76d308e440e28b7a732c69e176f3a 100644 (file)
@@ -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)
index e27b0f4b70218f98ca0dddaf69f9840acc013b37..f54a204c93aa3ba0bea80e32f479c5e57119b34e 100644 (file)
@@ -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);
index 3871452232282bb444b0d9b57b012162066c26be..7001e821785ce7bbca281a4870f5efc9269ff5b3 100644 (file)
 #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;
 }
index 4f639577ad4280dd9a38aed24dff41c4a3cab40a..f76f07e655073b9c1667cda68308517b8eb4d91f 100644 (file)
@@ -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);