diff --git a/configure b/configure index 5e9b7f4..9857295 100755 --- a/configure +++ b/configure @@ -569,6 +569,21 @@ then fi fi +if test_code 'clock_gettime()' 'time.h' '' '' \ + 'clock_gettime(CLOCK_REALTIME, NULL);' +then + add_def HAVE_CLOCK_GETTIME +else + if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \ + 'clock_gettime(CLOCK_REALTIME, NULL);' + then + add_def HAVE_CLOCK_GETTIME + EXTRA_LIBS="$EXTRA_LIBS -lrt" + else + try_phc=0 + fi +fi + if test_code 'getaddrinfo()' 'sys/types.h sys/socket.h netdb.h' '' "$EXTRA_LIBS" \ 'return getaddrinfo(0, 0, 0, 0);' then @@ -676,16 +691,7 @@ if [ $feat_refclock = "1" ] && [ $feat_phc = "1" ] && [ $try_phc = "1" ] && \ test_code '' 'sys/ioctl.h linux/ptp_clock.h' '' '' \ 'ioctl(1, PTP_CLOCK_GETCAPS, 0);' then - if test_code 'clock_gettime()' 'time.h' '' '' 'clock_gettime(0, NULL);'; then - add_def FEAT_PHC - else - if test_code 'clock_gettime() in -lrt' 'time.h' '' '-lrt' \ - 'clock_gettime(0, NULL);' - then - EXTRA_LIBS="$EXTRA_LIBS -lrt" - add_def FEAT_PHC - fi - fi + add_def FEAT_PHC fi if [ $try_setsched = "1" ] && \ diff --git a/local.c b/local.c index 6786c0f..c456f83 100644 --- a/local.c +++ b/local.c @@ -350,19 +350,21 @@ void LCL_RemoveDispersionNotifyHandler(LCL_DispersionNotifyHandler handler, void } /* ================================================== */ -/* At the moment, this is just gettimeofday(), because - I can't think of a Unix system where it would not be */ void LCL_ReadRawTime(struct timespec *ts) { +#if HAVE_CLOCK_GETTIME + if (clock_gettime(CLOCK_REALTIME, ts) < 0) + LOG_FATAL(LOGF_Local, "clock_gettime() failed : %s", strerror(errno)); +#else struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - LOG_FATAL(LOGF_Local, "gettimeofday() failed"); - } + if (gettimeofday(&tv, NULL) < 0) + LOG_FATAL(LOGF_Local, "gettimeofday() failed : %s", stderror(errno)); UTI_TimevalToTimespec(&tv, ts); +#endif } /* ================================================== */ diff --git a/local.h b/local.h index 2c2360f..618a0bd 100644 --- a/local.h +++ b/local.h @@ -31,8 +31,7 @@ #include "sysincl.h" -/* Read the system clock. This is analogous to gettimeofday(), - but with the timezone information ignored */ +/* Read the system clock */ extern void LCL_ReadRawTime(struct timespec *ts); /* Read the system clock, corrected according to all accumulated diff --git a/sys_linux.c b/sys_linux.c index b6df86c..dd8529b 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -452,8 +452,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), - SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), + SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), SCMP_SYS(rt_sigprocmask),