[PATCH] clock_nanosleep interrupt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Subject: Avoid segfault of cyclictest if it gets immediately interrupted.

From: Daniel Gollub <dgollub@xxxxxxx>

If clock_nanosleep() gets interrupted this could result in a negative
time diff from calcdiff().

With the histogram patch this leads to a segfault, since the time diff
is used as index for the histogram array:

Core was generated by `/usr/bin/cyclictest -n -q -p 99 -t 2 -i 500 -l
1000000 -h
 20000'.
 Program terminated with signal 11, Segmentation fault.
#0  0x0000000000402324 in timerthread (param=<value optimized out>)
     at src/cyclictest/cyclictest.c:339
     339                             stat->hist_array[diff] += 1;
     (gdb) p diff
     $1 = -751974

Signed-off-by: Daniel Gollub <dgollub@xxxxxxx>
Acked-by: Sven-Thorsten Dietrich <sdietrich@xxxxxxx>
---
 src/cyclictest/cyclictest.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Index: rt-tests/src/cyclictest/cyclictest.c
===================================================================
--- rt-tests.orig/src/cyclictest/cyclictest.c
+++ rt-tests/src/cyclictest/cyclictest.c
@@ -376,7 +376,7 @@ void *timerthread(void *param)
 	while (!shutdown) {
 
 		long diff;
-		int sigs;
+		int sigs, ret;
 
 		/* Wait for next period */
 		switch (par->mode) {
@@ -387,17 +387,24 @@ void *timerthread(void *param)
 			break;
 
 		case MODE_CLOCK_NANOSLEEP:
-			if (par->timermode == TIMER_ABSTIME)
-				clock_nanosleep(par->clock, TIMER_ABSTIME,
+			if (par->timermode == TIMER_ABSTIME) {
+				ret = clock_nanosleep(par->clock, TIMER_ABSTIME,
 						&next, NULL);
-			else {
+			} else {
 				clock_gettime(par->clock, &now);
-				clock_nanosleep(par->clock, TIMER_RELTIME,
+				ret = clock_nanosleep(par->clock, TIMER_RELTIME,
 						&interval, NULL);
 				next.tv_sec = now.tv_sec + interval.tv_sec;
 				next.tv_nsec = now.tv_nsec + interval.tv_nsec;
 				tsnorm(&next);
 			}
+
+			/* Avoid negative calcdiff result if clock_nanosleep() 
+			 * gets interrupted.
+			 */
+			if (ret == EINTR)
+				goto out;
+
 			break;
 
 		case MODE_SYS_NANOSLEEP:


--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux