Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!math.fu-berlin.de!opal!unido!mcshh!abqhh!tpki!oski!schlut From: schlut@oski.toppoint.de (Olaf Schlueter) Newsgroups: comp.os.minix Subject: Re: Vi and alarm. Message-ID: <79@oski.toppoint.de> Date: 23 Mar 91 13:33:24 GMT References: <2996@redstar.cs.qmw.ac.uk> Organization: Toppoint Mailbox Lines: 55 zawada@cs.qmw.ac.uk (Simpson) writes: > Does it gets hate me, or is there really something in it? > > Whenever I run elvis or vi, after a while, I get the message > > Alarm clock...... > > Vi aborts, and mucks up the tty! > Vi, as many other unix programms, does the usual version 7 unix trick for non-blocking read, which is: wind up the alarm-clock, call read, which returns either one or more chars or EOF, if the alarm call happens during the call. If read is not aborted by the alarm clock, an alarm(0) should stop the clock, but there is a bug in Minix, so this fails. I discovered this on MINIX 1.5 ST, as distributed by PH, when I was programming an uucico. I got around this bug without fixing the kernel by setting a SIGALRM interrupt handler dummy routine (which does nothing) whenever I used alarm for non-blocking IO. You cannot avoid the alarm signal but this way you can prevent it from stopping your program. The other feature of alarm, that another alarm-call with a value > 0 resets the alarm clock to the new value, works. You can watch the bug working in: #include int donothing() {signal(SIGALRM,donothing);} int main() { char c; int n; #ifdef FOOL_THE_BUG signalSIGALRM,donothing); #endif do { alarm(1); n = read (1,&c,1); alarm(0) } while( n > 0); } run this program and hold the "a" key pressed. In normal v7 Unix that programm will stop within a second after releasing "a". In Minix the program runs 1 second, whether you press "a" or not. (I keyed that program in from my long-term memory, it has been a couple of months since I used it to verify the bug - so there maybe a mistake in it.) -- Olaf Schlueter, Sandkuhle 4-6, 2300 Kiel 1, FRG, schlut@oski.toppoint.de "Someone is always the evil in the land, and then the good guys are marching, the eyes full of sand, into a holy war." Konstantin Wecker