This source file includes following definitions.
- clear_time_state
- handler
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <time.h>
21 #include <sys/time.h>
22 #include <sys/timex.h>
23 #include <string.h>
24 #include <signal.h>
25 #include "../kselftest.h"
26
27
28 int clear_time_state(void)
29 {
30 struct timex tx;
31 int ret;
32
33
34
35
36
37
38
39 tx.modes = ADJ_STATUS;
40 tx.status = STA_PLL;
41 ret = adjtimex(&tx);
42
43 tx.modes = ADJ_STATUS;
44 tx.status = 0;
45 ret = adjtimex(&tx);
46
47 return ret;
48 }
49
50
51 void handler(int unused)
52 {
53 clear_time_state();
54 exit(0);
55 }
56
57
58 int main(void)
59 {
60 struct timex tx;
61 struct timespec ts;
62 time_t next_leap;
63 int count = 0;
64
65 setbuf(stdout, NULL);
66
67 signal(SIGINT, handler);
68 signal(SIGKILL, handler);
69 printf("This runs for a few minutes. Press ctrl-c to stop\n");
70
71 clear_time_state();
72
73
74
75 clock_gettime(CLOCK_REALTIME, &ts);
76
77
78 next_leap = ts.tv_sec;
79 next_leap += 86400 - (next_leap % 86400);
80
81 for (count = 0; count < 20; count++) {
82 struct timeval tv;
83
84
85
86 tv.tv_sec = next_leap - 2;
87 tv.tv_usec = 0;
88 if (settimeofday(&tv, NULL)) {
89 printf("Error: You're likely not running with proper (ie: root) permissions\n");
90 return ksft_exit_fail();
91 }
92 tx.modes = 0;
93 adjtimex(&tx);
94
95
96 while (tx.time.tv_sec < next_leap + 1) {
97
98 tx.modes = ADJ_STATUS;
99 tx.status = STA_INS;
100 adjtimex(&tx);
101 }
102 clear_time_state();
103 printf(".");
104 fflush(stdout);
105 }
106 printf("[OK]\n");
107 return ksft_exit_pass();
108 }