resolved: apply epoch to system time from PID 1

For use in timesyncd we already defined a compile-time "epoch" value, which is based on the mtime of the NEWS file, and
specifies a point in time we know lies in the past at runtime. timesyncd uses this to filter out nonsensical timestamp
file data, and bump the system clock to a time that is after the build time of systemd. This patch adds similar bumping
code to earliest PID 1 initialization, so that the system never continues operation with a clock that is in the 1970ies
or even 1930s.
This commit is contained in:
Lennart Poettering
2016-02-03 23:58:24 +01:00
parent 5f932eb9af
commit 021dd87bc0
3 changed files with 22 additions and 1 deletions
+14
View File
@@ -146,3 +146,17 @@ int clock_reset_timewarp(void) {
return 0;
}
#define TIME_EPOCH_USEC ((usec_t) TIME_EPOCH * USEC_PER_SEC)
int clock_apply_epoch(void) {
struct timespec ts;
if (now(CLOCK_REALTIME) >= TIME_EPOCH_USEC)
return 0;
if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, TIME_EPOCH_USEC)) < 0)
return -errno;
return 1;
}