Commit 51a16c1e authored by John Stultz's avatar John Stultz Committed by Thomas Gleixner

selftest: Timers: Avoid signal deadlock in leap-a-day

In 0c4a5fc9 (Add leap-second timer edge testing to
leap-a-day.c), we added a timer to the test which checks to make
sure timers near the leapsecond edge behave correctly.

However, the output generated from the timer uses ctime_r, which
isn't async-signal safe, and should that signal land while the
main test is using ctime_r to print its output, its possible for
the test to deadlock on glibc internal locks.

Thus this patch reworks the output to avoid using ctime_r in
the signal handler.
Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1434565003-3386-1-git-send-email-john.stultz@linaro.orgSigned-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 906c5557
...@@ -141,27 +141,28 @@ void handler(int unused) ...@@ -141,27 +141,28 @@ void handler(int unused)
void sigalarm(int signo) void sigalarm(int signo)
{ {
struct timex tx; struct timex tx;
char buf[26];
int ret; int ret;
tx.modes = 0; tx.modes = 0;
ret = adjtimex(&tx); ret = adjtimex(&tx);
ctime_r(&tx.time.tv_sec, buf); if (tx.time.tv_sec < next_leap) {
buf[strlen(buf)-1] = 0; /*remove trailing\n */ printf("Error: Early timer expiration! (Should be %ld)\n", next_leap);
printf("%s + %6ld us (%i)\t%s - TIMER FIRED\n", error_found = 1;
buf, printf("adjtimex: %10ld sec + %6ld us (%i)\t%s\n",
tx.time.tv_sec,
tx.time.tv_usec, tx.time.tv_usec,
tx.tai, tx.tai,
time_state_str(ret)); time_state_str(ret));
if (tx.time.tv_sec < next_leap) {
printf("Error: Early timer expiration!\n");
error_found = 1;
} }
if (ret != TIME_WAIT) { if (ret != TIME_WAIT) {
printf("Error: Incorrect NTP state?\n"); printf("Error: Timer seeing incorrect NTP state? (Should be TIME_WAIT)\n");
error_found = 1; error_found = 1;
printf("adjtimex: %10ld sec + %6ld us (%i)\t%s\n",
tx.time.tv_sec,
tx.time.tv_usec,
tx.tai,
time_state_str(ret));
} }
} }
...@@ -297,7 +298,7 @@ int main(int argc, char **argv) ...@@ -297,7 +298,7 @@ int main(int argc, char **argv)
printf("Scheduling leap second for %s", ctime(&next_leap)); printf("Scheduling leap second for %s", ctime(&next_leap));
/* Set up timer */ /* Set up timer */
printf("Setting timer for %s", ctime(&next_leap)); printf("Setting timer for %ld - %s", next_leap, ctime(&next_leap));
memset(&se, 0, sizeof(se)); memset(&se, 0, sizeof(se));
se.sigev_notify = SIGEV_SIGNAL; se.sigev_notify = SIGEV_SIGNAL;
se.sigev_signo = signum; se.sigev_signo = signum;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment