Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 179292
Collapse All | Expand All

(-)ntp-4.2.4/include/ntp_stdlib.h.sleep (+1 lines)
Lines 101-106 Link Here
101
extern	void	signal_no_reset P((int, RETSIGTYPE (*func)(int)));
101
extern	void	signal_no_reset P((int, RETSIGTYPE (*func)(int)));
102
102
103
extern	void	getauthkeys 	P((const char *));
103
extern	void	getauthkeys 	P((const char *));
104
extern	int	auth_agekeys_is_needed P((void));
104
extern	void	auth_agekeys	P((void));
105
extern	void	auth_agekeys	P((void));
105
extern	void	rereadkeys	P((void));
106
extern	void	rereadkeys	P((void));
106
107
(-)ntp-4.2.4/include/ntpd.h.sleep (-2 / +5 lines)
Lines 118-125 Link Here
118
/* ntp_loopfilter.c */
118
/* ntp_loopfilter.c */
119
extern	void	init_loopfilter P((void));
119
extern	void	init_loopfilter P((void));
120
extern	int 	local_clock P((struct peer *, double));
120
extern	int 	local_clock P((struct peer *, double));
121
extern	void	adj_host_clock	P((void));
121
extern	int	adj_host_clock_is_needed P((void));
122
extern	void	adj_host_clock	P((int));
122
extern	void	loop_config P((int, double));
123
extern	void	loop_config P((int, double));
124
extern	int	huffpuff_enabled P((void));
123
extern	void	huffpuff	P((void));
125
extern	void	huffpuff	P((void));
124
extern	u_long	sys_clocktime;
126
extern	u_long	sys_clocktime;
125
extern	u_long	sys_tai;
127
extern	u_long	sys_tai;
Lines 219-225 Link Here
219
/* ntp_timer.c */
221
/* ntp_timer.c */
220
extern	void	init_timer	P((void));
222
extern	void	init_timer	P((void));
221
extern	void	reinit_timer	P((void));
223
extern	void	reinit_timer	P((void));
222
extern	void	timer		P((void));
224
extern	int	when_next_event	P((void));
225
extern	void	timer		P((int));
223
extern	void	timer_clr_stats P((void));
226
extern	void	timer_clr_stats P((void));
224
extern  void    timer_interfacetimeout P((u_long));
227
extern  void    timer_interfacetimeout P((u_long));
225
extern  volatile int interface_interval;
228
extern  volatile int interface_interval;
(-)ntp-4.2.4/libntp/authkeys.c.sleep (+18 lines)
Lines 394-399 Link Here
394
	}
394
	}
395
}
395
}
396
396
397
int auth_agekeys_is_needed() {
398
	struct savekey *sk;
399
	int i;
400
401
	if (authnumkeys > 20)
402
		return 1;
403
404
	for (i = 0; i < HASHSIZE; i++) {
405
		sk = key_hash[i];
406
		while (sk != 0) {
407
			if (sk->lifetime > 0)
408
				return 1;
409
			sk = sk->next;
410
		}
411
	}
412
	return 0;
413
}
414
397
/*
415
/*
398
 * auth_agekeys - delete keys whose lifetimes have expired
416
 * auth_agekeys - delete keys whose lifetimes have expired
399
 */
417
 */
(-)ntp-4.2.4/ntpd/ntp_loopfilter.c.sleep (-2 / +14 lines)
Lines 765-770 Link Here
765
#endif /* LOCKCLOCK */
765
#endif /* LOCKCLOCK */
766
}
766
}
767
767
768
int adj_host_clock_is_needed() {
769
	return !(!ntp_enable || mode_ntpdate || (pll_control &&
770
	    kern_enable && clock_max < 0.5));
771
}
768
772
769
/*
773
/*
770
 * adj_host_clock - Called once every second to update the local clock.
774
 * adj_host_clock - Called once every second to update the local clock.
Lines 774-780 Link Here
774
 */
778
 */
775
void
779
void
776
adj_host_clock(
780
adj_host_clock(
777
	void
781
	int time_elapsed
778
	)
782
	)
