~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/timers/leapcrash.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/timers/leapcrash.c (Version linux-6.12-rc7) and /tools/testing/selftests/timers/leapcrash.c (Version linux-4.19.323)


  1 /* Demo leapsecond deadlock                         1 /* Demo leapsecond deadlock
  2  *              by: John Stultz (john.stultz@l      2  *              by: John Stultz (john.stultz@linaro.org)
  3  *              (C) Copyright IBM 2012              3  *              (C) Copyright IBM 2012
  4  *              (C) Copyright 2013, 2015 Linar      4  *              (C) Copyright 2013, 2015 Linaro Limited
  5  *              Licensed under the GPL              5  *              Licensed under the GPL
  6  *                                                  6  *
  7  * This test demonstrates leapsecond deadlock  !!   7  * This test demonstrates leapsecond deadlock that is possibe
  8  * on kernels from 2.6.26 to 3.3.                   8  * on kernels from 2.6.26 to 3.3.
  9  *                                                  9  *
 10  * WARNING: THIS WILL LIKELY HARD HANG SYSTEMS !!  10  * WARNING: THIS WILL LIKELY HARDHANG SYSTEMS AND MAY LOSE DATA
 11  * RUN AT YOUR OWN RISK!                           11  * RUN AT YOUR OWN RISK!
 12  *  To build:                                      12  *  To build:
 13  *      $ gcc leapcrash.c -o leapcrash -lrt        13  *      $ gcc leapcrash.c -o leapcrash -lrt
 14  */                                                14  */
 15                                                    15 
 16                                                    16 
 17                                                    17 
 18 #include <stdio.h>                                 18 #include <stdio.h>
 19 #include <stdlib.h>                                19 #include <stdlib.h>
 20 #include <time.h>                                  20 #include <time.h>
 21 #include <sys/time.h>                              21 #include <sys/time.h>
 22 #include <sys/timex.h>                             22 #include <sys/timex.h>
 23 #include <string.h>                                23 #include <string.h>
 24 #include <signal.h>                                24 #include <signal.h>
 25 #include "../kselftest.h"                          25 #include "../kselftest.h"
 26                                                    26 
 27 /* clear NTP time_status & time_state */           27 /* clear NTP time_status & time_state */
 28 int clear_time_state(void)                         28 int clear_time_state(void)
 29 {                                                  29 {
 30         struct timex tx;                           30         struct timex tx;
 31         int ret;                                   31         int ret;
 32                                                    32 
 33         /*                                         33         /*
 34          * We have to call adjtime twice here,     34          * We have to call adjtime twice here, as kernels
 35          * prior to 6b1859dba01c7 (included in     35          * prior to 6b1859dba01c7 (included in 3.5 and
 36          * -stable), had an issue with the sta     36          * -stable), had an issue with the state machine
 37          * and wouldn't clear the STA_INS/DEL      37          * and wouldn't clear the STA_INS/DEL flag directly.
 38          */                                        38          */
 39         tx.modes = ADJ_STATUS;                     39         tx.modes = ADJ_STATUS;
 40         tx.status = STA_PLL;                       40         tx.status = STA_PLL;
 41         ret = adjtimex(&tx);                       41         ret = adjtimex(&tx);
 42                                                    42 
 43         tx.modes = ADJ_STATUS;                     43         tx.modes = ADJ_STATUS;
 44         tx.status = 0;                             44         tx.status = 0;
 45         ret = adjtimex(&tx);                       45         ret = adjtimex(&tx);
 46                                                    46 
 47         return ret;                                47         return ret;
 48 }                                                  48 }
 49                                                    49 
 50 /* Make sure we cleanup on ctrl-c */               50 /* Make sure we cleanup on ctrl-c */
 51 void handler(int unused)                           51 void handler(int unused)
 52 {                                                  52 {
 53         clear_time_state();                        53         clear_time_state();
 54         exit(0);                                   54         exit(0);
 55 }                                                  55 }
 56                                                    56 
 57                                                    57 
 58 int main(void)                                     58 int main(void)
 59 {                                                  59 {
 60         struct timex tx;                           60         struct timex tx;
 61         struct timespec ts;                        61         struct timespec ts;
 62         time_t next_leap;                          62         time_t next_leap;
 63         int count = 0;                             63         int count = 0;
 64                                                    64 
 65         setbuf(stdout, NULL);                      65         setbuf(stdout, NULL);
 66                                                    66 
 67         signal(SIGINT, handler);                   67         signal(SIGINT, handler);
 68         signal(SIGKILL, handler);                  68         signal(SIGKILL, handler);
 69         printf("This runs for a few minutes. P     69         printf("This runs for a few minutes. Press ctrl-c to stop\n");
 70                                                    70 
 71         clear_time_state();                        71         clear_time_state();
 72                                                    72 
 73                                                    73 
 74         /* Get the current time */                 74         /* Get the current time */
 75         clock_gettime(CLOCK_REALTIME, &ts);        75         clock_gettime(CLOCK_REALTIME, &ts);
 76                                                    76 
 77         /* Calculate the next possible leap se     77         /* Calculate the next possible leap second 23:59:60 GMT */
 78         next_leap = ts.tv_sec;                     78         next_leap = ts.tv_sec;
 79         next_leap += 86400 - (next_leap % 8640     79         next_leap += 86400 - (next_leap % 86400);
 80                                                    80 
 81         for (count = 0; count < 20; count++) {     81         for (count = 0; count < 20; count++) {
 82                 struct timeval tv;                 82                 struct timeval tv;
 83                                                    83 
 84                                                    84 
 85                 /* set the time to 2 seconds b     85                 /* set the time to 2 seconds before the leap */
 86                 tv.tv_sec = next_leap - 2;         86                 tv.tv_sec = next_leap - 2;
 87                 tv.tv_usec = 0;                    87                 tv.tv_usec = 0;
 88                 if (settimeofday(&tv, NULL)) {     88                 if (settimeofday(&tv, NULL)) {
 89                         printf("Error: You're      89                         printf("Error: You're likely not running with proper (ie: root) permissions\n");
 90                         ksft_exit_fail();      !!  90                         return ksft_exit_fail();
 91                 }                                  91                 }
 92                 tx.modes = 0;                      92                 tx.modes = 0;
 93                 adjtimex(&tx);                     93                 adjtimex(&tx);
 94                                                    94 
 95                 /* hammer on adjtime w/ STA_IN     95                 /* hammer on adjtime w/ STA_INS */
 96                 while (tx.time.tv_sec < next_l     96                 while (tx.time.tv_sec < next_leap + 1) {
 97                         /* Set the leap second     97                         /* Set the leap second insert flag */
 98                         tx.modes = ADJ_STATUS;     98                         tx.modes = ADJ_STATUS;
 99                         tx.status = STA_INS;       99                         tx.status = STA_INS;
100                         adjtimex(&tx);            100                         adjtimex(&tx);
101                 }                                 101                 }
102                 clear_time_state();               102                 clear_time_state();
103                 printf(".");                      103                 printf(".");
104                 fflush(stdout);                   104                 fflush(stdout);
105         }                                         105         }
106         printf("[OK]\n");                         106         printf("[OK]\n");
107         ksft_exit_pass();                      !! 107         return ksft_exit_pass();
108 }                                                 108 }
109                                                   109 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php