]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: map ALARM clockids to non-ALARM clockids in now() 2600/head
authorLennart Poettering <lennart@poettering.net>
Fri, 12 Feb 2016 20:29:01 +0000 (21:29 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 12 Feb 2016 20:30:15 +0000 (21:30 +0100)
Fixes: #2597
src/basic/time-util.c
src/libsystemd/sd-event/sd-event.c

index 3973850b442af72367da2804de88fc6bbac53799..510f018d9bf4dbefae7697490a143c41ca89ddab 100644 (file)
 
 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);
 }
index deef6ba9d36b7e50c4615e77a4dad3b7af6e249c..2b46a1ff06f724a264321edf0bdf0507a2c51528 100644 (file)
@@ -2780,9 +2780,13 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
                 *usec = e->timestamp.monotonic;
                 break;
 
-        default:
+        case CLOCK_BOOTTIME:
+        case CLOCK_BOOTTIME_ALARM:
                 *usec = e->timestamp_boottime;
                 break;
+
+        default:
+                assert_not_reached("Unknown clock?");
         }
 
         return 0;