alarm() bug in 4.2

jeff at voder.UUCP jeff at voder.UUCP
Tue Jul 10 14:05:50 AEST 1984


There is a bug in the 4.2 implementation of alarm(3).  In the following

	oldalarm = alarm(newalarm);

oldalarm gets the current value of the interval timer *rounded down*
to the nearest second.  So ...

	for (...) {
		oldalarm = alarm((unsigned) 0);
		...
		alarm(oldalarm);	
	}

causes the interval timer to be *repeatedly* rounded down.  End
result: the alarm goes off early.  And, of course, if the interval
timer just *happened* to be at some value *less* than a second the
alarm will be turned off completely.

Fortunately, there is an easy workaround; change the previous code
to read:

	for (...) {
		oldmask = sigblock(1<<SIGALRM);
		...
		sigblock(oldmask);
	}

The fix to alarm() is left as an exercise to the interested reader.

Jeff Gilliam

No pain, no gain ...	*sigh*



More information about the Comp.bugs.4bsd.ucb-fixes mailing list