779
{
783
{
780
	double	adjustment;
784
	double	adjustment;
Lines 789-795 Link Here
789
	 * maximum error and the local clock driver will pick it up and
793
	 * maximum error and the local clock driver will pick it up and
790
	 * pass to the common refclock routines. Very elegant.
794
	 * pass to the common refclock routines. Very elegant.
791
	 */
795
	 */
792
	sys_rootdispersion += clock_phi;
796
	sys_rootdispersion += clock_phi * time_elapsed;
797
#if 0
798
	printf("loopfilter: %d\n", time_elapsed);
799
#endif
793
800
794
#ifndef LOCKCLOCK
801
#ifndef LOCKCLOCK
795
	/*
802
	/*
Lines 849-854 Link Here
849
}
856
}
850
857
851
858
859
int huffpuff_enabled()
860
{
861
	return sys_huffpuff != NULL;
862
}
863
852
/*
864
/*
853
 * huff-n'-puff filter
865
 * huff-n'-puff filter
854
 */
866
 */
(-)ntp-4.2.4/ntpd/ntpd.c.sleep (-31 / +54 lines)
Lines 188-195 Link Here
188
188
189
char const *progname;
189
char const *progname;
190
190
191
int was_alarmed;
192
193
#ifdef DECL_SYSCALL
191
#ifdef DECL_SYSCALL
194
/*
192
/*
195
 * We put this here, since the argument profile is syscall-specific
193
 * We put this here, since the argument profile is syscall-specific
Lines 443-448 Link Here
443
		msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
441
		msyslog(LOG_ERR, "set_process_priority: No way found to improve our priority");
444
}
442
}
445
443
444
#define TS_LAST_SIZE 2
446
445
447
/*
446
/*
448
 * Main program.  Initialize us, disconnect us from the tty if necessary,
447
 * Main program.  Initialize us, disconnect us from the tty if necessary,
Lines 455-460 Link Here
455
	)
454
	)
456
{
455
{
457
	l_fp now;
456
	l_fp now;
457
	l_fp ts_last[TS_LAST_SIZE];
458
	unsigned int ts_last_index;
459
	int time_elapsed;
458
	struct recvbuf *rbuf;
460
	struct recvbuf *rbuf;
459
#ifdef _AIX			/* HMS: ifdef SIGDANGER? */
461
#ifdef _AIX			/* HMS: ifdef SIGDANGER? */
460
	struct sigaction sa;
462
	struct sigaction sa;
Lines 1012-1018 Link Here
1012
#else /* normal I/O */
1014
#else /* normal I/O */
1013
1015
1014
	BLOCK_IO_AND_ALARM();
1016
	BLOCK_IO_AND_ALARM();
1015
	was_alarmed = 0;
1017
1018
	for (ts_last_index = 0; ts_last_index < TS_LAST_SIZE; ts_last_index++)
1019
		L_CLR(&ts_last[ts_last_index]);
1020
	time_elapsed = 0;
1021
1016
	for (;;)
1022
	for (;;)
1017
	{
1023
	{
1018
# if !defined(HAVE_SIGNALED_IO) 
1024
# if !defined(HAVE_SIGNALED_IO) 
Lines 1023-1061 Link Here
1023
		int nfound;
1029
		int nfound;
1024
# endif
1030
# endif
1025
1031
1026
		if (alarm_flag) 	/* alarmed? */
1032
		if (has_full_recv_buffer() == ISC_FALSE)
1027
		{
1028
			was_alarmed = 1;
1029
			alarm_flag = 0;
1030
		}
1031
1032
		if (!was_alarmed && has_full_recv_buffer() == ISC_FALSE)
1033
		{
1033
		{
1034
			/*
1034
			/*
1035
			 * Nothing to do.  Wait for something.
1035
			 * Nothing to do.  Wait for something.
1036
			 */
1036
			 */
1037
# ifndef HAVE_SIGNALED_IO
1037
# ifndef HAVE_SIGNALED_IO
1038
			extern l_fp timer_base;
1039
			l_fp ts, ts2, ts3;
1040
			double d;
1041
1038
			rdfdes = activefds;
1042
			rdfdes = activefds;
1039
#  if defined(VMS) || defined(SYS_VXWORKS)
1043
			ts2 = timer_base;
1040
			/* make select() wake up after one second */
1044
			get_systime(&ts);
1041
			{
1045
			ts3 = ts;
1046
			L_SUB(&ts3, &ts_last[ts_last_index]);
1047
1048
			/* don't call when_next_event() too often */
1049
			if (ts3.l_ui)
1050
				ts2.l_ui += when_next_event();
1051
			else
1052
				ts2.l_ui += 1;
1053
1054
			L_SUB(&ts2, &ts);
1055
			LFPTOD(&ts2, d);
1056
#if 0
1057
			printf("%f ", d);
1058
#endif
1059
			if (d >= 0.0) {
1042
				struct timeval t1;
1060
				struct timeval t1;
1043
1061
1044
				t1.tv_sec = 1; t1.tv_usec = 0;
1062
				/* shoot 1ms over */
1063
				d += 0.001;
1064
				t1.tv_sec = floor(d);
1065
				t1.tv_usec = (d - t1.tv_sec) * 1000000;
1045
				nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
1066
				nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
1046
						(fd_set *)0, &t1);
1067
						(fd_set *)0, &t1);
1047
			}
1048
#  else
1049
			nfound = select(maxactivefd+1, &rdfdes, (fd_set *)0,
1050
					(fd_set *)0, (struct timeval *)0);
1051
#  endif /* VMS */
1052
			if (nfound > 0)
1053
			{
1054
				l_fp ts;
1055
1056
				get_systime(&ts);
1068
				get_systime(&ts);
1069
			} else
1070
				nfound = 0;
1057
1071
1072
			ts2 = ts;
1073
			L_SUB(&ts2, &timer_base);
1074
			time_elapsed += ts2.l_ui;
1075
			timer_base.l_ui += ts2.l_ui;
1076
#if 0
1077
			ts2 = ts;
1078
			ts2.l_ui = 0;
1079
			LFPTOD(&ts2, d);
1080
			printf("%f\n", d);
1081
#endif
1082
			if (nfound > 0)
1083
			{
1058
				(void)input_handler(&ts);
1084
				(void)input_handler(&ts);
1085
				ts_last[ts_last_index] = ts;
1086
				ts_last_index = (ts_last_index + 1) % TS_LAST_SIZE;
1059
			}
1087
			}
1060
			else if (nfound == -1 && errno != EINTR)
1088
			else if (nfound == -1 && errno != EINTR)
1061
				netsyslog(LOG_ERR, "select() error: %m");
1089
				netsyslog(LOG_ERR, "select() error: %m");
Lines 1067-1088 Link Here
1067
                        
1095
                        
1068
			wait_for_signal();
1096
			wait_for_signal();
1069
# endif /* HAVE_SIGNALED_IO */
1097
# endif /* HAVE_SIGNALED_IO */
1070
			if (alarm_flag) 	/* alarmed? */
1071
			{
1072
				was_alarmed = 1;
1073
				alarm_flag = 0;
1074
			}
1075
		}
1098
		}
1076
1099
1077
		if (was_alarmed)
1100
		if (time_elapsed)
1078
		{
1101
		{
1079
			UNBLOCK_IO_AND_ALARM();
1102
			UNBLOCK_IO_AND_ALARM();
1080
			/*
1103
			/*
1081
			 * Out here, signals are unblocked.  Call timer routine
1104
			 * Out here, signals are unblocked.  Call timer routine
1082
			 * to process expiry.
1105
			 * to process expiry.
1083
			 */
1106
			 */
1084
			timer();
1107
			timer(time_elapsed);
1085
			was_alarmed = 0;
1108
			time_elapsed = 0;
1086
                        BLOCK_IO_AND_ALARM();
1109
                        BLOCK_IO_AND_ALARM();
1087
		}
1110
		}
1088
1111
(-)ntp-4.2.4/ntpd/ntp_timer.c.sleep (-4 / +49 lines)
Lines 63-68 Link Here
63
#define HOUR	(60*60)
63
#define HOUR	(60*60)
64
64
65
u_long current_time;
65
u_long current_time;
66
l_fp timer_base;
66
67
67
/*
68
/*
68
 * Stats.  Number of overflows and number of calls to transmit().
69
 * Stats.  Number of overflows and number of calls to transmit().
Lines 116-121 Link Here
116
	itimer.it_interval.tv_nsec = 0;
117
	itimer.it_interval.tv_nsec = 0;
117
	timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL);
118
	timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL);
118
#  else
119
#  else
120
	get_systime(&timer_base);
121
	return;
119
	getitimer(ITIMER_REAL, &itimer);
122
	getitimer(ITIMER_REAL, &itimer);
120
	if (itimer.it_value.tv_sec < 0 || itimer.it_value.tv_sec > (1<<EVENT_TIMEOUT)) {
123
	if (itimer.it_value.tv_sec < 0 || itimer.it_value.tv_sec > (1<<EVENT_TIMEOUT)) {
121
		itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
124
		itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
Lines 160-165 Link Here
160
	timer_timereset = 0;
163
	timer_timereset = 0;
161
164
162
#if !defined(SYS_WINNT)
165
#if !defined(SYS_WINNT)
166
	get_systime(&timer_base);
167
	return;
163
	/*
168
	/*
164
	 * Set up the alarm interrupt.	The first comes 2**EVENT_TIMEOUT
169
	 * Set up the alarm interrupt.	The first comes 2**EVENT_TIMEOUT
165
	 * seconds from now and they continue on every 2**EVENT_TIMEOUT
170
	 * seconds from now and they continue on every 2**EVENT_TIMEOUT
Lines 252-262 Link Here
252
}
257
}
253
#endif
258
#endif
254
259
260
int when_next_event() {
261
	register struct peer *peer, *next_peer;
262
	u_int n;
263
	int next = current_time + HOUR;
264
265
	if (adj_host_clock_is_needed())
266
		return 1;
267
	for (n = 0; n < NTP_HASH_SIZE; n++) {
268
		for (peer = peer_hash[n]; peer != 0; peer = next_peer) {
269
			next_peer = peer->next;
270
#ifdef REFCLOCK
271
			if (peer->flags & FLAG_REFCLOCK)
272
				return 1;
273
#endif /* REFCLOCK */
274
			if (peer->action && peer->nextaction < next)
275
				next = peer->nextaction;
276
			if (peer->nextdate < next)
277
				next = peer->nextdate;
278
		}
279
	}
