summaryrefslogtreecommitdiff
path: root/src/basic/time-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-12 21:29:01 +0100
committerLennart Poettering <lennart@poettering.net>2016-02-12 21:30:15 +0100
commit32c1f5a57998f2a9e1992af006b83e39e3155830 (patch)
treeeea5c491a248765d1eb1ab5de6d4baf46374295d /src/basic/time-util.c
parent736ffecc9cf58a0d2c5f147a1f56f2c3532c10ce (diff)
time-util: map ALARM clockids to non-ALARM clockids in now()
Fixes: #2597
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r--src/basic/time-util.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 3973850b44..510f018d9b 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -42,10 +42,30 @@
static nsec_t timespec_load_nsec(const struct timespec *ts);
+static clockid_t map_clock_id(clockid_t c) {
+
+ /* Some more exotic archs (s390, ppc, …) lack the "ALARM" flavour of the clocks. Thus, clock_gettime() will
+ * fail for them. Since they are essentially the same as their non-ALARM pendants (their only difference is
+ * when timers are set on them), let's just map them accordingly. This way, we can get the correct time even on
+ * those archs. */
+
+ switch (c) {
+
+ case CLOCK_BOOTTIME_ALARM:
+ return CLOCK_BOOTTIME;
+
+ case CLOCK_REALTIME_ALARM:
+ return CLOCK_REALTIME;
+
+ default:
+ return c;
+ }
+}
+
usec_t now(clockid_t clock_id) {
struct timespec ts;
- assert_se(clock_gettime(clock_id, &ts) == 0);
+ assert_se(clock_gettime(map_clock_id(clock_id), &ts) == 0);
return timespec_load(&ts);
}
@@ -53,7 +73,7 @@ usec_t now(clockid_t clock_id) {
nsec_t now_nsec(clockid_t clock_id) {
struct timespec ts;
- assert_se(clock_gettime(clock_id, &ts) == 0);
+ assert_se(clock_gettime(map_clock_id(clock_id), &ts) == 0);
return timespec_load_nsec(&ts);
}