From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoIqv-0001GD-Ni for qemu-devel@nongnu.org; Mon, 19 Oct 2015 18:24:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoIqs-00021G-6P for qemu-devel@nongnu.org; Mon, 19 Oct 2015 18:24:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoIqr-00020y-Uz for qemu-devel@nongnu.org; Mon, 19 Oct 2015 18:24:22 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 3E8CEC1C4A06 for ; Mon, 19 Oct 2015 22:24:21 +0000 (UTC) References: <1444648509-29179-1-git-send-email-berrange@redhat.com> <1444648509-29179-6-git-send-email-berrange@redhat.com> From: Eric Blake Message-ID: <56256D94.7010101@redhat.com> Date: Mon, 19 Oct 2015 16:24:20 -0600 MIME-Version: 1.0 In-Reply-To: <1444648509-29179-6-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MoOisbdeK3GtvJEf3Agox5RHv2louVVcB" Subject: Re: [Qemu-devel] [PATCH v2 05/16] osdep: add qemu_fork() wrapper for safely handling signals List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Paolo Bonzini , "Dr. David Alan Gilbert" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --MoOisbdeK3GtvJEf3Agox5RHv2louVVcB Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/12/2015 05:14 AM, Daniel P. Berrange wrote: > When using regular fork() the child process of course inherits > all the parents' signal handlers. If the child then proceeds > to close() any open file descriptors, it may break some of those > registered signal handlers. The child generally does not want to > ever run any of the signal handlers tha parent may have installed s/tha/that the/ > in the short time before it exec's. The parent may also have blocked > various signals which the child process will want enabled. >=20 > This introduces a wrapper qemu_fork() that takes care to sanitize > signal handling across fork. Before forking it blocks all signals > in the parent thread. After fork returns, the parent unblocks the > signals and carries on as usual. The child, however, resets all the > signal handlers back to their defaults before it unblocks signals. > The child process can now exec the binary in a "clean" signal > environment. >=20 > Signed-off-by: Daniel P. Berrange > --- > include/qemu/osdep.h | 16 ++++++++++++ > util/oslib-posix.c | 71 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > util/oslib-win32.c | 9 +++++++ > 3 files changed, 96 insertions(+) Looks very similar to libvirt's fork() wrapper :) > + for (i =3D 1; i < NSIG; i++) { > + /* Only possible errors are EFAULT or EINVAL The former > + * won't happen, the latter we expect, so no need to check= > + * return value */ > + (void)sigaction(i, &sig_action, NULL); > + } Libvirt gets to rely on gnulib for a guaranteed definition of NSIG. But POSIX doesn't document it, and I'm not sure whether it is present on all platforms qemu targets. I guess we'll find out soon enough. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --MoOisbdeK3GtvJEf3Agox5RHv2louVVcB Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWJW2UAAoJEKeha0olJ0Nqa5EIAK9Ny5yL5SXFsom/pQ2dweCH AJaYcmwhkelj60jFWdHPbNsg3Mk1Hg6IATq0DLp9eUHWflcG6K6Wk8mk9ozbsces lR9ar2WkOFQ/ElvlpL2aflKkjT+BmPqj/DKjYe3wmvGq+/A7O7aZl9iJFlz1pPMx w15gFS9aviosO9MPfphQQ9NcZbUWFzcGXEj806G2XZhZIQCgc7zGBZM8UJKG6hXW BRsPqtbDdLAqmCFPtizj4TxqKFUBg9uZdt5AwBc2NfMdPz7hiJ1p4UVOOO7iNDM5 nSBVNxjS1YW7E4bX9QGaa07XmQxB+ytkh6IoGm3uRko6TFYnlm0i/aOkUOMC9UY= =zj5O -----END PGP SIGNATURE----- --MoOisbdeK3GtvJEf3Agox5RHv2louVVcB--