]> git.pld-linux.org Git - packages/ntp.git/blame - ntp-4.2.6p1-sleep.patch
ntpd requires libgcc_s.so.1
[packages/ntp.git] / ntp-4.2.6p1-sleep.patch
CommitLineData
a8809dbd
ER
1diff -up ntp-4.2.6p1/include/ntp_refclock.h.sleep ntp-4.2.6p1/include/ntp_refclock.h
2--- ntp-4.2.6p1/include/ntp_refclock.h.sleep 2009-12-09 08:36:35.000000000 +0100
3+++ ntp-4.2.6p1/include/ntp_refclock.h 2010-03-10 19:27:46.000000000 +0100
4@@ -260,6 +260,7 @@ extern void refclock_control (sockaddr_u
5 struct refclockstat *);
6 extern int refclock_open (char *, u_int, u_int);
7 extern int refclock_setup (int, u_int, u_int);
8+extern int refclock_timer_needed (struct peer *);
9 extern void refclock_timer (struct peer *);
10 extern void refclock_transmit (struct peer *);
11 extern int refclock_ioctl (int, u_int);
12diff -up ntp-4.2.6p1/include/ntp_stdlib.h.sleep ntp-4.2.6p1/include/ntp_stdlib.h
13--- ntp-4.2.6p1/include/ntp_stdlib.h.sleep 2009-12-09 08:36:35.000000000 +0100
14+++ ntp-4.2.6p1/include/ntp_stdlib.h 2010-03-10 19:27:46.000000000 +0100
15@@ -116,6 +116,7 @@ extern const char * FindConfig (const ch
16 extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
17
18 extern void getauthkeys (const char *);
19+extern int auth_agekeys_needed (void);
20 extern void auth_agekeys (void);
21 extern void rereadkeys (void);
22
23diff -up ntp-4.2.6p1/include/ntpd.h.sleep ntp-4.2.6p1/include/ntpd.h
24--- ntp-4.2.6p1/include/ntpd.h.sleep 2009-12-09 08:36:35.000000000 +0100
25+++ ntp-4.2.6p1/include/ntpd.h 2010-03-10 19:27:46.000000000 +0100
26@@ -112,8 +112,10 @@ extern void block_io_and_alarm (void);
27 /* ntp_loopfilter.c */
28 extern void init_loopfilter(void);
29 extern int local_clock(struct peer *, double);
30-extern void adj_host_clock(void);
31+extern int adj_host_clock_needed(void);
32+extern void adj_host_clock(int);
33 extern void loop_config(int, double);
34+extern int huffpuff_enabled(void);
35 extern void huffpuff(void);
36 extern u_long sys_clocktime;
37 extern u_int sys_tai;
38@@ -219,6 +221,8 @@ extern void hack_restrict (int, sockaddr
39 /* ntp_timer.c */
40 extern void init_timer (void);
41 extern void reinit_timer (void);
42+extern double get_timeout (l_fp *);
43+extern int timer_elapsed (l_fp, int);
44 extern void timer (void);
45 extern void timer_clr_stats (void);
46 extern void timer_interfacetimeout (u_long);
47diff -up ntp-4.2.6p1/libntp/authkeys.c.sleep ntp-4.2.6p1/libntp/authkeys.c
48--- ntp-4.2.6p1/libntp/authkeys.c.sleep 2009-12-09 08:36:35.000000000 +0100
49+++ ntp-4.2.6p1/libntp/authkeys.c 2010-03-10 19:27:46.000000000 +0100
50@@ -445,6 +445,25 @@ auth_delkeys(void)
51 }
52 }
53
54+int
55+auth_agekeys_needed(void) {
56+ struct savekey *sk;
57+ int i;
58+
59+ if (authnumkeys > 20)
60+ return 1;
61+
62+ for (i = 0; i < HASHSIZE; i++) {
63+ sk = key_hash[i];
64+ while (sk != 0) {
65+ if (sk->lifetime > 0)
66+ return 1;
67+ sk = sk->next;
68+ }
69+ }
70+ return 0;
71+}
72+
73 /*
74 * auth_agekeys - delete keys whose lifetimes have expired
75 */
76diff -up ntp-4.2.6p1/ntpd/ntp_loopfilter.c.sleep ntp-4.2.6p1/ntpd/ntp_loopfilter.c
77--- ntp-4.2.6p1/ntpd/ntp_loopfilter.c.sleep 2009-12-09 08:36:36.000000000 +0100
78+++ ntp-4.2.6p1/ntpd/ntp_loopfilter.c 2010-03-10 19:27:46.000000000 +0100
79@@ -677,6 +677,13 @@ local_clock(
80 #endif /* LOCKCLOCK */
81 }
82
83+int
84+adj_host_clock_needed(void)
85+{
86+ return !(!ntp_enable || mode_ntpdate || (pll_control &&
87+ kern_enable));
88+}
89+
90
91 /*
92 * adj_host_clock - Called once every second to update the local clock.
93@@ -686,7 +693,7 @@ local_clock(
94 */
95 void
96 adj_host_clock(
97- void
98+ int time_elapsed
99 )
100 {
101 double adjustment;
102@@ -698,7 +705,7 @@ adj_host_clock(
103 * since the poll interval can exceed one day, the old test
104 * would be counterproductive.
105 */
106- sys_rootdisp += clock_phi;
107+ sys_rootdisp += clock_phi * time_elapsed;
108
109 #ifndef LOCKCLOCK
110 /*
111@@ -819,6 +826,12 @@ set_freq(
112 #endif /* KERNEL_PLL */
113 }
114
115+int
116+huffpuff_enabled(void)
117+{
118+ return sys_huffpuff != NULL;
119+}
120+
121 /*
122 * huff-n'-puff filter
123 */
124diff -up ntp-4.2.6p1/ntpd/ntp_refclock.c.sleep ntp-4.2.6p1/ntpd/ntp_refclock.c
125--- ntp-4.2.6p1/ntpd/ntp_refclock.c.sleep 2009-12-09 08:36:36.000000000 +0100
126+++ ntp-4.2.6p1/ntpd/ntp_refclock.c 2010-03-10 19:27:46.000000000 +0100
127@@ -268,6 +268,21 @@ refclock_unpeer(
128 }
129
130
131+int
132+refclock_timer_needed(
133+ struct peer *peer /* peer structure pointer */
134+ )
135+{
136+ u_char clktype;
137+ int unit;
138+
139+ clktype = peer->refclktype;
140+ unit = peer->refclkunit;
141+ if (refclock_conf[clktype]->clock_timer != noentry)
142+ return 1;
143+ return 0;
144+}
145+
146 /*
147 * refclock_timer - called once per second for housekeeping.
148 */
149diff -up ntp-4.2.6p1/ntpd/ntp_timer.c.sleep ntp-4.2.6p1/ntpd/ntp_timer.c
150--- ntp-4.2.6p1/ntpd/ntp_timer.c.sleep 2009-12-09 08:36:35.000000000 +0100
151+++ ntp-4.2.6p1/ntpd/ntp_timer.c 2010-03-11 15:23:59.000000000 +0100
152@@ -56,7 +56,6 @@ static u_long adjust_timer; /* second ti
153 static u_long stats_timer; /* stats timer */
154 static u_long huffpuff_timer; /* huff-n'-puff timer */
155 u_long leapsec; /* leapseconds countdown */
156-l_fp sys_time; /* current system time */
157 #ifdef OPENSSL
158 static u_long revoke_timer; /* keys revoke timer */
159 static u_long keys_timer; /* session key timer */
160@@ -74,6 +73,12 @@ volatile u_long alarm_overflow;
161 #define DAY (24 * HOUR)
162
163 u_long current_time; /* seconds since startup */
164+l_fp timer_base;
165+int time_elapsed;
166+
167+#define TIMEOUT_TS_SIZE 2
168+l_fp timeout_ts[TIMEOUT_TS_SIZE];
169+unsigned int timeout_ts_index;
170
171 /*
172 * Stats. Number of overflows and number of calls to transmit().
173@@ -110,6 +115,8 @@ static RETSIGTYPE alarming (int);
174 void
175 reinit_timer(void)
176 {
177+ get_systime(&timer_base);
178+#if 0
179 #if !defined(SYS_WINNT) && !defined(VMS)
180 # if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
181 timer_gettime(ntpd_timerid, &itimer);
182@@ -143,6 +150,7 @@ reinit_timer(void)
183 setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
184 # endif
185 # endif /* VMS */
186+#endif
187 }
188
189 /*
190@@ -165,6 +173,12 @@ init_timer(void)
191 timer_xmtcalls = 0;
192 timer_timereset = 0;
193
194+ get_systime(&timer_base);
195+
196+ for (timeout_ts_index = 0; timeout_ts_index < TIMEOUT_TS_SIZE; timeout_ts_index++)
197+ L_CLR(&timeout_ts[timeout_ts_index]);
198+ timeout_ts_index = 0;
199+#if 0
200 #if !defined(SYS_WINNT)
201 /*
202 * Set up the alarm interrupt. The first comes 2**EVENT_TIMEOUT
203@@ -226,6 +240,7 @@ init_timer(void)
204 }
205
206 #endif /* SYS_WINNT */
207+#endif
208 }
209
210 #if defined(SYS_WINNT)
211@@ -236,6 +251,104 @@ get_timer_handle(void)
212 }
213 #endif
214
215+double
216+get_timeout(l_fp *now)
217+{
218+ register struct peer *peer, *next_peer;
219+ u_int n;
220+ double r;
221+ int next;
222+ l_fp ts;
223+
224+ ts = *now;
225+ L_SUB(&ts, &timeout_ts[timeout_ts_index]);
226+ timeout_ts[timeout_ts_index] = *now;
227+ timeout_ts_index = (timeout_ts_index + 1) % TIMEOUT_TS_SIZE;
228+
229+ /* don't waste CPU time if called too frequently */
230+ if (ts.l_ui == 0) {
231+ next = 1;
232+ goto finish;
233+ }
234+
235+ next = current_time + HOUR;
236+
237+ if (adj_host_clock_needed()) {
238+ next = 1;
239+ goto finish;
240+ }
241+ for (n = 0; n < NTP_HASH_SIZE; n++) {
242+ for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
243+ next_peer = peer->next;
244+#ifdef REFCLOCK
245+ if (peer->flags & FLAG_REFCLOCK && refclock_timer_needed(peer)) {
246+ next = 1;
247+ goto finish;
248+ }
249+#endif /* REFCLOCK */
250+ if (peer->action)
251+ next = min(next, peer->nextaction);
252+ next = min(next, peer->nextdate);
253+ }
254+ }
255+
256+ if (leapsec > 0)
257+ next = min(next, leapsec);
258+
259+ if (huffpuff_enabled())
260+ next = min(next, huffpuff_timer);
261+
262+#ifdef OPENSSL
263+ if (auth_agekeys_needed())
264+ next = min(next, keys_timer);
265+ if (sys_leap != LEAP_NOTINSYNC)
266+ next = min(next, revoke_timer);
267+#endif /* OPENSSL */
268+
269+ if (interface_interval)
270+ next = min(next, interface_timer);
271+
272+ next = min(next, stats_timer);
273+
274+ next -= current_time;
275+ if (next <= 0)
276+ next = 1;
277+finish:
278+ ts = timer_base;
279+ ts.l_ui += next;
280+ L_SUB(&ts, now);
281+ LFPTOD(&ts, r);
282+#ifdef DEBUG
283+ DPRINTF(2, ("timer: timeout %f\n", r));
284+#endif
285+
286+ return r;
287+}
288+
289+int
290+timer_elapsed(l_fp now, int timeout)
291+{
292+ int elapsed;
293+
294+ L_SUB(&now, &timer_base);
295+ elapsed = now.l_i;
296+ if (elapsed < 0 || elapsed > timeout + 10) {
297+#ifdef DEBUG
298+ DPRINTF(2, ("timer: unexpected time jump\n"));
299+#endif
300+ elapsed = 0;
301+ reinit_timer();
302+
303+ }
304+ timer_base.l_ui += elapsed;
305+ time_elapsed += elapsed;
306+ current_time += elapsed;
307+#ifdef DEBUG
308+ DPRINTF(2, ("timer: time elapsed %d\n", time_elapsed));
309+#endif
310+ return time_elapsed;
311+}
312+
313 /*
314 * timer - event timer
315 */
316@@ -251,11 +364,9 @@ timer(void)
317 * kiss-o'-deatch function and implement the association
318 * polling function..
319 */
320- current_time++;
321- get_systime(&sys_time);
322 if (adjust_timer <= current_time) {
323- adjust_timer += 1;
324- adj_host_clock();
325+ adjust_timer += time_elapsed;
326+ adj_host_clock(time_elapsed);
327 #ifdef REFCLOCK
328 for (n = 0; n < NTP_HASH_SIZE; n++) {
329 for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
330@@ -286,7 +397,7 @@ timer(void)
331 * 128 s or less.
332 */
333 if (peer->throttle > 0)
334- peer->throttle--;
335+ peer->throttle -= min(peer->throttle, time_elapsed);
336 if (peer->nextdate <= current_time) {
337 #ifdef REFCLOCK
338 if (peer->flags & FLAG_REFCLOCK)
339@@ -333,7 +444,7 @@ timer(void)
340 * set.
341 */
342 if (leapsec > 0) {
343- leapsec--;
344+ leapsec -= min(leapsec, time_elapsed);
345 if (leapsec == 0) {
346 sys_leap = LEAP_NOWARNING;
347 sys_tai = leap_tai;
348@@ -398,11 +509,15 @@ timer(void)
349 * Finally, write hourly stats.
350 */
351 if (stats_timer <= current_time) {
352+ l_fp sys_time;
353+ get_systime(&sys_time);
354 stats_timer += HOUR;
355 write_stats();
356 if (sys_tai != 0 && sys_time.l_ui > leap_expire)
357 report_event(EVNT_LEAPVAL, NULL, NULL);
358 }
359+
360+ time_elapsed = 0;
361 }
362
363
364diff -up ntp-4.2.6p1/ntpd/ntpd.c.sleep ntp-4.2.6p1/ntpd/ntpd.c
365--- ntp-4.2.6p1/ntpd/ntpd.c.sleep 2010-03-10 19:27:46.000000000 +0100
366+++ ntp-4.2.6p1/ntpd/ntpd.c 2010-03-10 19:27:46.000000000 +0100
367@@ -195,8 +195,6 @@ extern const char *Version;
368
369 char const *progname;
370
371-int was_alarmed;
372-
373 #ifdef DECL_SYSCALL
374 /*
375 * We put this here, since the argument profile is syscall-specific
376@@ -1033,7 +1031,7 @@ getgroup:
377 #else /* normal I/O */
378
379 BLOCK_IO_AND_ALARM();
380- was_alarmed = 0;
381+
382 for (;;)
383 {
384 # if !defined(HAVE_SIGNALED_IO)
385@@ -1041,42 +1039,39 @@ getgroup:
386 extern int maxactivefd;
387
388 fd_set rdfdes;
389- int nfound;
390-# endif
391+ int nfound, time_elapsed;
392
393- if (alarm_flag) /* alarmed? */
394- {
395- was_alarmed = 1;
396- alarm_flag = 0;
397- }
398+ time_elapsed = 0;
399+# endif
400
401- if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
402+ if (has_full_recv_buffer() == ISC_FALSE)
403 {
404 /*
405 * Nothing to do. Wait for something.
406 */
407 # ifndef HAVE_SIGNALED_IO
408+ double timeout;
409+
410 rdfdes = activefds;
411-# if defined(VMS) || defined(SYS_VXWORKS)
412- /* make select() wake up after one second */
413- {
414- struct timeval t1;
415+ get_systime(&now);
416+ timeout = get_timeout(&now);
417
418- t1.tv_sec = 1; t1.tv_usec = 0;
419+ if (timeout > 0.0) {
420+ struct timeval t1;
421+
422+ t1.tv_sec = timeout;
423+ t1.tv_usec = (timeout - t1.tv_sec) * 1000000;
424 nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
425 (fd_set *)0, &t1);
426- }
427-# else
428- nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
429- (fd_set *)0, (struct timeval *)0);
430-# endif /* VMS */
431- if (nfound > 0)
432- {
433- l_fp ts;
434+ get_systime(&now);
435+ } else
436+ nfound = 0;
437
438- get_systime(&ts);
439+ time_elapsed = timer_elapsed(now, timeout);
440
441- (void)input_handler(&ts);
442+ if (nfound > 0)
443+ {
444+ (void)input_handler(&now);
445 }
446 else if (nfound == -1 && errno != EINTR)
447 msyslog(LOG_ERR, "select() error: %m");
448@@ -1085,17 +1080,13 @@ getgroup:
449 msyslog(LOG_DEBUG, "select(): nfound=%d, error: %m", nfound);
450 # endif /* DEBUG */
451 # else /* HAVE_SIGNALED_IO */
452+# error not supported by sleep patch
453
454 wait_for_signal();
455 # endif /* HAVE_SIGNALED_IO */
456- if (alarm_flag) /* alarmed? */
457- {
458- was_alarmed = 1;
459- alarm_flag = 0;
460- }
461 }
462
463- if (was_alarmed)
464+ if (time_elapsed > 0)
465 {
466 UNBLOCK_IO_AND_ALARM();
467 /*
468@@ -1103,7 +1094,6 @@ getgroup:
469 * to process expiry.
470 */
471 timer();
472- was_alarmed = 0;
473 BLOCK_IO_AND_ALARM();
474 }
475
476@@ -1121,19 +1111,8 @@ getgroup:
477 rbuf = get_full_recv_buffer();
478 while (rbuf != NULL)
479 {
480- if (alarm_flag)
481- {
482- was_alarmed = 1;
483- alarm_flag = 0;
484- }
485 UNBLOCK_IO_AND_ALARM();
486
487- if (was_alarmed)
488- { /* avoid timer starvation during lengthy I/O handling */
489- timer();
490- was_alarmed = 0;
491- }
492-
493 /*
494 * Call the data procedure to handle each received
495 * packet.
This page took 0.115384 seconds and 4 git commands to generate.