From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StRSO-00041j-5j for qemu-devel@nongnu.org; Mon, 23 Jul 2012 18:50:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StRSM-0007fi-Vw for qemu-devel@nongnu.org; Mon, 23 Jul 2012 18:50:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StRSM-0007fc-Na for qemu-devel@nongnu.org; Mon, 23 Jul 2012 18:50:26 -0400 Message-ID: <500DD522.3060303@redhat.com> Date: Mon, 23 Jul 2012 16:50:10 -0600 From: Eric Blake MIME-Version: 1.0 References: <1343048885-1701-1-git-send-email-coreyb@linux.vnet.ibm.com> <1343048885-1701-2-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1343048885-1701-2-git-send-email-coreyb@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig54E65CAF4052A9694DF54000" Subject: Re: [Qemu-devel] [PATCH v5 1/6] qemu-char: Add MSG_CMSG_CLOEXEC flag to recvmsg List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, qemu-devel@nongnu.org, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig54E65CAF4052A9694DF54000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 07/23/2012 07:08 AM, Corey Bryant wrote: > Set the close-on-exec flag for the file descriptor received > via SCM_RIGHTS. >=20 > +++ b/qemu-char.c > @@ -2263,9 +2263,17 @@ static ssize_t tcp_chr_recv(CharDriverState *chr= , char *buf, size_t len) > msg.msg_control =3D &msg_control; > msg.msg_controllen =3D sizeof(msg_control); > =20 > +#ifdef MSG_CMSG_CLOEXEC > + ret =3D recvmsg(s->fd, &msg, MSG_CMSG_CLOEXEC); > +#else > ret =3D recvmsg(s->fd, &msg, 0); > - if (ret > 0 && s->is_unix) > + if (ret > 0) { > + qemu_set_cloexec(s->fd); Wrong fd. You aren't changing cloexec on the socket (s->fd), but on the fd that was received via msg (which you don't know at this point in time)= =2E > + } > +#endif > + if (ret > 0 && s->is_unix) { > unix_process_msgfd(chr, &msg); Only here do you know what fd you received. I would write it more like: int flags =3D 0; #ifdef MSG_CMSG_CLOEXEC flags |=3D MSG_CMSG_CLOEXEC #endif ret =3D recvmsg(s->fd, &msg, flags); if (ret > 0 && s->is_unix) { unix_process_msgfd(chr, &msg); #ifndef MSG_CMSG_CLOEXEC qemu_set_cloexec(/* fd determined from msg */) #endif } which almost implies that unix_process_msgfd() should be the function that sets cloexec, but without wasting the time doing so if recvmsg already did the job. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig54E65CAF4052A9694DF54000 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://enigmail.mozdev.org/ iQEcBAEBCAAGBQJQDdUmAAoJEKeha0olJ0NqjuUH/RC8n+28+5P/PhTULy6yrCBS oY075JMr/bHSqEq/wl9oLg+jt0bZ+hBtgGmzhRTgc63UdRz8A8OBuMfvqy2b0nLv HHVR2GLqoffY/d+d4MLPuiwWXW6jmjRmh6NuXyMB57FKI6OyiUYdBJUgdiZO2GbY beVAuG8KDBuyuN+Jgq170hMeaHxMe3WviWVxuEsL+PiEzv4phOdaPgS0tXL9YtuB nCeY1ZBiXgL89LhZdVtWbQAze2jd5RhkcuGLyw7IwLWVmsB7fTrhGNqF6lvuPill jay7loC7ntxksxAr3cfrjkyXiS/ljkFar4duq6NG4m3JTLeD/GvIdP6voSkF5O4= =Bdps -----END PGP SIGNATURE----- --------------enig54E65CAF4052A9694DF54000--