9fc0f6
From eaae0683686ccd07d1cf79f2247032586162f854 Mon Sep 17 00:00:00 2001
9fc0f6
From: Lennart Poettering <lennart@poettering.net>
9fc0f6
Date: Mon, 11 Nov 2013 03:03:17 +0100
9fc0f6
Subject: [PATCH] timer: consider (usec_t) -1 an invalid timestamp
9fc0f6
9fc0f6
---
9fc0f6
 src/shared/time-util.c | 4 ++--
9fc0f6
 src/shared/time-util.h | 5 ++++-
9fc0f6
 2 files changed, 6 insertions(+), 3 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
9fc0f6
index b8a6bd7..81d4ede 100644
9fc0f6
--- a/src/shared/time-util.c
9fc0f6
+++ b/src/shared/time-util.c
9fc0f6
@@ -157,7 +157,7 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
9fc0f6
         assert(buf);
9fc0f6
         assert(l > 0);
9fc0f6
 
9fc0f6
-        if (t <= 0)
9fc0f6
+        if (t <= 0 || t == (usec_t) -1)
9fc0f6
                 return NULL;
9fc0f6
 
9fc0f6
         sec = (time_t) (t / USEC_PER_SEC);
9fc0f6
@@ -175,7 +175,7 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
9fc0f6
         assert(buf);
9fc0f6
         assert(l > 0);
9fc0f6
 
9fc0f6
-        if (t <= 0)
9fc0f6
+        if (t <= 0 || t == (usec_t) -1)
9fc0f6
                 return NULL;
9fc0f6
 
9fc0f6
         sec = (time_t) (t / USEC_PER_SEC);
9fc0f6
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
9fc0f6
index 7660fe1..bc10d22 100644
9fc0f6
--- a/src/shared/time-util.h
9fc0f6
+++ b/src/shared/time-util.h
9fc0f6
@@ -64,7 +64,10 @@ dual_timestamp* dual_timestamp_get(dual_timestamp *ts);
9fc0f6
 dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u);
9fc0f6
 dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u);
9fc0f6
 
9fc0f6
-#define dual_timestamp_is_set(ts) ((ts)->realtime > 0)
9fc0f6
+static inline bool dual_timestamp_is_set(dual_timestamp *ts) {
9fc0f6
+        return ((ts->realtime > 0 && ts->realtime != (usec_t) -1) ||
9fc0f6
+                (ts->monotonic > 0 && ts->monotonic != (usec_t) -1));
9fc0f6
+}
9fc0f6
 
9fc0f6
 usec_t timespec_load(const struct timespec *ts) _pure_;
9fc0f6
 struct timespec *timespec_store(struct timespec *ts, usec_t u);