qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] audit needed for signal handlers


From: Eric Blake
Subject: Re: [Qemu-devel] audit needed for signal handlers
Date: Mon, 11 Nov 2013 10:03:34 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

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: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]