Andreas Jaeger <aj(a)suse.de> writes:
The problem seems to be sysdeps/generic/utmp_file.c. We try to lock
the utmp file and save/restore the alarm values (we don't mess around
with the values - but if XEmacs overwrites alarm...). That's AFAIK
(besides sleep) the only place where glibc uses alarm.
This is typical usage, i.e.
old_timeout = alarm(0);
push new SIGALARM handler
alarm(our_time);
/* do your thing */
alarm(0);
pop SIGALARM handler
alarm(old_timeout);
The reason XEmacs overrides the alarm() functions is exactly to detect
stuff like this because it is often wrong
urysohn:/tmp> gcc testlarm.c [1]
urysohn:/tmp> ./a.out
value from alarm() was : 1
Restored to: 1.000000 s , should be 0.000500 s
Repeat to: 0.000000 s , should be 0.000700 s
So IMO this is a bug in glibc (should I file one?)
1. This really is a wart in the Unix API. The above code is only
correct if our_time << old_timeout (because it doesn't check for
the fact that the real timer could very well have expired. For that
reason it would be really nice if glibc would refrain from messing with
the timers, especially in stuff like get_login() where it is not
obvious.
2. If it really wants to mess with the timer (Don't the posix realtime
extensions now offer independent timers?), it should do so using
getitimer/setitimer because that doesn't loose precision and repeat
values.
Jan
Footnotes:
[1]
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main (int argc, char *argv[])
{
struct itimerval mydelay = {{0, 700} , {0,500}}; /* 500 msec, repeat 700 */
struct itimerval newdelay;
int inseconds;
if (setitimer(ITIMER_REAL,&mydelay,NULL))
{
perror("setimer: ");
exit(1);
}
inseconds = alarm(0);
alarm(inseconds);
getitimer(ITIMER_REAL,&newdelay);
alarm(0);
printf("value from alarm() was : %i\n",inseconds);
printf("Restored to: %li.%6.6li s , should be %li.%6.6li s\n",
newdelay.it_value.tv_sec, newdelay.it_value.tv_usec,
mydelay.it_value.tv_sec, mydelay.it_value.tv_usec);
printf("Repeat to: %li.%6.6li s , should be %li.%6.6li s\n",
newdelay.it_interval.tv_sec, newdelay.it_interval.tv_usec,
mydelay.it_interval.tv_sec, mydelay.it_interval.tv_usec);
}
--
Jan Vroonhof
http://www.math.ethz.ch/~vroonhof/
Mathematik, vroonhof @ math.ethz.ch
HG E16, ETH-Zentrum, Tel: +41-1-6325456/25154
Raemistrasse 101, CH-8092 Zuerich. Fax: +41-1-6321085