1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00

manager: apply clock epoch on updates too

If we're updating on a system with an invalid clock, and we're installing
a newer system version with a higher update, adjust the clock. This
way the invariant that the clock is always later than
max(compile time, timestamp file, other timestamp file) is maintained.

Also, adjust the wording of messages. When /usr/lib/clock-epoch was
introduced, "build time" stopped being acurate. Just say "epoch" instead.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2024-06-05 13:21:45 +02:00
parent ed23f7cbcb
commit 20fa2bb893
3 changed files with 14 additions and 10 deletions

View File

@ -18,7 +18,7 @@ int clock_reset_timewarp(void) {
return RET_NERRNO(settimeofday(NULL, &tz));
}
void clock_apply_epoch(void) {
void clock_apply_epoch(bool allow_backwards) {
usec_t epoch_usec = 0, timesyncd_usec = 0;
struct stat st;
int r;
@ -47,7 +47,9 @@ void clock_apply_epoch(void) {
if (now_usec < epoch_usec)
advance = true;
else if (CLOCK_VALID_RANGE_USEC_MAX > 0 && now_usec > usec_add(epoch_usec, CLOCK_VALID_RANGE_USEC_MAX))
else if (CLOCK_VALID_RANGE_USEC_MAX > 0 &&
now_usec > usec_add(epoch_usec, CLOCK_VALID_RANGE_USEC_MAX) &&
allow_backwards)
advance = false;
else
return; /* Nothing to do. */

View File

@ -1,5 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <stdbool.h>
int clock_reset_timewarp(void);
void clock_apply_epoch(void);
void clock_apply_epoch(bool allow_backwards);

View File

@ -1671,7 +1671,7 @@ static int become_shutdown(int objective, int retval) {
return -errno;
}
static void initialize_clock(void) {
static void initialize_clock_timewarp(void) {
int r;
/* This is called very early on, before we parse the kernel command line or otherwise figure out why
@ -1683,7 +1683,7 @@ static void initialize_clock(void) {
/* The very first call of settimeofday() also does a time warp in the kernel.
*
* In the rtc-in-local time mode, we set the kernel's timezone, and rely on external tools to
* take care of maintaining the RTC and do all adjustments. This matches the behavior of
* take care of maintaining the RTC and do all adjustments. This matches the behavior of
* Windows, which leaves the RTC alone if the registry tells that the RTC runs in UTC.
*/
r = clock_set_timezone(&min);
@ -1705,13 +1705,11 @@ static void initialize_clock(void) {
* time concepts will be treated as UTC that way.
*/
(void) clock_reset_timewarp();
clock_apply_epoch();
}
static void apply_clock_update(void) {
/* This is called later than initialize_clock(), i.e. after we parsed configuration files/kernel
* command line and such. */
/* This is called later than clock_apply_epoch(), i.e. after we have parsed
* configuration files/kernel command line and such. */
if (arg_clock_usec == 0)
return;
@ -3038,7 +3036,9 @@ int main(int argc, char *argv[]) {
}
if (!skip_setup)
initialize_clock();
initialize_clock_timewarp();
clock_apply_epoch(/* allow_backwards= */ !skip_setup);
/* Set the default for later on, but don't actually open the logs like this for
* now. Note that if we are transitioning from the initrd there might still be