Re: interesting behavior.. this right ?

Alan Cox (alan@lxorguk.ukuu.org.uk)
Sun, 13 Apr 1997 14:55:46 +0100 (BST)


> > printf("connecting...\n");
>
> signal(SIGALRM, dummy);
> alarm(5);
> >
> > if (connect(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) < 0)
> > perror("connect");
>
> These modifications will get you out of any system call. If the connection
> failed, the errno will be "interrupted system call", when tha alarm clock

These modifications don't work. This is the prehistoric V7 sleep bug. You
have no guarantee that the alarm will not go off before connect() is called.
At that point you lose. Instead you need to do something more like this

void foo_func()
{
siglongjmp(...)
}

and ..

if(sigsetjmp(....))
return TIMEOUT;
signal(SIGALRM, foo_func);
alarm(5);
if(connect(...