From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M3YuI-0003XO-Eh for qemu-devel@nongnu.org; Mon, 11 May 2009 13:03:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M3YuD-0003SQ-SK for qemu-devel@nongnu.org; Mon, 11 May 2009 13:03:13 -0400 Received: from [199.232.76.173] (port=42955 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M3YuD-0003S8-Gd for qemu-devel@nongnu.org; Mon, 11 May 2009 13:03:09 -0400 Received: from mail2.shareable.org ([80.68.89.115]:50572) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M3YuC-0007gS-Uc for qemu-devel@nongnu.org; Mon, 11 May 2009 13:03:09 -0400 Date: Mon, 11 May 2009 18:02:59 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] suppress 'warn_unused_result' warning Message-ID: <20090511170259.GA1422@shareable.org> References: <20090510221500.GA27879@miranda.arrow> <20090510.195335.-1303462317.imp@bsdimp.com> <20090511154226.GA29818@miranda.arrow> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090511154226.GA29818@miranda.arrow> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stuart Brady Cc: qemu-devel@nongnu.org Stuart Brady wrote: > On Sun, May 10, 2009 at 07:53:35PM -0600, M. Warner Losh wrote: > > When a signal is received and you are waiting for data, you get > > EINTR. If there's data available, then I believe the behavior is to > > return that data and not EINTR. That's the way Unix works. > > So if I do a read() from a file over NFS, and there's an awful lot of > latency (and perhaps even connection problems), and the process gets a > signal -- does that mean that the signal will only be delivered once > data is returned? With NFS, if it's mounted "hard" it behaves like reading from a local disk and returns exactly the number of bytes requested (unless it reaches the end of file), and never returns EINTR. If it's mounted "soft", it can return EINTR and does not have to wait for data to be received. But if it _already_ has some data when the signal happens, it will return the amount of data it has already. EINTR is not rare if you do a blocknig read from a pipe or socket, and then receive a signal. It returns EINTR every time :-) > If not, then I would really start to wonder whether /all/ code dealing > with read(), write(), etc. should be written to cope with EINTR (and > also partial reads/writes?) regardless of whatever is done with threads > and signal masks, as doing otherwise seems only to be asking for trouble > at some point. (I'd be especially concerned about signals intended for > libraries that are not under the developer's control...) In some cases it's easier to set SA_RESTART when setting the signal handler. See "man 7 signal" and restarting signals - it has a good explanation of when EINTR is received, when you can disable it, and which systems calls you can't disable it for. Of course signal handlers set by library code might not set that flag, which is why it's usually not a good idea to rely on it.n To be more thorough, do all I/O in thread swhich never receives signals (except stop/kill). This is achieved by pthread_sigmask() to block all signals on those threads. Make sure no libraries unmask them! -- Jamie