From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOyJe-0007yL-IJ for qemu-devel@nongnu.org; Thu, 18 Oct 2012 18:11:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOyJd-0008Jd-Bq for qemu-devel@nongnu.org; Thu, 18 Oct 2012 18:11:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52014) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOyJd-0008JP-0s for qemu-devel@nongnu.org; Thu, 18 Oct 2012 18:11:45 -0400 Message-ID: <50807E33.3080905@redhat.com> Date: Thu, 18 Oct 2012 16:09:55 -0600 From: Eric Blake MIME-Version: 1.0 References: <1350587974-6378-1-git-send-email-coreyb@linux.vnet.ibm.com> <1350587974-6378-5-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1350587974-6378-5-git-send-email-coreyb@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigC7843078B132D5BF8C257940" Subject: Re: [Qemu-devel] [PATCH v4 4/4] qemu-config: Add new -add-fd command line option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, libvir-list@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC7843078B132D5BF8C257940 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 10/18/2012 01:19 PM, Corey Bryant wrote: > This option can be used for passing file descriptors on the > command line. It mirrors the existing add-fd QMP command which > allows an fd to be passed to QEMU via SCM_RIGHTS and added to an > fd set. >=20 > + > +static int cleanup_add_fd(QemuOpts *opts, void *opaque) > +{ > + int fd; > + > + fd =3D qemu_opt_get_number(opts, "fd", -1); > + close(fd); One other subtle point: Given 'qemu-kvm -add-fd fd=3D3,set=3D1 -add-fd fd=3D3,set=3D2', this code will call close(3) twice. In a single-threade= d scenario, we happen to be safe (because we merely ignore that the second one fails with EBADF), but in a multi-threaded scenario, it is a recipe for disaster with a chance for closing an fd opened by another thread. > @@ -3320,6 +3390,14 @@ int main(int argc, char **argv, char **envp) > exit(1); > } > =20 > + if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL= , 1)) { > + exit(1); > + } > + > + if (qemu_opts_foreach(qemu_find_opts("add-fd"), cleanup_add_fd, NU= LL, 1)) { > + exit(1); > + } Thankfully, we only ever call that code in main(), prior to spawning threads. So my positive review still stands. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigC7843078B132D5BF8C257940 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.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iQEcBAEBCAAGBQJQgH4zAAoJEKeha0olJ0NqZwQH/06eVBS50PQj3G0sIvViA4fs 9+umUiqTpzmVAKNNtDpT6Blq1MM5YZPgtOgBKTlf0+KQymsDYc9GfyV0kWtXVTr+ 7LFPBnvwmmRA53O43Qce2rbYCJwkyxlMBSUNnV3egxp4lK/jBLx1ABx36WcMkSxc 4MAmptCYJD1HTcDzj2OmjFtODBK0ikDjz/coU2VxIs7KExEXV+aITJW48tLaoGGz tT2zN2nwLR6m9MTxt0+x2FaGvTCmsoWfOyypxGE72UiLcWTFZS8PCX+WUiZs08wu hG6eKY3ppX/cjM1lK6fw5hdUT74L1X/Q6v28rq13TE8CJJxBNmZC1eA/B9KalpM= =gUJz -----END PGP SIGNATURE----- --------------enigC7843078B132D5BF8C257940--