]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/openntpd/files/adjtimex-3.7p1.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / openntpd / files / adjtimex-3.7p1.patch
1 diff -u -p -r1.46 client.c
2 --- openntpd-3.7p1/client.c     13 Mar 2005 12:36:43 -0000      1.46
3 +++ openntpd-3.7p1/client.c     26 Jun 2005 03:15:54 -0000
4 @@ -306,7 +306,7 @@ client_update(struct ntp_peer *p)
5         priv_adjtime();
6  
7         for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
8 -               if (p->reply[i].rcvd <= p->reply[best].rcvd)
9 +               /* if (p->reply[i].rcvd <= p->reply[best].rcvd) */
10                         p->reply[i].good = 0;
11  
12         return (0);
13 --- openntpd-3.7p1/configure.ac 23 May 2005 11:10:34 -0000      1.62
14 +++ openntpd-3.7p1/configure.ac 26 Jun 2005 03:15:54 -0000
15 @@ -466,6 +466,11 @@ AC_ARG_WITH(builtin-arc4random,
16         [ builtin_arc4random=$withval ]
17  )
18  
19 +AC_ARG_WITH(adjtimex,
20 +       [  --with-adjtimex         Use adjtimex to adjust kernel skew],
21 +       [ AC_DEFINE(USE_ADJTIMEX, [], [Use adjust skew with adjtimex (experimental)]) ]
22 +)
23 +
24  # Search for OpenSSL if required.
25  if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
26  saved_CPPFLAGS="$CPPFLAGS"
27 --- openntpd-3.7p1/defines.h    23 May 2005 00:16:15 -0000      1.23
28 +++ openntpd-3.7p1/defines.h    26 Jun 2005 03:15:54 -0000
29 @@ -20,6 +20,10 @@
30  # define setproctitle(x)
31  #endif
32  
33 +#ifdef USE_ADJTIMEX
34 +# define adjtime(a,b)  (_compat_adjtime((a),(b)))
35 +#endif
36 +
37  #if !defined(SA_LEN)
38  # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
39  #  define SA_LEN(x)    ((x)->sa_len)
40 --- openntpd-3.7p1/openbsd-compat/Makefile.in   19 Dec 2004 23:41:28 -0000      1.10
41 +++ openntpd-3.7p1/openbsd-compat/Makefile.in   26 Jun 2005 03:17:15 -0000
42 @@ -9,7 +9,7 @@ all:    libopenbsd-compat.a
43  OPENBSD=       asprintf.o daemon.o inet_pton.o strlcpy.o
44  COMPAT=                atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
45                 bsd-snprintf.o fake-rfc2553.o uidswap.o
46 -PORT=          port-qnx.o
47 +PORT=          port-linux.o port-qnx.o
48  
49  VPATH=@srcdir@
50  CC=@CC@
51 --- openntpd-3.7p1/openbsd-compat/openbsd-compat.h      19 Dec 2004 03:04:22 -0000      1.15
52 +++ openntpd-3.7p1/openbsd-compat/openbsd-compat.h      26 Jun 2005 03:15:54 -0000
53 @@ -44,6 +44,11 @@ int      asprintf(char **, const char *,
54                  __attribute__((__format__ (printf, 2, 3)));
55  #endif
56  
57 +#ifdef USE_ADJTIMEX
58 +# include <sys/time.h>
59 +int _compat_adjtime(const struct timeval *, struct timeval *);
60 +#endif
61 +
62  #ifndef HAVE_INET_PTON
63  int inet_pton(int, const char *, void *);
64  #endif
65 --- /dev/null   1 Jan 1970 00:00:00 -0000
66 +++ openntpd-3.7p1/openbsd-compat/port-linux.c  10 Dec 2004 01:10:30 -0000
67 @@ -0,0 +1,105 @@
68 +/* $Id$ */
69 +
70 +/*
71 + * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
72 + *
73 + * Permission to use, copy, modify, and distribute this software for any
74 + * purpose with or without fee is hereby granted, provided that the above
75 + * copyright notice and this permission notice appear in all copies.
76 + *
77 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
78 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
79 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
80 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
81 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
82 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
83 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
84 + */
85 +
86 +#include "includes.h"
87 +
88 +#ifdef USE_ADJTIMEX
89 +#include <sys/timex.h>
90 +#include <errno.h>
91 +#ifdef adjtime
92 +# undef adjtime
93 +#endif
94 +
95 +#include "ntpd.h"
96 +
97 +/* scale factor used by adjtimex freq param.  1 ppm = 65536 */
98 +#define ADJTIMEX_FREQ_SCALE 65536
99 +
100 +/* maximum change to skew per adjustment, in PPM */
101 +#define MAX_SKEW_DELTA 5.0
102 +
103 +int
104 +_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
105 +{
106 +       static struct timeval tlast = {0,0};
107 +       static double tskew = 0;
108 +       static int synced = -1;
109 +       struct timeval tnow, tdelta;
110 +       double skew = 0, newskew, deltaskew, adjust, interval = 0;
111 +       struct timex tmx;
112 +       int result, saved_errno;
113 +
114 +       gettimeofday(&tnow, NULL);
115 +       adjust = (double)delta->tv_sec;
116 +       adjust += (double)delta->tv_usec / 1000000;
117 +
118 +       /* Even if the caller doesn't care about the olddelta, we do */
119 +       if (olddelta == NULL)
120 +               olddelta = &tdelta;
121 +
122 +       result = adjtime(delta, olddelta);
123 +       saved_errno = errno;
124 +
125 +       if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
126 +           synced != INT_MAX)
127 +               synced++;
128 +        else
129 +               synced = 0;
130 +
131 +       /*
132 +        * do skew calculations if we have synced
133 +        */
134 +       if (synced == 0 ) {
135 +               tmx.modes = 0;
136 +               if (adjtimex(&tmx) == -1)
137 +                       log_warn("adjtimex get failed");
138 +               else
139 +                       tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
140 +       } else if (synced >= 1) {
141 +               interval = (double)(tnow.tv_sec - tlast.tv_sec);
142 +               interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
143 +
144 +               skew = (adjust * 1000000) / interval;
145 +               newskew = ((tskew * synced) + skew) / synced;
146 +               deltaskew = newskew - tskew;
147 +
148 +               if (deltaskew > MAX_SKEW_DELTA) {
149 +                       log_info("skew change %0.3lf exceeds limit", deltaskew);
150 +                       tskew += MAX_SKEW_DELTA;
151 +               } else if (deltaskew < -MAX_SKEW_DELTA) {
152 +                       log_info("skew change %0.3lf exceeds limit", deltaskew);
153 +                       tskew -= MAX_SKEW_DELTA;
154 +               } else {
155 +                       tskew = newskew;
156 +               }
157 +
158 +               /* Adjust the kernel skew.  */
159 +               tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
160 +               tmx.modes = ADJ_FREQUENCY;
161 +               if (adjtimex(&tmx) == -1)
162 +                       log_warn("adjtimex set freq failed");
163 +       }
164 +
165 +       log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
166 +           skew, tskew);
167 +
168 +       tlast = tnow;
169 +       errno = saved_errno;
170 +       return result;
171 +}
172 +#endif