]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: make constant ratelimit compound actually const
authorLennart Poettering <lennart@poettering.net>
Fri, 18 Nov 2022 17:29:16 +0000 (18:29 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 22 Nov 2022 00:30:55 +0000 (01:30 +0100)
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.

src/basic/fs-util.c
src/core/manager.c
src/core/unit.c
src/import/import-fs.c
src/journal/journald-server.c
src/journal/journald-server.h
src/libsystemd/sd-journal/journal-file.c
src/resolve/resolved-dns-scope.c
src/test/test-ratelimit.c
src/timesync/timesyncd-manager.c

index 4d24cd59de96a7ffccb21ba30e0bc9746d5b8a24..33b4d1f07bfa51b86e52e62c641b77c11020e5d0 100644 (file)
@@ -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)
index ffaa9fa595b6057e3a043fd00474657f7ea74e5e..598604d69453d3e3cecb2077f1ccf7cefff12e7d 100644 (file)
@@ -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)
index d08c73613b0494b478752683e9fb4889688d40c6..c8dc97b99d7bfa05d6717ba270b1c5268be5f287 100644 (file)
@@ -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;
 }
index 4e7250c02e9df365802fdb7cda1d2aee5e0e6954..ca5d33c00821b0669f41a027fac52404fb207682 100644 (file)
@@ -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);
index e86aa481d93e5c01628d304eda51b37ccf9e72dd..cb94a037d572e744fb826c9278f26f37e8614b96 100644 (file)
@@ -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,
index 84efb04265873ea1f4b5a6f750c00f98a78b1c4a..fb512dcfeb7664906f3c19464053145848a014b7 100644 (file)
@@ -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,
index 23eed6f8dda3278372cc06bc33f4ba71c920af7f..9084da41e3648171ad25049d847908b16f7bb380 100644 (file)
@@ -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);
index 4f744499aabc66293d44e564acb02d9860bca065..b586d2c56f42210071d8f2ed99384f190633f31b 100644 (file)
@@ -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;
index d82bda53472f059a59c03dbd39ce81413db30055..de208c74083aa59b01cdfd958102cb50eeb4f99d 100644 (file)
@@ -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));
 }
index da540856ee93e360fa17ffa23ed9c970df9188a3..5b076157aac71ebb7ffc8f4508b83afbc1de0446 100644 (file)
@@ -1112,7 +1112,7 @@ int manager_new(Manager **ret) {
 
                 .server_socket = -1,
 
-                .ratelimit = (RateLimit) {
+                .ratelimit = (const RateLimit) {
                         RATELIMIT_INTERVAL_USEC,
                         RATELIMIT_BURST
                 },