ahm... don't do this.
you only shorten the race.
If you must do this, Alan Cox sent a much better (and
correct solution) to this list that went something like
void handler(int sig)
{
siglongjump(stuff);
}
...
signal(SIGALRM, handler);
if (setlongjump(stuff))
return TIMEOUT;
alarm(timeout);
status=read(fd, buffer, len);
alarm(0);
................
There is still a race, but now it is between the return
from the read and the alarm(0), which may cause a false
error. You might be able to avoid it, but I don't know how.
... btw, the code fragment above is from memory, and almost
certainly misuses functions, but the idea should be right.
(use the man pages)
This should be in a faq somewhere...
-gordo