qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Stuart Brady <stuart.brady@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] suppress 'warn_unused_result' warning
Date: Mon, 11 May 2009 18:02:59 +0100	[thread overview]
Message-ID: <20090511170259.GA1422@shareable.org> (raw)
In-Reply-To: <20090511154226.GA29818@miranda.arrow>

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

  parent reply	other threads:[~2009-05-11 17:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-10 19:15 [Qemu-devel] [PATCH] suppress 'warn_unused_result' warning Chih-Min Chao
2009-05-10 22:11 ` Paul Brook
2009-05-10 22:15 ` Stuart Brady
2009-05-10 23:19   ` Anthony Liguori
2009-05-11  1:53   ` M. Warner Losh
2009-05-11 15:42     ` Stuart Brady
2009-05-11 16:02       ` Paul Brook
2009-05-11 16:16       ` Anthony Liguori
2009-05-11 16:25         ` Daniel P. Berrange
2009-05-11 16:57           ` Anthony Liguori
2009-05-12 12:19             ` Jamie Lokier
2009-05-11 17:02       ` Jamie Lokier [this message]
2009-05-11 16:15 ` Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090511170259.GA1422@shareable.org \
    --to=jamie@shareable.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stuart.brady@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).