280
281
	if (auth_agekeys_is_needed() && keys_timer < next)
282
		next = keys_timer;
283
	if (huffpuff_enabled() && huffpuff_timer < next)
284
		next = huffpuff_timer;
285
#ifdef OPENSSL
286
	if (revoke_timer < next)
287
		next = revoke_timer;
288
#endif /* OPENSSL */
289
	if (interface_interval && interface_timer < next)
290
		next = interface_timer;
291
	if (stats_timer < next)
292
		next = stats_timer;
293
294
	next -= current_time;
295
	if (next <= 0)
296
		next = 1;
297
	return next;
298
}
299
255
/*
300
/*
256
 * timer - dispatch anyone who needs to be
301
 * timer - dispatch anyone who needs to be
257
 */
302
 */
258
void
303
void
259
timer(void)
304
timer(int time_elapsed)
260
{
305
{
261
	register struct peer *peer, *next_peer;
306
	register struct peer *peer, *next_peer;
262
#ifdef OPENSSL
307
#ifdef OPENSSL
Lines 264-277 Link Here
264
#endif /* OPENSSL */
309
#endif /* OPENSSL */
265
	u_int n;
310
	u_int n;
266
311
267
	current_time += (1<<EVENT_TIMEOUT);
312
	current_time += time_elapsed;
268
313
269
	/*
314
	/*
270
	 * Adjustment timeout first.
315
	 * Adjustment timeout first.
271
	 */
316
	 */
272
	if (adjust_timer <= current_time) {
317
	if (adjust_timer <= current_time) {
273
		adjust_timer += 1;
318
		adj_host_clock(current_time - adjust_timer + 1);
274
		adj_host_clock();
319
		adjust_timer = current_time + 1;
275
		kod_proto();
320
		kod_proto();
276
#ifdef REFCLOCK
321
#ifdef REFCLOCK
277
		for (n = 0; n < NTP_HASH_SIZE; n++) {
322
		for (n = 0; n < NTP_HASH_SIZE; n++) {

Return to bug 179292