$DragonFly: src/usr.sbin/ntpd/patches/Attic/ntpd.c.patch,v 1.7 2005/04/22 08:35:04 joerg Exp $ --- ntpd.c.orig 2004-11-09 20:39:54.000000000 +0100 +++ ntpd.c 2004-11-09 20:40:48.000000000 +0100 @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -33,11 +34,12 @@ #include "ntpd.h" void sighdlr(int); -__dead void usage(void); +void usage(void) __dead2; int main(int, char *[]); int check_child(pid_t, const char *); int dispatch_imsg(struct ntpd_conf *); void ntpd_adjtime(double); +void ntpd_adjfreq(double); void ntpd_settime(double); volatile sig_atomic_t quit = 0; @@ -62,12 +64,10 @@ } } -__dead void +void usage(void) { - extern char *__progname; - - fprintf(stderr, "usage: %s [-dSs] [-f file]\n", __progname); + fprintf(stderr, "usage: %s [-dSs] [-f file]\n", getprogname()); exit(1); } @@ -266,6 +266,12 @@ memcpy(&d, imsg.data, sizeof(d)); ntpd_adjtime(d); break; + case IMSG_ADJFREQ: + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d)) + fatalx("invalid IMSG_ADJFREQ received"); + memcpy(&d, imsg.data, sizeof(d)); + ntpd_adjfreq(d); + break; case IMSG_SETTIME: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d)) fatalx("invalid IMSG_SETTIME received"); @@ -311,16 +317,37 @@ void ntpd_adjtime(double d) { - struct timeval tv; + int64_t adjust; if (d >= (double)LOG_NEGLIGEE / 1000 || d <= -1 * (double)LOG_NEGLIGEE / 1000) log_info("adjusting local clock by %fs", d); else log_debug("adjusting local clock by %fs", d); - d_to_tv(d, &tv); - if (adjtime(&tv, NULL) == -1) - log_warn("adjtime failed"); + adjust = d * 1e9; + + if (sysctlbyname("kern.ntp.adjust", NULL, NULL, &adjust, + sizeof(adjust))) + log_info("adjtime failed"); +} + +void +ntpd_adjfreq(double relfreq) +{ + int64_t curfreq; + size_t len = sizeof(curfreq); + + if (sysctlbyname("kern.ntp.permanent", &curfreq, &len, NULL, 0) || + len != sizeof(curfreq)) { + log_warn("adjfreq failed"); + return; + } + + curfreq += relfreq * 1e9 * (1ll << 32); + + if (sysctlbyname("kern.ntp.permanent", NULL, NULL, &curfreq, + sizeof(curfreq))) + log_warn("adjfreq failed"); } void