summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-18 18:29:16 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2022-11-22 01:30:55 +0100
commit7d1e61cab6d27ed95372a313df3cd4538cf2880e (patch)
tree6a728c8fe92653b263a0092ecb1ec7dcb66207e6
parent47b3e96647e18e8ca219c4792ab769344eea11bb (diff)
downloadsystemd-7d1e61cab6d27ed95372a313df3cd4538cf2880e.tar.gz
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.
-rw-r--r--src/basic/fs-util.c2
-rw-r--r--src/core/manager.c2
-rw-r--r--src/core/unit.c2
-rw-r--r--src/import/import-fs.c2
-rw-r--r--src/journal/journald-server.c2
-rw-r--r--src/journal/journald-server.h2
-rw-r--r--src/libsystemd/sd-journal/journal-file.c2
-rw-r--r--src/resolve/resolved-dns-scope.c2
-rw-r--r--src/test/test-ratelimit.c2
-rw-r--r--src/timesync/timesyncd-manager.c2
10 files changed, 10 insertions, 10 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 4d24cd59de..33b4d1f07b 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 ffaa9fa595..598604d694 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 d08c73613b..c8dc97b99d 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 4e7250c02e..ca5d33c008 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 e86aa481d9..cb94a037d5 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 84efb04265..fb512dcfeb 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 23eed6f8dd..9084da41e3 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 4f744499aa..b586d2c56f 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 d82bda5347..de208c7408 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 da540856ee..5b076157aa 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
},