]> git.pld-linux.org Git - packages/ntp.git/blob - ntp-4.2.4p7-sleep.patch
- release 4
[packages/ntp.git] / ntp-4.2.4p7-sleep.patch
1 diff -up ntp-4.2.4p7/include/ntp_refclock.h.sleep ntp-4.2.4p7/include/ntp_refclock.h
2 --- ntp-4.2.4p7/include/ntp_refclock.h.sleep    2006-06-06 22:16:19.000000000 +0200
3 +++ ntp-4.2.4p7/include/ntp_refclock.h  2009-07-21 16:38:47.000000000 +0200
4 @@ -260,6 +260,7 @@ extern      void    refclock_control P((struct s
5                                     struct refclockstat *));
6  extern int     refclock_open   P((char *, u_int, u_int));
7  extern int     refclock_setup  P((int, u_int, u_int));
8 +extern int     refclock_timer_needed   P((struct peer *));
9  extern void    refclock_timer  P((struct peer *));
10  extern void    refclock_transmit P((struct peer *));
11  extern int     refclock_ioctl  P((int, u_int));
12 diff -up ntp-4.2.4p7/include/ntp_stdlib.h.sleep ntp-4.2.4p7/include/ntp_stdlib.h
13 --- ntp-4.2.4p7/include/ntp_stdlib.h.sleep      2006-12-28 13:03:05.000000000 +0100
14 +++ ntp-4.2.4p7/include/ntp_stdlib.h    2009-07-21 16:38:47.000000000 +0200
15 @@ -101,6 +101,7 @@ extern      const char *    FindConfig      P((const 
16  extern void    signal_no_reset P((int, RETSIGTYPE (*func)(int)));
17  
18  extern void    getauthkeys     P((const char *));
19 +extern int     auth_agekeys_is_needed P((void));
20  extern void    auth_agekeys    P((void));
21  extern void    rereadkeys      P((void));
22  
23 diff -up ntp-4.2.4p7/include/ntpd.h.sleep ntp-4.2.4p7/include/ntpd.h
24 --- ntp-4.2.4p7/include/ntpd.h.sleep    2009-07-21 16:38:47.000000000 +0200
25 +++ ntp-4.2.4p7/include/ntpd.h  2009-07-21 16:38:47.000000000 +0200
26 @@ -120,8 +120,10 @@ extern     int     leap_actual P((int));
27  /* ntp_loopfilter.c */
28  extern void    init_loopfilter P((void));
29  extern int     local_clock P((struct peer *, double));
30 -extern void    adj_host_clock  P((void));
31 +extern int     adj_host_clock_is_needed P((void));
32 +extern void    adj_host_clock  P((int));
33  extern void    loop_config P((int, double));
34 +extern int     huffpuff_enabled P((void));
35  extern void    huffpuff        P((void));
36  extern u_long  sys_clocktime;
37  extern u_long  sys_tai;
38 @@ -221,6 +223,7 @@ extern      void    hack_restrict   P((int, struct
39  /* ntp_timer.c */
40  extern void    init_timer      P((void));
41  extern void    reinit_timer    P((void));
42 +extern int     when_next_event P((void));
43  extern void    timer           P((void));
44  extern void    timer_clr_stats P((void));
45  extern  void    timer_interfacetimeout P((u_long));
46 diff -up ntp-4.2.4p7/libntp/authkeys.c.sleep ntp-4.2.4p7/libntp/authkeys.c
47 --- ntp-4.2.4p7/libntp/authkeys.c.sleep 2004-02-25 06:58:03.000000000 +0100
48 +++ ntp-4.2.4p7/libntp/authkeys.c       2009-07-21 16:38:47.000000000 +0200
49 @@ -394,6 +394,24 @@ auth_delkeys(void)
50         }
51  }
52  
53 +int auth_agekeys_is_needed() {
54 +       struct savekey *sk;
55 +       int i;
56 +
57 +       if (authnumkeys > 20)
58 +               return 1;
59 +
60 +       for (i = 0; i < HASHSIZE; i++) {
61 +               sk = key_hash[i];
62 +               while (sk != 0) {
63 +                       if (sk->lifetime > 0)
64 +                               return 1;
65 +                       sk = sk->next;
66 +               }
67 +       }
68 +       return 0;
69 +}
70 +
71  /*
72   * auth_agekeys - delete keys whose lifetimes have expired
73   */
74 diff -up ntp-4.2.4p7/ntpd/ntp_loopfilter.c.sleep ntp-4.2.4p7/ntpd/ntp_loopfilter.c
75 --- ntp-4.2.4p7/ntpd/ntp_loopfilter.c.sleep     2009-07-21 16:38:47.000000000 +0200
76 +++ ntp-4.2.4p7/ntpd/ntp_loopfilter.c   2009-07-21 16:38:47.000000000 +0200
77 @@ -752,6 +752,10 @@ local_clock(
78  #endif /* LOCKCLOCK */
79  }
80  
81 +int adj_host_clock_is_needed() {
82 +       return !(!ntp_enable || mode_ntpdate || (pll_control &&
83 +           kern_enable));
84 +}
85  
86  /*
87   * adj_host_clock - Called once every second to update the local clock.
88 @@ -761,7 +765,7 @@ local_clock(
89   */
90  void
91  adj_host_clock(
92 -       void
93 +       int time_elapsed
94         )
95  {
96         double  adjustment;
97 @@ -776,7 +780,8 @@ adj_host_clock(
98          * maximum error and the local clock driver will pick it up and
99          * pass to the common refclock routines. Very elegant.
100          */
101 -       sys_rootdispersion += clock_phi;
102 +       sys_rootdispersion += clock_phi * time_elapsed;
103 +       DPRINTF(2, ("loopfilter: %d\n", time_elapsed));
104  
105  #ifndef LOCKCLOCK
106         /*
107 @@ -833,6 +838,11 @@ rstclock(
108  }
109  
110  
111 +int huffpuff_enabled()
112 +{
113 +       return sys_huffpuff != NULL;
114 +}
115 +
116  /*
117   * huff-n'-puff filter
118   */
119 diff -up ntp-4.2.4p7/ntpd/ntp_refclock.c.sleep ntp-4.2.4p7/ntpd/ntp_refclock.c
120 --- ntp-4.2.4p7/ntpd/ntp_refclock.c.sleep       2006-06-06 22:16:43.000000000 +0200
121 +++ ntp-4.2.4p7/ntpd/ntp_refclock.c     2009-07-21 16:38:47.000000000 +0200
122 @@ -309,6 +309,21 @@ refclock_unpeer(
123  }
124  
125  
126 +int
127 +refclock_timer_needed(
128 +       struct peer *peer       /* peer structure pointer */
129 +       )
130 +{
131 +       u_char clktype;
132 +       int unit;
133 +
134 +       clktype = peer->refclktype;
135 +       unit = peer->refclkunit;
136 +       if (refclock_conf[clktype]->clock_timer != noentry)
137 +               return 1;
138 +       return 0;
139 +}
140 +
141  /*
142   * refclock_timer - called once per second for housekeeping.
143   */
144 diff -up ntp-4.2.4p7/ntpd/ntp_timer.c.sleep ntp-4.2.4p7/ntpd/ntp_timer.c
145 --- ntp-4.2.4p7/ntpd/ntp_timer.c.sleep  2009-05-12 07:58:55.000000000 +0200
146 +++ ntp-4.2.4p7/ntpd/ntp_timer.c        2009-07-21 16:38:47.000000000 +0200
147 @@ -63,6 +63,7 @@ volatile u_long alarm_overflow;
148  #define HOUR   (60*60)
149  
150  u_long current_time;
151 +l_fp timer_base;
152  
153  /*
154   * Stats.  Number of overflows and number of calls to transmit().
155 @@ -99,6 +100,8 @@ static       RETSIGTYPE alarming P((int));
156  void 
157  reinit_timer(void)
158  {
159 +       get_systime(&timer_base);
160 +#if 0
161  #if !defined(SYS_WINNT) && !defined(VMS)
162  #  if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
163         timer_gettime(ntpd_timerid, &itimer);
164 @@ -132,6 +135,7 @@ reinit_timer(void)
165         setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
166  #  endif
167  # endif /* VMS */
168 +#endif
169  }
170  
171  /*
172 @@ -159,6 +163,8 @@ init_timer(void)
173         timer_xmtcalls = 0;
174         timer_timereset = 0;
175  
176 +       get_systime(&timer_base);
177 +#if 0
178  #if !defined(SYS_WINNT)
179         /*
180          * Set up the alarm interrupt.  The first comes 2**EVENT_TIMEOUT
181 @@ -242,6 +248,7 @@ init_timer(void)
182         }
183  
184  #endif /* SYS_WINNT */
185 +#endif
186  }
187  
188  #if defined(SYS_WINNT)
189 @@ -252,6 +259,46 @@ get_timer_handle(void)
190  }
191  #endif
192  
193 +int when_next_event() {
194 +       register struct peer *peer, *next_peer;
195 +       u_int n;
196 +       int next = current_time + HOUR;
197 +
198 +       if (adj_host_clock_is_needed())
199 +               return 1;
200 +       for (n = 0; n < NTP_HASH_SIZE; n++) {
201 +               for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
202 +                       next_peer = peer->next;
203 +#ifdef REFCLOCK
204 +                       if (peer->flags & FLAG_REFCLOCK && refclock_timer_needed(peer))
205 +                               return 1;
206 +#endif /* REFCLOCK */
207 +                       if (peer->action && peer->nextaction < next)
208 +                               next = peer->nextaction;
209 +                       if (peer->nextdate < next)
210 +                               next = peer->nextdate;
211 +               }
212 +       }
213 +
214 +       if (auth_agekeys_is_needed() && keys_timer < next)
215 +               next = keys_timer;
216 +       if (huffpuff_enabled() && huffpuff_timer < next)
217 +               next = huffpuff_timer;
218 +#ifdef OPENSSL
219 +       if (revoke_timer < next)
220 +               next = revoke_timer;
221 +#endif /* OPENSSL */
222 +       if (interface_interval && interface_timer < next)
223 +               next = interface_timer;
224 +       if (stats_timer < next)
225 +               next = stats_timer;
226 +
227 +       next -= current_time;
228 +       if (next <= 0)
229 +               next = 1;
230 +       return next;
231 +}
232 +
233  /*
234   * timer - dispatch anyone who needs to be
235   */
236 @@ -264,14 +311,12 @@ timer(void)
237  #endif /* OPENSSL */
238         u_int n;
239  
240 -       current_time += (1<<EVENT_TIMEOUT);
241 -
242         /*
243          * Adjustment timeout first.
244          */
245         if (adjust_timer <= current_time) {
246 -               adjust_timer += 1;
247 -               adj_host_clock();
248 +               adj_host_clock(current_time - adjust_timer + 1);
249 +               adjust_timer = current_time + 1;
250                 kod_proto();
251  #ifdef REFCLOCK
252                 for (n = 0; n < NTP_HASH_SIZE; n++) {
253 diff -up ntp-4.2.4p7/ntpd/ntpd.c.sleep ntp-4.2.4p7/ntpd/ntpd.c
254 --- ntp-4.2.4p7/ntpd/ntpd.c.sleep       2009-07-21 16:38:47.000000000 +0200
255 +++ ntp-4.2.4p7/ntpd/ntpd.c     2009-07-21 16:39:29.000000000 +0200
256 @@ -179,8 +179,6 @@ extern const char *Version;
257  
258  char const *progname;
259  
260 -int was_alarmed;
261 -
262  #ifdef DECL_SYSCALL
263  /*
264   * We put this here, since the argument profile is syscall-specific
265 @@ -434,6 +432,7 @@ set_process_priority(void)
266                 msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
267  }
268  
269 +#define TS_LAST_SIZE 2
270  
271  /*
272   * Main program.  Initialize us, disconnect us from the tty if necessary,
273 @@ -446,6 +445,9 @@ ntpdmain(
274         )
275  {
276         l_fp now;
277 +       l_fp ts_last[TS_LAST_SIZE];
278 +       unsigned int ts_last_index;
279 +       int time_elapsed;
280         struct recvbuf *rbuf;
281  #ifdef _AIX                    /* HMS: ifdef SIGDANGER? */
282         struct sigaction sa;
283 @@ -998,7 +1000,11 @@ getgroup: 
284  #else /* normal I/O */
285  
286         BLOCK_IO_AND_ALARM();
287 -       was_alarmed = 0;
288 +
289 +       for (ts_last_index = 0; ts_last_index < TS_LAST_SIZE; ts_last_index++)
290 +               L_CLR(&ts_last[ts_last_index]);
291 +       time_elapsed = ts_last_index = 0;
292 +
293         for (;;)
294         {
295  # if !defined(HAVE_SIGNALED_IO) 
296 @@ -1009,39 +1015,66 @@ getgroup:       
297                 int nfound;
298  # endif
299  
300 -               if (alarm_flag)         /* alarmed? */
301 -               {
302 -                       was_alarmed = 1;
303 -                       alarm_flag = 0;
304 -               }
305 -
306 -               if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
307 +               if (has_full_recv_buffer() == ISC_FALSE)
308                 {
309                         /*
310                          * Nothing to do.  Wait for something.
311                          */
312  # ifndef HAVE_SIGNALED_IO
313 +                       extern l_fp timer_base;
314 +                       l_fp ts, ts2, ts3;
315 +                       double d;
316 +
317                         rdfdes = activefds;
318 -#  if defined(VMS) || defined(SYS_VXWORKS)
319 -                       /* make select() wake up after one second */
320 -                       {
321 +                       ts2 = timer_base;
322 +                       get_systime(&ts);
323 +                       ts3 = ts;
324 +                       L_SUB(&ts3, &ts_last[ts_last_index]);
325 +
326 +                       /* don't call when_next_event() too often */
327 +                       if (ts3.l_ui)
328 +                               ts2.l_ui += when_next_event();
329 +                       else
330 +                               ts2.l_ui += 1;
331 +
332 +                       L_SUB(&ts2, &ts);
333 +                       LFPTOD(&ts2, d);
334 +                       DPRINTF(2, ("main: scheduled event in %f\n", d));
335 +                       if (d > 0.0) {
336                                 struct timeval t1;
337  
338 -                               t1.tv_sec = 1; t1.tv_usec = 0;
339 +                               t1.tv_sec = d;
340 +                               t1.tv_usec = (d - t1.tv_sec) * 1000000;
341                                 nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
342                                                 (fd_set *)0, &t1);
343 +                               get_systime(&ts);
344 +                       } else
345 +                               nfound = 0;
346 +
347 +                       ts3 = ts;
348 +                       L_SUB(&ts3, &timer_base);
349 +#ifdef DEBUG 
350 +                       LFPTOD(&ts3, d);
351 +                       DPRINTF(2, ("main: elapsed %f\n", d));
352 +#endif
353 +
354 +                       if (ts3.l_i < 0 || ts3.l_ui > ts2.l_ui + 10) {
355 +#ifdef DEBUG 
356 +                               DPRINTF(2, ("main: unexpected time jump\n"));
357 +#endif
358 +                               ts3.l_ui = 0;
359 +                               reinit_timer();
360                         }
361 -#  else
362 -                       nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
363 -                                       (fd_set *)0, (struct timeval *)0);
364 -#  endif /* VMS */
365 -                       if (nfound > 0)
366 -                       {
367 -                               l_fp ts;
368  
369 -                               get_systime(&ts);
370 +                       time_elapsed += ts3.l_ui;
371 +                       current_time += ts3.l_ui;
372 +                       timer_base.l_ui += ts3.l_ui;
373  
374 +                       if (nfound > 0)
375 +                       {
376                                 (void)input_handler(&ts);
377 +                               ts_last[ts_last_index] = ts;
378 +                               ts_last_index = (ts_last_index + 1) % TS_LAST_SIZE;
379                         }
380                         else if (nfound == -1 && errno != EINTR)
381                                 netsyslog(LOG_ERR, "select() error: %m");
382 @@ -1050,17 +1083,12 @@ getgroup:       
383                                 netsyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
384  #  endif /* DEBUG */
385  # else /* HAVE_SIGNALED_IO */
386 -                        
387 +#  error not supported
388                         wait_for_signal();
389  # endif /* HAVE_SIGNALED_IO */
390 -                       if (alarm_flag)         /* alarmed? */
391 -                       {
392 -                               was_alarmed = 1;
393 -                               alarm_flag = 0;
394 -                       }
395                 }
396  
397 -               if (was_alarmed)
398 +               if (time_elapsed)
399                 {
400                         UNBLOCK_IO_AND_ALARM();
401                         /*
402 @@ -1068,7 +1096,7 @@ getgroup: 
403                          * to process expiry.
404                          */
405                         timer();
406 -                       was_alarmed = 0;
407 +                       time_elapsed = 0;
408                          BLOCK_IO_AND_ALARM();
409                 }
410  
411 @@ -1086,19 +1114,8 @@ getgroup:        
412                         rbuf = get_full_recv_buffer();
413                         while (rbuf != NULL)
414                         {
415 -                               if (alarm_flag)
416 -                               {
417 -                                       was_alarmed = 1;
418 -                                       alarm_flag = 0;
419 -                               }
420                                 UNBLOCK_IO_AND_ALARM();
421  
422 -                               if (was_alarmed)
423 -                               {       /* avoid timer starvation during lengthy I/O handling */
424 -                                       timer();
425 -                                       was_alarmed = 0;
426 -                               }
427 -
428                                 /*
429                                  * Call the data procedure to handle each received
430                                  * packet.
This page took 0.055336 seconds and 3 git commands to generate.