From: Eric Blake <eblake@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] audit needed for signal handlers
Date: Mon, 11 Nov 2013 10:03:34 -0700 [thread overview]
Message-ID: <52810DE6.7030400@redhat.com> (raw)
In-Reply-To: <CA+aC4kugrRczy5X=c797_YikXsNqCuruM2NaVfNeN-n6Oidnkg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1244 bytes --]
On 11/11/2013 09:56 AM, Anthony Liguori wrote:
>> Here's a hint: ioctl() can clobber errno. But if a signal handler is
>> called in the middle of other code that is using errno, then the handler
>> MUST restore the value of errno before returning, if it is to guarantee
>> that the interrupted context won't be corrupted.
>
> Isn't this precisely why EINTR exists?
That's part of the equation, but not everything. EINTR exists for a
system call that was cut short by the delivery of a signal; if you check
for errno==EINTR after a call that is documented to support it (such as
write() or poll()), then you know that the call was interrupted; use of
SA_RESTART with sigaction() can also control whether you will even see
EINTR in the first place for some functions.
But consider what happens when the system call completes normally, and
the signal handler then gets invoked in between the syscall completion
and the later code that checks the value of errno. There, errno will
NOT be EINTR, and it is vital that the signal handler not corrupt errno
prior to returning control to normal execution context.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
next prev parent reply other threads:[~2013-11-11 17:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-11 16:50 [Qemu-devel] audit needed for signal handlers Eric Blake
2013-11-11 16:56 ` Anthony Liguori
2013-11-11 17:03 ` Eric Blake [this message]
2013-11-11 17:05 ` Paolo Bonzini
2013-11-11 17:08 ` Eric Blake
2013-11-11 17:11 ` Paolo Bonzini
2013-11-11 17:13 ` Peter Maydell
2013-11-11 17:22 ` Eric Blake
2013-11-11 17:47 ` Paolo Bonzini
2013-11-12 8:18 ` Gerd Hoffmann
2013-11-12 12:07 ` Laszlo Ersek
2013-11-11 17:11 ` Peter Maydell
2013-11-11 18:03 ` Max Filippov
2013-11-12 12:24 ` Laszlo Ersek
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=52810DE6.7030400@redhat.com \
--to=eblake@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.org \
/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).