Centos – Using real time kernel headers to compile userspace code vs default headers

centosheader-filelinux-kernel

Per customer requirements, I installed CentOS 5.6 with the default kernel. With this kernel installed, the time.h file includes the #define CLOCK_MONOTONIC.

Now, a real-time kernel was installed along with the kernel-devel and our code would like to use CLOCK_MONOTONIC_RAW. It does exist as a part of the kernel's header files, but when I compile our code, it does not find it in the standard userspace includes.

My question is, what is the proper procedure to including/replacing the time.h found by default with the real-time kernel? From my research, it looks like symlinks are bad, so how should it be handled? What is the procedure or process? Upgrading to CentOS 6.0 or 5.7 is not an option per customer requirements.

Best Answer

There's a key distinction to be made about where header files come from:

  • <time.h> is provided by glibc (e.g. the glibc-headers package)
  • <linux/time.h> is provided by the Linux kernel headers.

Changing the kernel and its header packages will not affect <time.h>. Only changing glibc will do that.

You should find that glibc's <time.h> includes <bits/time.h> which resolves as e.g. /usr/include/x86_64-linux-gnu/bits/time.h and defines CLOCK_MONOTONIC_RAW. If it doesn't, and you can't upgrade it, then you'll have to resort to including code like this:

#include <time.h>
#ifndef CLOCK_MONOTONIC_RAW
# define CLOCK_MONOTONIC_RAW 4
#endif
Related Question