From e78a89520df6bbf080f86657a58b6fbcc884c13f Mon Sep 17 00:00:00 2001 From: seife Date: Mon, 7 Mar 2011 10:44:46 +0000 Subject: [PATCH] abstime.c: add 7 day offset to time_monotonic() functions The start point of the monotonic clock is undefined, but in practice it is often zero. There is lots of code that does not assume that a timestamp can be that low and then fails in subtle ways. Add a 7 day offset to the clock value to work around that. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1271 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/driver/abstime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/driver/abstime.c b/src/driver/abstime.c index 5b3023da1..c2af8d4f7 100644 --- a/src/driver/abstime.c +++ b/src/driver/abstime.c @@ -10,7 +10,7 @@ time_t time_monotonic_ms(void) perror("time_monotonic_ms clock_gettime"); return -1; } - ret = (t.tv_sec & 0x01FFFFF) * 1000; /* avoid overflow */ + ret = ((t.tv_sec + 604800)& 0x01FFFFF) * 1000; /* avoid overflow */ ret += t.tv_nsec / 1000000; return ret; } @@ -23,5 +23,7 @@ time_t time_monotonic(void) perror("time_monotonic clock_gettime"); return -1; } - return t.tv_sec; + /* CLOCK_MONOTONIC is often == uptime, so starts at 0. Bad for relative + time comparisons if the uptime is low, so add 7 days */ + return t.tv_sec + 604800; }