]> git.hungrycats.org Git - linux/commitdiff
[PATCH] sys_alarm() return value fix
authorAndrew Morton <akpm@osdl.org>
Mon, 1 Mar 2004 15:04:56 +0000 (07:04 -0800)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Mon, 1 Mar 2004 15:04:56 +0000 (07:04 -0800)
From: Kurt Garloff <garloff@suse.de>

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 =3D=3D 1000, there would not need to be rounding
error IMVHO, but they even occur there.  On HZ=3D1024 platforms, they may
even be unavoidable.

Attached patch fixes the return value of alarm().

kernel/timer.c

index 51df7364331c144ebc8e3b198505af6c2a89257a..f88763c4d820400674ac3390b067b14c56d7b880 100644 (file)
@@ -868,7 +868,7 @@ asmlinkage unsigned long sys_alarm(unsigned int seconds)
        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;
 }