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.
This commit is contained in:
Lennart Poettering
2022-11-18 18:29:16 +01:00
committed by Luca Boccassi
parent 47b3e96647
commit 7d1e61cab6
10 changed files with 10 additions and 10 deletions

View 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)

View 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)

View 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;
}

View 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);

View 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,

View 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,

View 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);

View 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;

View 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));
}

View File

@@ -1112,7 +1112,7 @@ int manager_new(Manager **ret) {
.server_socket = -1,
.ratelimit = (RateLimit) {
.ratelimit = (const RateLimit) {
RATELIMIT_INTERVAL_USEC,
RATELIMIT_BURST
},