source: freewrt/package/openntpd/patches/01-adjtimex_linux.patch@ 475ad56

freewrt_1_0 freewrt_2_0
Last change on this file since 475ad56 was 475ad56, checked in by Waldemar Brodkorb <wbx@…>, 20 years ago

add OpenWrt trunk revision 3830.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@1 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 5.7 KB
  • openntpd-3.7p1

    diff -urN openntpd-3.7p1.orig/client.c openntpd-3.7p1/client.c
    old new  
    306306        priv_adjtime();
    307307
    308308        for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
    309                 if (p->reply[i].rcvd <= p->reply[best].rcvd)
     309                /* if (p->reply[i].rcvd <= p->reply[best].rcvd) */
    310310                        p->reply[i].good = 0;
    311311
    312312        return (0);
  • openntpd-3.7p1

    diff -urN openntpd-3.7p1.orig/configure.ac openntpd-3.7p1/configure.ac
    old new  
    466466        [ builtin_arc4random=$withval ]
    467467)
    468468
     469AC_ARG_WITH(adjtimex,
     470        [  --with-adjtimex         Use adjtimex to adjust kernel skew],
     471        [ AC_DEFINE(USE_ADJTIMEX, [], [Use adjust skew with adjtimex (experimental)]) ]
     472)
     473
    469474# Search for OpenSSL if required.
    470475if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
    471476saved_CPPFLAGS="$CPPFLAGS"
  • openntpd-3.7p1

    diff -urN openntpd-3.7p1.orig/defines.h openntpd-3.7p1/defines.h
    old new  
    2020# define setproctitle(x)
    2121#endif
    2222
     23#ifdef USE_ADJTIMEX
     24# define adjtime(a,b)   (_compat_adjtime((a),(b)))
     25#endif
     26
    2327#if !defined(SA_LEN)
    2428# if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
    2529#  define SA_LEN(x)     ((x)->sa_len)
  • openbsd-compat/Makefile.in

    diff -urN openntpd-3.7p1.orig/openbsd-compat/Makefile.in openntpd-3.7p1/openbsd-compat/Makefile.in
    old new  
    99OPENBSD=        asprintf.o daemon.o inet_pton.o strlcpy.o
    1010COMPAT=         atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
    1111                bsd-snprintf.o fake-rfc2553.o uidswap.o
    12 PORT=           port-qnx.o
     12PORT=           port-linux.o port-qnx.o
    1313
    1414VPATH=@srcdir@
    1515CC=@CC@
  • openbsd-compat/openbsd-compat.h

    diff -urN openntpd-3.7p1.orig/openbsd-compat/openbsd-compat.h openntpd-3.7p1/openbsd-compat/openbsd-compat.h
    old new  
    4444                __attribute__((__format__ (printf, 2, 3)));
    4545#endif
    4646
     47#ifdef USE_ADJTIMEX
     48# include <sys/time.h>
     49int _compat_adjtime(const struct timeval *, struct timeval *);
     50#endif
     51
    4752#ifndef HAVE_INET_PTON
    4853int inet_pton(int, const char *, void *);
    4954#endif
  • openbsd-compat/port-linux.c

    diff -urN openntpd-3.7p1.orig/openbsd-compat/port-linux.c openntpd-3.7p1/openbsd-compat/port-linux.c
    old new  
     1/* $Id$ */
     2
     3/*
     4 * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
     5 *
     6 * Permission to use, copy, modify, and distribute this software for any
     7 * purpose with or without fee is hereby granted, provided that the above
     8 * copyright notice and this permission notice appear in all copies.
     9 *
     10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     17 */
     18
     19#include "includes.h"
     20
     21#ifdef USE_ADJTIMEX
     22#include <sys/timex.h>
     23#include <errno.h>
     24#ifdef adjtime
     25# undef adjtime
     26#endif
     27
     28#include "ntpd.h"
     29
     30/* scale factor used by adjtimex freq param.  1 ppm = 65536 */
     31#define ADJTIMEX_FREQ_SCALE 65536
     32
     33/* maximum change to skew per adjustment, in PPM */
     34#define MAX_SKEW_DELTA 5.0
     35
     36int
     37_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
     38{
     39        static struct timeval tlast = {0,0};
     40        static double tskew = 0;
     41        static int synced = -1;
     42        struct timeval tnow, tdelta;
     43        double skew = 0, newskew, deltaskew, adjust, interval = 0;
     44        struct timex tmx;
     45        int result, saved_errno;
     46
     47        gettimeofday(&tnow, NULL);
     48        adjust = (double)delta->tv_sec;
     49        adjust += (double)delta->tv_usec / 1000000;
     50
     51        /* Even if the caller doesn't care about the olddelta, we do */
     52        if (olddelta == NULL)
     53                olddelta = &tdelta;
     54
     55        result = adjtime(delta, olddelta);
     56        saved_errno = errno;
     57
     58        if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
     59            synced != INT_MAX)
     60                synced++;
     61         else
     62                synced = 0;
     63
     64        /*
     65         * do skew calculations if we have synced
     66         */
     67        if (synced == 0 ) {
     68                tmx.modes = 0;
     69                if (adjtimex(&tmx) == -1)
     70                        log_warn("adjtimex get failed");
     71                else
     72                        tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
     73        } else if (synced >= 1) {
     74                interval = (double)(tnow.tv_sec - tlast.tv_sec);
     75                interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
     76
     77                skew = (adjust * 1000000) / interval;
     78                newskew = ((tskew * synced) + skew) / synced;
     79                deltaskew = newskew - tskew;
     80
     81                if (deltaskew > MAX_SKEW_DELTA) {
     82                        log_info("skew change %0.3lf exceeds limit", deltaskew);
     83                        tskew += MAX_SKEW_DELTA;
     84                } else if (deltaskew < -MAX_SKEW_DELTA) {
     85                        log_info("skew change %0.3lf exceeds limit", deltaskew);
     86                        tskew -= MAX_SKEW_DELTA;
     87                } else {
     88                        tskew = newskew;
     89                }
     90
     91                /* Adjust the kernel skew.  */
     92                tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
     93                tmx.modes = ADJ_FREQUENCY;
     94                if (adjtimex(&tmx) == -1)
     95                        log_warn("adjtimex set freq failed");
     96        }
     97
     98        log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
     99            skew, tskew);
     100
     101        tlast = tnow;
     102        errno = saved_errno;
     103        return result;
     104}
     105#endif
Note: See TracBrowser for help on using the repository browser.