From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MbqRt-0006Rr-9z for qemu-devel@nongnu.org; Fri, 14 Aug 2009 02:39:37 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MbqRo-0006RM-Lp for qemu-devel@nongnu.org; Fri, 14 Aug 2009 02:39:36 -0400 Received: from [199.232.76.173] (port=46384 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MbqRo-0006RJ-EM for qemu-devel@nongnu.org; Fri, 14 Aug 2009 02:39:32 -0400 Received: from mx2.redhat.com ([66.187.237.31]:58035) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbqRn-0004Jo-R1 for qemu-devel@nongnu.org; Fri, 14 Aug 2009 02:39:32 -0400 Subject: Re: [Qemu-devel] [PATCH 2/5] Add SCM_RIGHTS support to unix socket character devices From: Mark McLoughlin In-Reply-To: <4A843D4A.5030306@cs.ualberta.ca> References: <1248250235.2867.34.camel@blaa> <1248250302-28595-2-git-send-email-markmc@redhat.com> <4A843D4A.5030306@cs.ualberta.ca> Content-Type: text/plain Date: Fri, 14 Aug 2009 07:38:39 +0100 Message-Id: <1250231919.3010.9.camel@blaa> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Reply-To: Mark McLoughlin List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cam Macdonell Cc: qemu-devel@nongnu.org On Thu, 2009-08-13 at 10:20 -0600, Cam Macdonell wrote: > > @@ -1957,6 +2004,10 @@ static void tcp_chr_read(void *opaque) > > tcp_chr_process_IAC_bytes(chr, s, buf, &size); > > if (size > 0) > > qemu_chr_read(chr, buf, size); > > + if (s->msgfd != -1) { > > + close(s->msgfd); > > + s->msgfd = -1; > > + } > > Hi Mark, > > I'm trying to understand the intended behaviour here so I can use your > patch. In your comments for the patch it reads "store the file > descriptor for use in the chr_read() handler. Close the file descriptor > if it was not used." It seems that upon returning from the chr_read() > handler the descriptor is closed if s->msgfd is not set to -1. Does > this mean the handler should set the fd to -1 after retrieving it if the > process wants to keep that fd open, otherwise it will be closed when > chr_read() returns? Should tcp_get_msgfd() perhaps set s->msgfd to -1 > after it is retrieved? Sort of a "read and clear" behaviour? Yes, that would work and TBH I can't recall why I chose not to do that. It'd be like popping the fd from a one item queue. The current caller of get_msgfd() dup()s the fd which achieves the same thing. Cheers, Mark.