xref: /netbsd-src/external/bsd/ntp/dist/util/testrs6000.c (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1*cdfa2a7eSchristos /*	$NetBSD: testrs6000.c,v 1.5 2020/05/25 20:47:37 christos Exp $	*/
2abb0f93cSkardel 
3abb0f93cSkardel /* Checks for the RS/6000 AIX adjtime() bug, in which if a negative
4abb0f93cSkardel  * offset is given, the system gets messed up and never completes the
5abb0f93cSkardel  * adjustment.  If the problem is fixed, this program will print the
6abb0f93cSkardel  * time, sit there for 10 seconds, and exit.  If the problem isn't fixed,
7abb0f93cSkardel  * the program will print an occasional "result=nnnnnn" (the residual
8abb0f93cSkardel  * slew from adjtime()).
9abb0f93cSkardel  *
10abb0f93cSkardel  * Compile this with bsdcc and run it as root!
11abb0f93cSkardel  */
12abb0f93cSkardel #include <signal.h>
13abb0f93cSkardel #include <sys/time.h>
14abb0f93cSkardel #include <time.h>
15abb0f93cSkardel #include <stdio.h>
16abb0f93cSkardel 
17abb0f93cSkardel int timeout();
18abb0f93cSkardel struct timeval adjustment, result;
19abb0f93cSkardel 
20abb0f93cSkardel int
main(int argc,char * argv[])21abb0f93cSkardel main (
22abb0f93cSkardel 	int argc,
23abb0f93cSkardel 	char *argv[]
24abb0f93cSkardel 	)
25abb0f93cSkardel {
26abb0f93cSkardel 	struct itimerval value, oldvalue;
27abb0f93cSkardel 	int i;
28abb0f93cSkardel 	time_t curtime;
29abb0f93cSkardel 
30abb0f93cSkardel 	curtime = time(0);
31abb0f93cSkardel 	printf("Starting: %s", ctime(&curtime));
32abb0f93cSkardel 	value.it_interval.tv_sec = value.it_value.tv_sec = 1;
33abb0f93cSkardel 	value.it_interval.tv_usec = value.it_value.tv_usec = 0;
34abb0f93cSkardel 	adjustment.tv_sec = 0;
35abb0f93cSkardel 	adjustment.tv_usec = -2000;
36abb0f93cSkardel 	signal(SIGALRM, timeout);
37abb0f93cSkardel 	setitimer(ITIMER_REAL, &value, &oldvalue);
38abb0f93cSkardel 	for (i=0; i<10; i++) {
39abb0f93cSkardel 		pause();
40abb0f93cSkardel 	}
41abb0f93cSkardel }
42abb0f93cSkardel 
43abb0f93cSkardel int
timeout(int sig,int code,struct sigcontext * scp)44abb0f93cSkardel timeout(
45abb0f93cSkardel 	int sig,
46abb0f93cSkardel 	int code,
47abb0f93cSkardel 	struct sigcontext *scp
48abb0f93cSkardel 	)
49abb0f93cSkardel {
50abb0f93cSkardel 	signal (SIGALRM, timeout);
51abb0f93cSkardel 	if (adjtime(&adjustment, &result))
52abb0f93cSkardel 	    printf("adjtime call failed\n");
53abb0f93cSkardel 	if (result.tv_sec != 0 || result.tv_usec != 0) {
54abb0f93cSkardel 		printf("result.u = %d.%06.6d  ", (int) result.tv_sec,
55abb0f93cSkardel 		       (int) result.tv_usec);
56abb0f93cSkardel 	}
57abb0f93cSkardel }
58