]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: use usec_add() and usec_sub_unsigned()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 4 Dec 2023 07:19:47 +0000 (16:19 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 6 Dec 2023 02:01:28 +0000 (11:01 +0900)
src/journal/journald.c

index 2210e17c0aea878f5d535fb9c71453312a71e7ea..b6b08da3b3624240ba89dd76ebd3fd33013dc1c7 100644 (file)
@@ -75,7 +75,7 @@ static int run(int argc, char *argv[]) {
         server_space_usage_message(s, NULL);
 
         for (;;) {
-                usec_t t = USEC_INFINITY, n;
+                usec_t t, n;
 
                 r = sd_event_get_state(s->event);
                 if (r < 0)
@@ -86,29 +86,25 @@ static int run(int argc, char *argv[]) {
                 n = now(CLOCK_REALTIME);
 
                 if (s->max_retention_usec > 0 && s->oldest_file_usec > 0) {
+                        /* Calculate when to rotate the next time */
+                        t = usec_sub_unsigned(usec_add(s->oldest_file_usec, s->max_retention_usec), n);
 
                         /* The retention time is reached, so let's vacuum! */
-                        if (s->oldest_file_usec + s->max_retention_usec < n) {
+                        if (t <= 0) {
                                 log_info("Retention time reached, rotating.");
                                 server_rotate(s);
                                 server_vacuum(s, /* verbose = */ false);
                                 continue;
                         }
-
-                        /* Calculate when to rotate the next time */
-                        t = s->oldest_file_usec + s->max_retention_usec - n;
-                }
+                } else
+                        t = USEC_INFINITY;
 
 #if HAVE_GCRYPT
                 if (s->system_journal) {
                         usec_t u;
 
-                        if (journal_file_next_evolve_usec(s->system_journal, &u)) {
-                                if (n >= u)
-                                        t = 0;
-                                else
-                                        t = MIN(t, u - n);
-                        }
+                        if (journal_file_next_evolve_usec(s->system_journal, &u))
+                                t = MIN(t, usec_sub_unsigned(u, n));
                 }
 #endif