Browse Source

use per-OS files for adjfreq emulation

This makes it easier to see what is supported by each OS, and to improve
them individually.
OPENBSD_5_7
Brent Cook 10 years ago
committed by Brent Cook
parent
commit
04f3b3eeee
6 changed files with 175 additions and 58 deletions
  1. +36
    -25
      Makefile.am
  2. +1
    -32
      compat/adjfreq_freebsd.c
  3. +59
    -0
      compat/adjfreq_linux.c
  4. +19
    -0
      compat/adjfreq_osx.c
  5. +59
    -0
      compat/adjfreq_solaris.c
  6. +1
    -1
      configure.ac

+ 36
- 25
Makefile.am View File

@ -49,32 +49,33 @@ libcompat_la_CFLAGS = $(CFLAGS) $(USER_CFLAGS)
libcompat_la_SOURCES =
libcompat_la_LIBADD = $(PLATFORM_LDADD)
if !HAVE_SETPROCTITLE
libcompat_la_SOURCES += compat/setproctitle.c
if !HAVE_ADJFREQ
if HOST_FREEBSD
libcompat_la_SOURCES += compat/adjfreq_freebsd.c
endif
if !HAVE_STRLCAT
libcompat_la_SOURCES += compat/strlcat.c
if HOST_LINUX
libcompat_la_SOURCES += compat/adjfreq_linux.c
endif
if !HAVE_STRLCPY
libcompat_la_SOURCES += compat/strlcpy.c
if HOST_DARWIN
libcompat_la_SOURCES += compat/adjfreq_osx.c
endif
if HOST_SOLARIS
libcompat_la_SOURCES += compat/adjfreq_solaris.c
endif
if !HAVE_STRTONUM
libcompat_la_SOURCES += compat/strtonum.c
endif
if !HAVE_ASPRINTF
libcompat_la_SOURCES += compat/bsd-asprintf.c
endif
if !HAVE_REALLOCARRAY
libcompat_la_SOURCES += compat/reallocarray.c
if !HAVE_CLOCK_GETRES
libcompat_la_SOURCES += compat/clock_getres.c
endif
if !HAVE_MD5
libcompat_la_SOURCES += compat/md5.c
if !HAVE_CLOCK_GETTIME
if HOST_DARWIN
libcompat_la_SOURCES += compat/mach-clock_gettime.c
endif
endif
if !HAVE_IMSG
@ -82,12 +83,28 @@ libcompat_la_SOURCES += compat/imsg.c
libcompat_la_SOURCES += compat/imsg-buffer.c
endif
if !HAVE_ADJFREQ
libcompat_la_SOURCES += compat/bsd-adjfreq.c
if !HAVE_MD5
libcompat_la_SOURCES += compat/md5.c
endif
if !HAVE_CLOCK_GETRES
libcompat_la_SOURCES += compat/clock_getres.c
if !HAVE_REALLOCARRAY
libcompat_la_SOURCES += compat/reallocarray.c
endif
if !HAVE_SETPROCTITLE
libcompat_la_SOURCES += compat/setproctitle.c
endif
if !HAVE_STRLCAT
libcompat_la_SOURCES += compat/strlcat.c
endif
if !HAVE_STRLCPY
libcompat_la_SOURCES += compat/strlcpy.c
endif
if !HAVE_STRTONUM
libcompat_la_SOURCES += compat/strtonum.c
endif
if !HAVE_SETRESGID
@ -98,12 +115,6 @@ if !HAVE_SETRESUID
libcompat_la_SOURCES += compat/bsd-setresuid.c
endif
if !HAVE_CLOCK_GETTIME
if HOST_DARWIN
libcompat_la_SOURCES += compat/mach-clock_gettime.c
endif
endif
if !HAVE_ARC4RANDOM
libcompat_la_SOURCES += compat/arc4random.c


compat/bsd-adjfreq.c → compat/adjfreq_freebsd.c View File

