sys_alarm() return value

From: Kurt Garloff
Date: Fri Feb 27 2004 - 08:11:02 EST


Hi,

when calling

alarm(1); alarm(0);

the second alarm can wrongly return 2. This makes an LSB test fail.

It happens due to rounding errors in the timeval to jiffie conversion
and back. On i386 with HZ == 1000, there would not need to be rounding
error IMVHO, but they even occur there. On HZ=1024 platforms, they may
even be unavoidable.

Attached patch fixes the return value of alarm().
Please consider applying.

Regards,
--
Kurt Garloff <garloff@xxxxxxx> Cologne, DE
SUSE LINUX AG, Nuernberg, DE SUSE Labs (Head)
--- linux-2.6.2.x86/kernel/timer.c.orig 2004-02-04 04:44:25.000000000 +0100
+++ linux-2.6.2.x86/kernel/timer.c 2004-02-27 11:11:57.458593978 +0100
@@ -868,7 +868,7 @@
oldalarm = it_old.it_value.tv_sec;
/* ehhh.. We can't return 0 if we have an alarm pending.. */
/* And we'd better return too much than too little anyway */
- if (it_old.it_value.tv_usec)
+ if ((!oldalarm && it_old.it_value.tv_usec) || it_old.it_value.tv_usec >= 500000)
oldalarm++;
return oldalarm;
}

Attachment: pgp00000.pgp
Description: PGP signature