From: Yu Watanabe Date: Mon, 4 Dec 2023 07:19:47 +0000 (+0900) Subject: journal: use usec_add() and usec_sub_unsigned() X-Git-Tag: v256-rc1~1561^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=90c27eb43baea96d5976c0d06d62cccda5dc0354;p=thirdparty%2Fsystemd.git journal: use usec_add() and usec_sub_unsigned() --- diff --git a/src/journal/journald.c b/src/journal/journald.c index 2210e17c0ae..b6b08da3b36 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -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