From owner-freebsd-hackers Sun Oct 10 21:16:27 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id E384514E74 for ; Sun, 10 Oct 1999 21:16:25 -0700 (PDT) (envelope-from bright@wintelcom.net) Received: from localhost (bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) with ESMTP id VAA25690; Sun, 10 Oct 1999 21:36:05 -0700 (PDT) Date: Sun, 10 Oct 1999 21:36:05 -0700 (PDT) From: Alfred Perlstein To: Zhihui Zhang Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: How to prevent a system call from restart? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sun, 10 Oct 1999, Zhihui Zhang wrote: > > I modify the day time client program from the Stevens' book and run it on > both a Sun workstation and a FreeBSD machine. In the program, I use > signal() and alarm() to set a 5 seconds timeout. The program works as > expected on Sun (after I comment out the daytime line in the file > /etc/inetd.conf) but not on the FreeBSD machine. > > Later I find out that the reason maybe the recvfrom() restarts > *automatically* in FreeBSD. Why the default behaviour is different from > SunOS? If I am correct about the reason, can anyone tell me how to prevent > the recvfrom() from restart after receiving the SIGALRM signal? > > By the way, I also try the socket timeout option. It works immediately. > > Any help is appreciated. from sigaction's manpage: If a signal is caught during the system calls listed below, the call may be forced to terminate with the error EINTR, the call may return with a data transfer shorter than requested, or the call may be restarted. Restart of pending calls is requested by setting the SA_RESTART bit in sa_flags. The affected system calls include open(2), read(2), write(2), sendto(2), recvfrom(2), sendmsg(2) and recvmsg(2) on a communications channel or a slow device (such as a terminal, but not a regular file) and during a wait(2) or ioctl(2). However, calls that have already committed are not restarted, but instead return a partial success (for example, a short read count). you want to turn off SA_RESTART. -Alfred Perlstein - [bright@rush.net|alfred@freebsd.org] Wintelcom systems administrator and programmer - http://www.wintelcom.net/ [bright@wintelcom.net] To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message