diff options
-rw-r--r-- | src/basic/ratelimit.h | 32 | ||||
-rw-r--r-- | src/core/manager.c | 5 | ||||
-rw-r--r-- | src/core/unit.c | 6 | ||||
-rw-r--r-- | src/import/export-raw.c | 3 | ||||
-rw-r--r-- | src/import/export-tar.c | 3 | ||||
-rw-r--r-- | src/import/import-fs.c | 2 | ||||
-rw-r--r-- | src/import/import-raw.c | 3 | ||||
-rw-r--r-- | src/import/import-tar.c | 3 | ||||
-rw-r--r-- | src/resolve/resolved-dns-scope.c | 2 | ||||
-rw-r--r-- | src/test/test-ratelimit.c | 4 | ||||
-rw-r--r-- | src/timesync/timesyncd-manager.c | 2 |
11 files changed, 20 insertions, 45 deletions
diff --git a/src/basic/ratelimit.h b/src/basic/ratelimit.h index de91def28d..79e33b6a62 100644 --- a/src/basic/ratelimit.h +++ b/src/basic/ratelimit.h @@ -7,34 +7,14 @@ #include "util.h" typedef struct RateLimit { - usec_t interval; - usec_t begin; - unsigned burst; + usec_t interval; /* Keep those two fields first so they can be initialized easily: */ + unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */ unsigned num; + usec_t begin; } RateLimit; -#define RATELIMIT_DEFINE(_name, _interval, _burst) \ - RateLimit _name = { \ - .interval = (_interval), \ - .burst = (_burst), \ - .num = 0, \ - .begin = 0 \ - } - -#define RATELIMIT_INIT(v, _interval, _burst) \ - do { \ - RateLimit *_r = &(v); \ - _r->interval = (_interval); \ - _r->burst = (_burst); \ - _r->num = 0; \ - _r->begin = 0; \ - } while (false) - -#define RATELIMIT_RESET(v) \ - do { \ - RateLimit *_r = &(v); \ - _r->num = 0; \ - _r->begin = 0; \ - } while (false) +static inline void ratelimit_reset(RateLimit *rl) { + rl->num = rl->begin = 0; +} bool ratelimit_below(RateLimit *r); diff --git a/src/core/manager.c b/src/core/manager.c index d9114bb0c5..dac4248356 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -815,7 +815,7 @@ int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager } /* Reboot immediately if the user hits C-A-D more often than 7x per 2s */ - RATELIMIT_INIT(m->ctrl_alt_del_ratelimit, 2 * USEC_PER_SEC, 7); + m->ctrl_alt_del_ratelimit = (RateLimit) { .interval = 2 * USEC_PER_SEC, .burst = 7 }; r = manager_default_environment(m); if (r < 0) @@ -2855,10 +2855,9 @@ static int manager_dispatch_jobs_in_progress(sd_event_source *source, usec_t use } int manager_loop(Manager *m) { + RateLimit rl = { .interval = 1*USEC_PER_SEC, .burst = 50000 }; int r; - RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000); - assert(m); assert(m->objective == MANAGER_OK); /* Ensure manager_startup() has been called */ diff --git a/src/core/unit.c b/src/core/unit.c index 87a5976dcc..7d6ee792ad 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -123,8 +123,8 @@ Unit *unit_new(Manager *m, size_t size) { u->last_section_private = -1; - RATELIMIT_INIT(u->start_limit, m->default_start_limit_interval, m->default_start_limit_burst); - RATELIMIT_INIT(u->auto_stop_ratelimit, 10 * USEC_PER_SEC, 16); + u->start_limit = (RateLimit) { m->default_start_limit_interval, m->default_start_limit_burst }; + u->auto_stop_ratelimit = (RateLimit) { 10 * USEC_PER_SEC, 16 }; for (CGroupIOAccountingMetric i = 0; i < _CGROUP_IO_ACCOUNTING_METRIC_MAX; i++) u->io_accounting_last[i] = UINT64_MAX; @@ -4000,7 +4000,7 @@ void unit_reset_failed(Unit *u) { if (UNIT_VTABLE(u)->reset_failed) UNIT_VTABLE(u)->reset_failed(u); - RATELIMIT_RESET(u->start_limit); + ratelimit_reset(&u->start_limit); u->start_limit_hit = false; } diff --git a/src/import/export-raw.c b/src/import/export-raw.c index c1c946cd2b..57b4334a65 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -96,10 +96,9 @@ int raw_export_new( .on_finished = on_finished, .userdata = userdata, .last_percent = (unsigned) -1, + .progress_rate_limit = { 100 * USEC_PER_MSEC, 1 }, }; - RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1); - if (event) e->event = sd_event_ref(event); else { diff --git a/src/import/export-tar.c b/src/import/export-tar.c index ed546769f3..b66b5ee37c 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -99,10 +99,9 @@ int tar_export_new( .userdata = userdata, .quota_referenced = (uint64_t) -1, .last_percent = (unsigned) -1, + .progress_rate_limit = { 100 * USEC_PER_MSEC, 1 }, }; - RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1); - if (event) e->event = sd_event_ref(event); else { diff --git a/src/import/import-fs.c b/src/import/import-fs.c index f8f3a23206..468303a6dc 100644 --- a/src/import/import-fs.c +++ b/src/import/import-fs.c @@ -169,7 +169,7 @@ static int import_fs(int argc, char *argv[], void *userdata) { (void) mkdir_parents_label(temp_path, 0700); - RATELIMIT_INIT(progress.limit, 200*USEC_PER_MSEC, 1); + progress.limit = (RateLimit) { 200*USEC_PER_MSEC, 1 }; /* Hook into SIGINT/SIGTERM, so that we can cancel things then */ assert(sigaction(SIGINT, &sa, &old_sigint_sa) >= 0); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index b905832603..dc73387bc2 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -111,10 +111,9 @@ int raw_import_new( .userdata = userdata, .last_percent = (unsigned) -1, .image_root = TAKE_PTR(root), + .progress_rate_limit = { 100 * USEC_PER_MSEC, 1 }, }; - RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1); - if (event) i->event = sd_event_ref(event); else { diff --git a/src/import/import-tar.c b/src/import/import-tar.c index f3eff82a29..c2ece7af74 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -119,10 +119,9 @@ int tar_import_new( .userdata = userdata, .last_percent = (unsigned) -1, .image_root = TAKE_PTR(root), + .progress_rate_limit = { 100 * USEC_PER_MSEC, 1 }, }; - RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1); - if (event) i->event = sd_event_ref(event); else { diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index eb304e52e5..ddcf164ebd 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -70,7 +70,7 @@ int dns_scope_new(Manager *m, DnsScope **ret, Link *l, DnsProtocol protocol, int log_debug("New scope on link %s, protocol %s, family %s", l ? l->ifname : "*", dns_protocol_to_string(protocol), family == AF_UNSPEC ? "*" : af_to_name(family)); /* Enforce ratelimiting for the multicast protocols */ - RATELIMIT_INIT(s->ratelimit, MULTICAST_RATELIMIT_INTERVAL_USEC, MULTICAST_RATELIMIT_BURST); + s->ratelimit = (RateLimit) { MULTICAST_RATELIMIT_INTERVAL_USEC, MULTICAST_RATELIMIT_BURST }; *ret = s; return 0; diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c index 9f344e1152..56a6fa2d76 100644 --- a/src/test/test-ratelimit.c +++ b/src/test/test-ratelimit.c @@ -8,7 +8,7 @@ static void test_ratelimit_below(void) { int i; - RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10); + RateLimit ratelimit = { 1 * USEC_PER_SEC, 10 }; for (i = 0; i < 10; i++) assert_se(ratelimit_below(&ratelimit)); @@ -17,7 +17,7 @@ static void test_ratelimit_below(void) { for (i = 0; i < 10; i++) assert_se(ratelimit_below(&ratelimit)); - RATELIMIT_INIT(ratelimit, 0, 10); + ratelimit = (RateLimit) { 0, 10 }; for (i = 0; i < 10000; i++) assert_se(ratelimit_below(&ratelimit)); } diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 3c3a7fe69a..604c7e01be 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -1094,7 +1094,7 @@ int manager_new(Manager **ret) { m->server_socket = m->clock_watch_fd = -1; - RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST); + m->ratelimit = (RateLimit) { RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST }; r = sd_event_default(&m->event); if (r < 0) |