From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAUf4-0002eR-Jd for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:28:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAUez-0002dJ-W1 for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:28:26 -0500 Received: from [199.232.76.173] (port=59046 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAUez-0002dG-QA for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:28:21 -0500 Received: from mail-gx0-f223.google.com ([209.85.217.223]:39616) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAUez-0007Vu-E9 for qemu-devel@nongnu.org; Tue, 17 Nov 2009 15:28:21 -0500 Received: by gxk23 with SMTP id 23so485626gxk.2 for ; Tue, 17 Nov 2009 12:28:21 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <4B0268FF.105@redhat.com> References: <1258125436-23759-1-git-send-email-kwolf@redhat.com> <4B0149C8.7040203@redhat.com> <20091116230507.GG12063@shareable.org> <4B0268FF.105@redhat.com> From: Blue Swirl Date: Tue, 17 Nov 2009 22:28:00 +0200 Message-ID: Subject: Re: [Qemu-devel] [PATCH] Don't leak file descriptors Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Tue, Nov 17, 2009 at 11:12 AM, Kevin Wolf wrote: > Am 17.11.2009 00:05, schrieb Jamie Lokier: >> Blue Swirl wrote: >>> On Mon, Nov 16, 2009 at 2:47 PM, Kevin Wolf wrote: >>>> Am 13.11.2009 22:05, schrieb Blue Swirl: >>>>> On Fri, Nov 13, 2009 at 5:17 PM, Kevin Wolf wrote: >>>>>> We're leaking file descriptors to child processes. Set FD_CLOEXEC on= file >>>>>> descriptors that don't need to be passed to children to stop this mi= sbehaviour. >>>>> >>>>>> - =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D accept(s, (struct sockaddr *)&add= r, &addrlen); >>>>>> + =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D qemu_accept(s, (struct sockaddr *= )&addr, &addrlen); >>>>> >>>>> Would it be possible to improve the interface so that no casts are >>>>> needed for the calling code? >>>> >>>> How exactly would you do that? The only way I see to do it would be >>>> using void*, but I'm not sure if this really is an improvement. >>> >>> Instead of sockaddr_in vs. sockaddr and the lame casts in between, we >>> could have QSockAddr which magically works. Or if we only ever use >>> sockaddr_in, just use that. >> >> int qemu_accept(int s, union __attribute__((__transparent_union__)) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct sockaddr *sa; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct sockaddr_in *sin; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct sockaddr_in6 *sin6; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } addr, socklen_= t len); >> >> #define qemu_accept(s, addr) qemu_accept(s, addr, sizeof(*addr)) >> >> Seems to work. :-) But on the downside, it's a gcc extension. > Interesting. I didn't even know that __transparent_union__ exists. Might > be worth to consider, but the CLOEXEC patch definitely isn't the right > place to do the conversion. > > Blue Swirl, care to do it on top of my patch? The interface change is clearly out of scope of your patch.