sysconf(_SC_MONOTONIC_CLOCK) problem

Peter Kjellerstedt peter.kjellerstedt at axis.com
Thu Jun 12 22:34:00 UTC 2008


> -----Original Message-----
> From: uclibc-bounces at uclibc.org [mailto:uclibc-bounces at uclibc.org] On
> Behalf Of Will Wagner
> Sent: den 12 juni 2008 20:36
> To: uclibc at uclibc.org
> Subject: sysconf(_SC_MONOTONIC_CLOCK) problem
>
> Hello,
>
> I am using uclicb 0.9.29 on Arm built with buildroot
>
> I want to use monotonic clock support and to test that that
> functionality exists I try the following bit of code:
>
>      long x = sysconf(_SC_MONOTONIC_CLOCK);
>      bool hasMonotonic = x >= 200112L;
>
> However when I run this sysconf return -1.
>
> Looking at the code it appears this happens if __NR_clock_getres is not
> defined. However looking at the kernel headers I think it is defined
> as:
>
> #define __NR_clock_getres               (__NR_SYSCALL_BASE+264)
>
> in unistd.h
>
> If I run this code:
>
>      if (syscall(__NR_clock_getres, CLOCK_MONOTONIC, NULL) < 0)
>      {
>          printf("syscall failed %d", errno);
>          return 0;
>      }
>
>      if (clock_getres(CLOCK_MONOTONIC, NULL) < 0)
>      {
>          printf("clock_getres failed %d", errno);
>          return 0;
>      }
>
> Then both calls succeed so the kernel supports this.
>
>  From this I assume that uclibc is compiled as if __NR_clock_getres is
> not defined. Does that sound right?
>
> I have looked for configuration options and can not find any for this.
> How can I enable this?
>
>
> Thanks,
>
> Will.

The problem is that someone added the check for __NR_clock_getres
after I added the support for _SC_MONOTONIC_CLOCK. Unfortunately
they forgot to add an inclusion of sys/sycall.h which means
__NR_clock_getres will never be defined...

I just committed the following patch to the uClibc repository
which should correct the situation:

Index: libc/unistd/sysconf.c
===================================================================
--- libc/unistd/sysconf.c       (revision 18424)
+++ libc/unistd/sysconf.c       (working copy)
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/syscall.h>
 #include <sys/sysinfo.h>
 #include <sys/types.h>
 #ifdef __UCLIBC_HAS_REGEX__

//Peter




More information about the uClibc mailing list