summaryrefslogtreecommitdiff
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-08-25 16:46:27 +0200
committerTom Gundersen <teg@jklm.no>2015-08-25 16:46:27 +0200
commit498fb56739a5d18cb85d2ba3523759b1d141d770 (patch)
treed68a7330da711f320063046007cddfbf469fea6f /src/basic/time-util.c
parent3ad216b44f4f5cba168f449ae455607a442cfd4c (diff)
parentef3100e9637adda26fa19e7ee8606788320dcde3 (diff)
Merge pull request #1022 from poettering/machinectl-shell
Add new "machinectl shell" command for su(1)-like behaviour
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 12f1b193be..e278196c90 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -88,6 +88,32 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
return ts;
}
+dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u) {
+ int64_t delta;
+
+ if (u == USEC_INFINITY) {
+ ts->realtime = ts->monotonic = USEC_INFINITY;
+ return ts;
+ }
+ ts->realtime = now(CLOCK_REALTIME);
+ ts->monotonic = now(CLOCK_MONOTONIC);
+
+ delta = (int64_t) now(clock_boottime_or_monotonic()) - (int64_t) u;
+
+ if ((int64_t) ts->realtime > delta)
+ ts->realtime -= delta;
+ else
+ ts->realtime = 0;
+
+ if ((int64_t) ts->monotonic > delta)
+ ts->monotonic -= delta;
+ else
+ ts->monotonic = 0;
+
+ return ts;
+}
+
+
usec_t timespec_load(const struct timespec *ts) {
assert(ts);