From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vfutr-0001sL-Hg for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:03:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vfutm-00013V-L3 for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:03:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39138) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vfutm-00013E-Bq for qemu-devel@nongnu.org; Mon, 11 Nov 2013 12:03:38 -0500 Message-ID: <52810DE6.7030400@redhat.com> Date: Mon, 11 Nov 2013 10:03:34 -0700 From: Eric Blake MIME-Version: 1.0 References: <52810AEA.5020806@redhat.com> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RWkLhG0JOGofShH7ENCO0Xw8mIxFm03na" Subject: Re: [Qemu-devel] audit needed for signal handlers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: "qemu-devel@nongnu.org" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --RWkLhG0JOGofShH7ENCO0Xw8mIxFm03na Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 handl= er >> MUST restore the value of errno before returning, if it is to guarante= e >> that the interrupted context won't be corrupted. >=20 > 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=3D=3DEINTR 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --RWkLhG0JOGofShH7ENCO0Xw8mIxFm03na Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSgQ3mAAoJEKeha0olJ0NqOJ4H/AufkB6sr+hyGLExE7WNt4U8 P9OwfKCtdmcl/s0xja7rKzhmyRmsuHxAFNGgDKuS0+miJQIxQeL+ZI1JtnFifnf4 BNyJkPvPVOqz/oSdZSf8jaQuL9SHEFuJXFawyZy6UvVOqs3iSA/NmA95fmsHmLv5 UNKhpEhpFXI2BCcUPowqntI4OOW/xqmMd9WFcq6mEW9QtOlg1hgZlG2kw9SJLEp0 eLE2Ui1SwZO3WYv0iZUwqeEez9QbsCWrrDtvYm6lRWB9G1sG131TctW8mOk1EnuL B99Q14xQx3Bxh9Y8nWQ0r0sI2c4cqHkSlVpUt/rQjwwULn5vAjEDe5t+ooHAJjg= =5648 -----END PGP SIGNATURE----- --RWkLhG0JOGofShH7ENCO0Xw8mIxFm03na--