teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0021-time-util-fall-back-to-CLOCK_MONOTONIC-if-CLOCK_BOOT.patch

Zbigniew Jędrzejewski-Szmek b9a1e3
From c411521802d5e89eeb5cdf39cdd7b9538a3a3a08 Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek b9a1e3
From: Lubomir Rintel <lkundrak@v3.sk>
Zbigniew Jędrzejewski-Szmek b9a1e3
Date: Tue, 15 Mar 2016 12:43:33 +0100
Zbigniew Jędrzejewski-Szmek b9a1e3
Subject: [PATCH] time-util: fall back to CLOCK_MONOTONIC if CLOCK_BOOTTIME
Zbigniew Jędrzejewski-Szmek b9a1e3
 unsupported
Zbigniew Jędrzejewski-Szmek b9a1e3
Zbigniew Jędrzejewski-Szmek b9a1e3
It was added in 2.6.39, and causes an assertion to fail when running in mock
Zbigniew Jędrzejewski-Szmek b9a1e3
hosted on 2.6.23-based RHEL-6:
Zbigniew Jędrzejewski-Szmek b9a1e3
Zbigniew Jędrzejewski-Szmek b9a1e3
Assertion 'clock_gettime(map_clock_id(clock_id), &ts) == 0' failed at systemd/src/basic/time-util.c:70, function now(). Aborting.
Zbigniew Jędrzejewski-Szmek b9a1e3
Zbigniew Jędrzejewski-Szmek b9a1e3
(cherry picked from commit 2abd5b5a49ae368b258ffc7257ab703bccda67dd)
Zbigniew Jędrzejewski-Szmek b9a1e3
---
Zbigniew Jędrzejewski-Szmek b9a1e3
 src/basic/time-util.c | 7 +++++--
Zbigniew Jędrzejewski-Szmek b9a1e3
 1 file changed, 5 insertions(+), 2 deletions(-)
Zbigniew Jędrzejewski-Szmek b9a1e3
Zbigniew Jędrzejewski-Szmek b9a1e3
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
Zbigniew Jędrzejewski-Szmek b9a1e3
index 510f018d9b..ec112e23e2 100644
Zbigniew Jędrzejewski-Szmek b9a1e3
--- a/src/basic/time-util.c
Zbigniew Jędrzejewski-Szmek b9a1e3
+++ b/src/basic/time-util.c
Zbigniew Jędrzejewski-Szmek b9a1e3
@@ -47,12 +47,15 @@ static clockid_t map_clock_id(clockid_t c) {
Zbigniew Jędrzejewski-Szmek b9a1e3
         /* Some more exotic archs (s390, ppc, …) lack the "ALARM" flavour of the clocks. Thus, clock_gettime() will
Zbigniew Jędrzejewski-Szmek b9a1e3
          * fail for them. Since they are essentially the same as their non-ALARM pendants (their only difference is
Zbigniew Jędrzejewski-Szmek b9a1e3
          * when timers are set on them), let's just map them accordingly. This way, we can get the correct time even on
Zbigniew Jędrzejewski-Szmek b9a1e3
-         * those archs. */
Zbigniew Jędrzejewski-Szmek b9a1e3
+         * those archs.
Zbigniew Jędrzejewski-Szmek b9a1e3
+         *
Zbigniew Jędrzejewski-Szmek b9a1e3
+         * Also, older kernels don't support CLOCK_BOOTTIME: fall back to CLOCK_MONOTONIC. */
Zbigniew Jędrzejewski-Szmek b9a1e3
 
Zbigniew Jędrzejewski-Szmek b9a1e3
         switch (c) {
Zbigniew Jędrzejewski-Szmek b9a1e3
 
Zbigniew Jędrzejewski-Szmek b9a1e3
+        case CLOCK_BOOTTIME:
Zbigniew Jędrzejewski-Szmek b9a1e3
         case CLOCK_BOOTTIME_ALARM:
Zbigniew Jędrzejewski-Szmek b9a1e3
-                return CLOCK_BOOTTIME;
Zbigniew Jędrzejewski-Szmek b9a1e3
+                return clock_boottime_or_monotonic ();
Zbigniew Jędrzejewski-Szmek b9a1e3
 
Zbigniew Jędrzejewski-Szmek b9a1e3
         case CLOCK_REALTIME_ALARM:
Zbigniew Jędrzejewski-Szmek b9a1e3
                 return CLOCK_REALTIME;