From: Lennart Poettering Date: Fri, 18 Nov 2022 17:29:16 +0000 (+0100) Subject: tree-wide: make constant ratelimit compound actually const X-Git-Tag: v253-rc1~479 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d1e61cab6d27ed95372a313df3cd4538cf2880e;p=thirdparty%2Fsystemd.git tree-wide: make constant ratelimit compound actually const The compiler should recognize that these are constant expressions, but let's better make this explicit, so that the linker can safely share the initializations all over the place. --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 4d24cd59de9..33b4d1f07bf 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -903,7 +903,7 @@ int posix_fallocate_loop(int fd, uint64_t offset, uint64_t size) { /* On EINTR try a couple of times more, but protect against busy looping * (not more than 16 times per 10s) */ - rl = (RateLimit) { 10 * USEC_PER_SEC, 16 }; + rl = (const RateLimit) { 10 * USEC_PER_SEC, 16 }; while (ratelimit_below(&rl)) { r = posix_fallocate(fd, offset, size); if (r != EINTR) diff --git a/src/core/manager.c b/src/core/manager.c index ffaa9fa595b..598604d6945 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -890,7 +890,7 @@ int manager_new(LookupScope scope, ManagerTestRunFlags test_run_flags, Manager * } /* Reboot immediately if the user hits C-A-D more often than 7x per 2s */ - m->ctrl_alt_del_ratelimit = (RateLimit) { .interval = 2 * USEC_PER_SEC, .burst = 7 }; + m->ctrl_alt_del_ratelimit = (const RateLimit) { .interval = 2 * USEC_PER_SEC, .burst = 7 }; r = manager_default_environment(m); if (r < 0) diff --git a/src/core/unit.c b/src/core/unit.c index d08c73613b0..c8dc97b99d7 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -127,7 +127,7 @@ Unit* unit_new(Manager *m, size_t size) { u->last_section_private = -1; u->start_ratelimit = (RateLimit) { m->default_start_limit_interval, m->default_start_limit_burst }; - u->auto_start_stop_ratelimit = (RateLimit) { 10 * USEC_PER_SEC, 16 }; + u->auto_start_stop_ratelimit = (const RateLimit) { 10 * USEC_PER_SEC, 16 }; return u; } diff --git a/src/import/import-fs.c b/src/import/import-fs.c index 4e7250c02e9..ca5d33c0082 100644 --- a/src/import/import-fs.c +++ b/src/import/import-fs.c @@ -188,7 +188,7 @@ static int import_fs(int argc, char *argv[], void *userdata) { (void) mkdir_parents_label(dest, 0700); - progress.limit = (RateLimit) { 200*USEC_PER_MSEC, 1 }; + progress.limit = (const RateLimit) { 200*USEC_PER_MSEC, 1 }; { BLOCK_SIGNALS(SIGINT, SIGTERM); diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index e86aa481d93..cb94a037d57 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -83,7 +83,7 @@ #define IDLE_TIMEOUT_USEC (30*USEC_PER_SEC) -#define FAILED_TO_WRITE_ENTRY_RATELIMIT ((RateLimit) { .interval = 1 * USEC_PER_SEC, .burst = 1 }) +#define FAILED_TO_WRITE_ENTRY_RATELIMIT ((const RateLimit) { .interval = 1 * USEC_PER_SEC, .burst = 1 }) static int determine_path_usage( Server *s, diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 84efb042658..fb512dcfeb7 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -20,7 +20,7 @@ typedef struct Server Server; #include "time-util.h" #include "varlink.h" -#define JOURNALD_LOG_RATELIMIT ((RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 }) +#define JOURNALD_LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 }) typedef enum Storage { STORAGE_AUTO, diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 23eed6f8dda..9084da41e36 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -4163,7 +4163,7 @@ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot_id, u /* Ideally this would be a function parameter but initializers for static fields have to be compile * time constants so we hardcode the interval instead. */ -#define LOG_RATELIMIT ((RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 }) +#define LOG_RATELIMIT ((const RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 }) bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec, int log_level) { assert(f); diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 4f744499aab..b586d2c56f4 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -71,7 +71,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 */ - s->ratelimit = (RateLimit) { MULTICAST_RATELIMIT_INTERVAL_USEC, MULTICAST_RATELIMIT_BURST }; + s->ratelimit = (const 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 d82bda53472..de208c74083 100644 --- a/src/test/test-ratelimit.c +++ b/src/test/test-ratelimit.c @@ -18,7 +18,7 @@ TEST(ratelimit_below) { for (i = 0; i < 10; i++) assert_se(ratelimit_below(&ratelimit)); - ratelimit = (RateLimit) { 0, 10 }; + ratelimit = (const 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 da540856ee9..5b076157aac 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -1112,7 +1112,7 @@ int manager_new(Manager **ret) { .server_socket = -1, - .ratelimit = (RateLimit) { + .ratelimit = (const RateLimit) { RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST },