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