[dev] [slstatus] CLOCK_BOOTTIME not available for old Linux/glibc

From: Alessandro DE LAURENZIS <just22_AT_atlantide.t28.net>
Date: Wed, 16 Jan 2019 19:08:54 +0100

Dear slstatus devs,

CLOCK_BOOTTIME (used in components/uptime.c) is missing on some
platforms (on RHEL6, for example). I'm not an expert in this field, but
for similar situations it seems to be a common practice to revert to
CLOCK_MONOTONIC.

Please consider the following patch, which works for me (lightly tested
on GNU/Linux 2.6.32-696.16.1.el6.x86_64, ldd (GNU libc) 2.12):

[...]
--- ./components/uptime.c.orig 2019-01-14 12:51:26.638713998 +0100
+++ ./components/uptime.c 2019-01-14 12:59:45.062248721 +0100
_AT_@ -11,8 +11,13 @@
         uintmax_t h, m;
         struct timespec uptime;

+#if defined(CLOCK_BOOTTIME)
         if (clock_gettime(CLOCK_BOOTTIME, &uptime) < 0) {
                 warn("clock_gettime 'CLOCK_BOOTTIME'");
+#else
+ if (clock_gettime(CLOCK_MONOTONIC, &uptime) < 0) {
+ warn("clock_gettime 'CLOCK_MONOTONIC'");
+#endif
                 return NULL;
         }

[...]

All the best

-- 
Alessandro DE LAURENZIS
[mailto:just22_AT_atlantide.t28.net]
Web: http://www.atlantide.t28.net
LinkedIn: http://it.linkedin.com/in/delaurenzis
Received on Wed Jan 16 2019 - 19:08:54 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 16 2019 - 19:12:07 CET