@ -14,39 +14,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* RCSID("$Id$"); */
#include <sys/types.h>
#include <unistd.h>
#ifdef HAVE_SYS_TIMEX_H
# include <sys/timex.h>
#endif
#ifdef adjfreq
# undef adjfreq
#endif
#include <unistd.h>
#include "ntp.h"
#include "ntpd.h"
#ifndef NTP_ADJTIME
#include <errno.h>
/*
* Some sad but very popular platforms do not appear to provide a mechanism to
* adjust the time frequency at all!
*/
int
adjfreq(const int64_t *freq, int64_t *oldfreq)
{
errno = ENOSYS;
return -1;
}
#else
/*
* adjfreq (old)freq = nanosec. per seconds shifted left 32 bits
* timex.freq is ppm / left shifted by SHIFT_USEC (16 bits), defined in timex.h
@ -59,11 +34,7 @@ adjfreq(const int64_t *freq, int64_t *oldfreq)
int64_t newfreq;
if (freq != NULL) {
#if defined(__linux__)
txc.modes = ADJ_FREQUENCY;
#else
txc.modes = MOD_FREQUENCY;
#endif
txc.freq = *freq / 1e3 / (1LL << 16);
if ((ntp_adjtime(&txc)) == -1)
@ -86,5 +57,3 @@ adjfreq(const int64_t *freq, int64_t *oldfreq)
return 0;
}
#endif

+ 59
- 0
compat/adjfreq_linux.c View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2007 Sebastian Benoit <benoit-lists@fb12.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
# include <sys/timex.h>
#include <unistd.h>
#include "ntp.h"
#include "ntpd.h"
/*
* adjfreq (old)freq = nanosec. per seconds shifted left 32 bits
* timex.freq is ppm / left shifted by SHIFT_USEC (16 bits), defined in timex.h
*/
int
adjfreq(const int64_t *freq, int64_t *oldfreq)
{
struct timex txc;
int64_t newfreq;
if (freq != NULL) {
txc.modes = ADJ_FREQUENCY;
txc.freq = *freq / 1e3 / (1LL << 16);
if ((ntp_adjtime(&txc)) == -1)
log_warn("ntp_adjtime (2) failed");
log_debug("ntp_adjtime adjusted frequency by %fppm",
((txc.freq * 1e3) * (1LL<<16) / 1e3 / (1LL << 32)));
}
if (oldfreq != NULL) {
txc.modes = 0;
if ((ntp_adjtime(&txc)) == -1) {
log_warn("ntp_adjtime (1) failed");
return -1;
}
newfreq = (txc.freq * 1e3) * (1LL<<16);
log_debug("ntp_adjtime returns frequency of %fppm",
newfreq / 1e3 / (1LL << 32));
*oldfreq = newfreq;
}
return 0;
}

+ 19
- 0
compat/adjfreq_osx.c View File

@ -0,0 +1,19 @@
/*
* This file is in the public domain.
*
* OS X does not appear to provide a mechanism to adjust the time frequency, or
* at least not one that is easy to discover. Always fail here until a suitable
* implementation is found.
*/
#include <sys/time.h>
#include <sys/types.h>
#include <errno.h>
int
adjfreq(const int64_t *freq, int64_t *oldfreq)
{
errno = ENOSYS;
return -1;
}

+ 59
- 0
compat/adjfreq_solaris.c View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2007 Sebastian Benoit <benoit-lists@fb12.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
# include <sys/timex.h>
#include <unistd.h>
#include "ntp.h"
#include "ntpd.h"
/*
* adjfreq (old)freq = nanosec. per seconds shifted left 32 bits
* timex.freq is ppm / left shifted by SHIFT_USEC (16 bits), defined in timex.h
*/
int
adjfreq(const int64_t *freq, int64_t *oldfreq)
{
struct timex txc;
int64_t newfreq;
if (freq != NULL) {
txc.modes = MOD_FREQUENCY;
txc.freq = *freq / 1e3 / (1LL << 16);
if ((ntp_adjtime(&txc)) == -1)
log_warn("ntp_adjtime (2) failed");
log_debug("ntp_adjtime adjusted frequency by %fppm",
((txc.freq * 1e3) * (1LL<<16) / 1e3 / (1LL << 32)));
}
if (oldfreq != NULL) {
txc.modes = 0;
if ((ntp_adjtime(&txc)) == -1) {
log_warn("ntp_adjtime (1) failed");
return -1;
}
newfreq = (txc.freq * 1e3) * (1LL<<16);
log_debug("ntp_adjtime returns frequency of %fppm",
newfreq / 1e3 / (1LL << 32));
*oldfreq = newfreq;
}
return 0;
}

+ 1
- 1
configure.ac View File

@ -145,7 +145,7 @@ if test "x$ac_cv_have___va_copy" = "xyes" ; then
AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
fi
AC_CHECK_HEADERS([sys/timex.h md5.h sha2.h])
AC_CHECK_HEADERS([md5.h sha2.h])
AC_CHECK_HEADERS([sys/sensors.h],
AM_CONDITIONAL(HAVE_SENSORS, true),
AM_CONDITIONAL(HAVE_SENSORS, false)


Loading…
Cancel
Save