0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <stdio.h>
0019 #include <stdlib.h>
0020 #include <time.h>
0021 #include <sys/time.h>
0022 #include <sys/timex.h>
0023 #include <string.h>
0024 #include <signal.h>
0025 #include "../kselftest.h"
0026
0027
0028 int clear_time_state(void)
0029 {
0030 struct timex tx;
0031 int ret;
0032
0033
0034
0035
0036
0037
0038
0039 tx.modes = ADJ_STATUS;
0040 tx.status = STA_PLL;
0041 ret = adjtimex(&tx);
0042
0043 tx.modes = ADJ_STATUS;
0044 tx.status = 0;
0045 ret = adjtimex(&tx);
0046
0047 return ret;
0048 }
0049
0050
0051 void handler(int unused)
0052 {
0053 clear_time_state();
0054 exit(0);
0055 }
0056
0057
0058 int main(void)
0059 {
0060 struct timex tx;
0061 struct timespec ts;
0062 time_t next_leap;
0063 int count = 0;
0064
0065 setbuf(stdout, NULL);
0066
0067 signal(SIGINT, handler);
0068 signal(SIGKILL, handler);
0069 printf("This runs for a few minutes. Press ctrl-c to stop\n");
0070
0071 clear_time_state();
0072
0073
0074
0075 clock_gettime(CLOCK_REALTIME, &ts);
0076
0077
0078 next_leap = ts.tv_sec;
0079 next_leap += 86400 - (next_leap % 86400);
0080
0081 for (count = 0; count < 20; count++) {
0082 struct timeval tv;
0083
0084
0085
0086 tv.tv_sec = next_leap - 2;
0087 tv.tv_usec = 0;
0088 if (settimeofday(&tv, NULL)) {
0089 printf("Error: You're likely not running with proper (ie: root) permissions\n");
0090 return ksft_exit_fail();
0091 }
0092 tx.modes = 0;
0093 adjtimex(&tx);
0094
0095
0096 while (tx.time.tv_sec < next_leap + 1) {
0097
0098 tx.modes = ADJ_STATUS;
0099 tx.status = STA_INS;
0100 adjtimex(&tx);
0101 }
0102 clear_time_state();
0103 printf(".");
0104 fflush(stdout);
0105 }
0106 printf("[OK]\n");
0107 return ksft_exit_pass();
0108 }