GNOME Bugzilla – Bug 353694
glib-2.12.3 fails to compile if CLOCK_MONOTONIC is undefined
Last modified: 2006-12-04 14:28:19 UTC
Please describe the problem: glib-2.12.3 fails to compile if glibc does not define CLOCK_MONOTONIC (in my case, glibc 2.3.2). It fails in glib/gtimer.c at line 96. Steps to reproduce: 1. Attempt to compile glib-2.12.3 with a version of glibc which does not define CLOCK_MONOTONIC 2. 3. Actual results: Compilation fails in glib/gtimer.c Expected results: Compilation to complete successfully Does this happen every time? Yes Other information: Line 94 of glib/gtimer.c is extremely suspicious and is as follows: #if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK >= 0 If it is changed to this: #if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 then compilation proceeds correctly and glib appears to work.
Created attachment 71966 [details] [review] Patch as described in bug report
I'm following the sysconf man page here: For options, typically, there is a constant _POSIX_FOO that may be defined in <unistd.h>. If it is undefined, one should ask at run-time. If it is defined to -1, then the option is not supported. If it is defined to 0, then relevant functions and headers exist, but one has to ask at runtime what degree of support is available. If it is defined to a value other than -1 or 0, then the option is supported. We probably need to wrap this additionally in #ifdef CLOCK_MONOTONIC #endif
If _POSIX_MONOTIC_CLOCK is undefined, I doubt that CLOCK_MONOTONIC will ever be defined: it would be a bizarre set of headers which did this, even if the SUS were to allow it (looking at the SUS I am not clear whether this is allowed or not). As not much depends on it anyway in this case, I would be inclined to ignore it. In any event, if you are going to do something more on this you may want to remove the call to sysconf() where _POSIX_MONOTIC_CLOCK is defined to a value greater than 0, as it is redundant in that case.
Created attachment 72158 [details] [review] Further patch which tests for CLOCK_MONOTONIC This tests for CLOCK_MONOTONIC if you would like to go down that route. It does not deal with the redundant call to sysconf where _POSIX_MONOTONIC_CLOCK is greater than 0, but you may not be too fussed about that.
*** Bug 356020 has been marked as a duplicate of this bug. ***
*** Bug 354938 has been marked as a duplicate of this bug. ***
I think the current code handles CLOCK_MONOTONIC not being defined.
Created attachment 73855 [details] [review] build fix Not quite. This patch is needed for 2.12.4 to build correctly.
*** Bug 359683 has been marked as a duplicate of this bug. ***
Fixed in cvs.
*** Bug 376487 has been marked as a duplicate of this bug. ***
*** Bug 367894 has been marked as a duplicate of this bug. ***