1 /* Demo leapsecond deadlock
2 * by: John Stultz (john.stultz@linaro.org)
3 * (C) Copyright IBM 2012
4 * (C) Copyright 2013, 2015 Linaro Limited
5 * Licensed under the GPL
7 * This test demonstrates leapsecond deadlock that is possibe
8 * on kernels from 2.6.26 to 3.3.
10 * WARNING: THIS WILL LIKELY HARDHANG SYSTEMS AND MAY LOSE DATA
11 * RUN AT YOUR OWN RISK!
13 * $ gcc leapcrash.c -o leapcrash -lrt
22 #include <sys/timex.h>
25 #include "../kselftest.h"
27 /* clear NTP time_status & time_state */
28 int clear_time_state(void)
34 * We have to call adjtime twice here, as kernels
35 * prior to 6b1859dba01c7 (included in 3.5 and
36 * -stable), had an issue with the state machine
37 * and wouldn't clear the STA_INS/DEL flag directly.
39 tx
.modes
= ADJ_STATUS
;
43 tx
.modes
= ADJ_STATUS
;
50 /* Make sure we cleanup on ctrl-c */
51 void handler(int unused
)
67 signal(SIGINT
, handler
);
68 signal(SIGKILL
, handler
);
69 printf("This runs for a few minutes. Press ctrl-c to stop\n");
74 /* Get the current time */
75 clock_gettime(CLOCK_REALTIME
, &ts
);
77 /* Calculate the next possible leap second 23:59:60 GMT */
78 next_leap
= ts
.tv_sec
;
79 next_leap
+= 86400 - (next_leap
% 86400);
81 for (count
= 0; count
< 20; count
++) {
85 /* set the time to 2 seconds before the leap */
86 tv
.tv_sec
= next_leap
- 2;
88 if (settimeofday(&tv
, NULL
)) {
89 printf("Error: You're likely not running with proper (ie: root) permissions\n");
90 return ksft_exit_fail();
95 /* hammer on adjtime w/ STA_INS */
96 while (tx
.time
.tv_sec
< next_leap
+ 1) {
97 /* Set the leap second insert flag */
98 tx
.modes
= ADJ_STATUS
;
107 return ksft_exit_pass();