summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basic/clock-util.c14
-rw-r--r--src/basic/clock-util.h1
-rw-r--r--src/core/main.c8
3 files changed, 22 insertions, 1 deletions
diff --git a/src/basic/clock-util.c b/src/basic/clock-util.c
index 05788a360e..c64b2e5e8c 100644
--- a/src/basic/clock-util.c
+++ b/src/basic/clock-util.c
@@ -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;
+}
diff --git a/src/basic/clock-util.h b/src/basic/clock-util.h
index fef2d471a6..09d46758f4 100644
--- a/src/basic/clock-util.h
+++ b/src/basic/clock-util.h
@@ -28,3 +28,4 @@ int clock_set_timezone(int *min);
int clock_reset_timewarp(void);
int clock_get_hwclock(struct tm *tm);
int clock_set_hwclock(const struct tm *tm);
+int clock_apply_epoch(void);
diff --git a/src/core/main.c b/src/core/main.c
index 99ef723fcb..fb27e897e4 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1424,8 +1424,14 @@ int main(int argc, char *argv[]) {
* saving time change. All kernel local time concepts will be treated
* as UTC that way.
*/
- clock_reset_timewarp();
+ (void) clock_reset_timewarp();
}
+
+ r = clock_apply_epoch();
+ if (r < 0)
+ log_error_errno(r, "Current system time is before build time, but cannot correct: %m");
+ else if (r > 0)
+ log_info("System time before build time, advancing clock.");
}
/* Set the default for later on, but don't actually