summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2016-02-04 18:05:32 +0100
committerTom Gundersen <teg@jklm.no>2016-02-04 18:05:32 +0100
commit6448e16d2102ecf38e25a2721f9f877638f4cb93 (patch)
treee6778b9654fd569cf2ab773412e3b270a3c6c01a /src/basic
parent145c990fc90277f3a89475db33bcca2af091458f (diff)
parent06d127543513a9d4881c4e915053901b77ec4fe0 (diff)
Merge pull request #2524 from poettering/bag-of-stuff
Bag of stuff
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/clock-util.c14
-rw-r--r--src/basic/clock-util.h1
-rw-r--r--src/basic/time-util.h2
3 files changed, 16 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/basic/time-util.h b/src/basic/time-util.h
index b37d5ad5dc..9c7758a959 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -69,7 +69,7 @@ typedef struct dual_timestamp {
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
#define FORMAT_TIMESPAN_MAX 64
-#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
+#define TIME_T_MAX (time_t)((UINTMAX_C(1) << ((sizeof(time_t) << 3) - 1)) - 1)
#define DUAL_TIMESTAMP_NULL ((struct dual_timestamp) { 0ULL, 0ULL })