]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: use uniform style for RateLimit initialization
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 17 Nov 2023 16:55:35 +0000 (17:55 +0100)
committerLuca Boccassi <bluca@debian.org>
Wed, 22 Nov 2023 12:32:31 +0000 (12:32 +0000)
RateLimit is designed so that we can always initialize only the first two
fields explicitly. All other call sites use a single line for this.

src/basic/ratelimit.h
src/core/manager.c
src/core/path.c
src/core/socket.c
src/core/unit.c

index bb7160a895b9b3f55fb9fcff19b701c33844db78..492ea3b48dde0197a5e44c9f5b1c660a9eb0cd39 100644 (file)
@@ -12,6 +12,8 @@ typedef struct RateLimit {
         usec_t begin;
 } RateLimit;
 
+#define RATELIMIT_OFF (const RateLimit) { .interval = USEC_INFINITY, .burst = UINT_MAX }
+
 static inline void ratelimit_reset(RateLimit *rl) {
         rl->num = rl->begin = 0;
 }
index fcb7739b13605391f90c5367b40ee5532ff1a4a7..57ec5f38609f3579c27e0b3d6d7f0c5461239637 100644 (file)
@@ -927,10 +927,7 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
                 .first_boot = -1,
                 .test_run_flags = test_run_flags,
 
-                .dump_ratelimit = {
-                        .interval = 10 * USEC_PER_MINUTE,
-                        .burst = 10,
-                },
+                .dump_ratelimit = (const RateLimit) { .interval = 10 * USEC_PER_MINUTE, .burst = 10 },
 
                 .executor_fd = -EBADF,
         };
index 3ffa0acc625c2b1d5375125040965c1e2bb3124d..c09f001d50a69af3e63546dfc6c0c2c2e3ec30fb 100644 (file)
@@ -279,8 +279,7 @@ static void path_init(Unit *u) {
 
         p->directory_mode = 0755;
 
-        p->trigger_limit.interval = USEC_INFINITY;
-        p->trigger_limit.burst = UINT_MAX;
+        p->trigger_limit = RATELIMIT_OFF;
 }
 
 void path_free_specs(Path *p) {
index 156ac4a2d59df6e60efe71ebb98427d8a4032771..cb28c78840711d89e95d31eba2c5e7a1af934ba4 100644 (file)
@@ -100,8 +100,7 @@ static void socket_init(Unit *u) {
         s->control_pid = PIDREF_NULL;
         s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID;
 
-        s->trigger_limit.interval = USEC_INFINITY;
-        s->trigger_limit.burst = UINT_MAX;
+        s->trigger_limit = RATELIMIT_OFF;
 
         s->poll_limit_interval = USEC_INFINITY;
         s->poll_limit_burst = UINT_MAX;
index b37b1710f26c75fd5fba7383ecc1e19188da0bb2..41f3bdb226a4cc80adfecbc58be3d9daefbf5f17 100644 (file)
@@ -132,15 +132,12 @@ Unit* unit_new(Manager *m, size_t size) {
 
         u->last_section_private = -1;
 
-        u->start_ratelimit = (RateLimit) {
+        u->start_ratelimit = (const RateLimit) {
                 m->defaults.start_limit_interval,
-                m->defaults.start_limit_burst
+                m->defaults.start_limit_burst,
         };
 
-        u->auto_start_stop_ratelimit = (const RateLimit) {
-                10 * USEC_PER_SEC,
-                16
-        };
+        u->auto_start_stop_ratelimit = (const RateLimit) { .interval = 10 * USEC_PER_SEC, .burst = 16 };
 
         return u;
 }