From owner-freebsd-net Wed Dec 13 13:23: 2 2000 From owner-freebsd-net@FreeBSD.ORG Wed Dec 13 13:22:55 2000 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from Awfulhak.org (awfulhak.demon.co.uk [194.222.196.252]) by hub.freebsd.org (Postfix) with ESMTP id 9188037B402; Wed, 13 Dec 2000 13:22:53 -0800 (PST) Received: from hak.lan.Awfulhak.org (root@hak.lan.awfulhak.org [172.16.0.12]) by Awfulhak.org (8.11.1/8.11.1) with ESMTP id eBDLKcZ03838; Wed, 13 Dec 2000 21:20:39 GMT (envelope-from brian@lan.awfulhak.org) Received: from hak.lan.Awfulhak.org (brian@localhost [127.0.0.1]) by hak.lan.Awfulhak.org (8.11.1/8.11.1) with ESMTP id eBDLOBU68538; Wed, 13 Dec 2000 21:24:11 GMT (envelope-from brian@hak.lan.Awfulhak.org) Message-Id: <200012132124.eBDLOBU68538@hak.lan.Awfulhak.org> X-Mailer: exmh version 2.2 06/23/2000 with nmh-1.0.4 To: Alfred Perlstein Cc: arch@FreeBSD.ORG, net@FreeBSD.ORG, brian@Awfulhak.org Subject: Re: patch to cleanup inflight desciptor handling. In-Reply-To: Message from Alfred Perlstein of "Wed, 13 Dec 2000 02:26:38 PST." <20001213022637.A16205@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 13 Dec 2000 21:24:11 +0000 From: Brian Somers Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > Not a lot of people are familiar with fd passing so I'll give > a short description: > > By using AF_UNIX sockets between processes, a process can use > sendmsg() to send a filedescriptor through the socket where the > other process will do a recvmsg() to pickup the descriptor. > > The "problem" is that if a descriptor is in transit/inflight > and the sending process closes the file, it still needs to > remain open for the recipient. > > What can happen is: > > process A: sendmsg(descriptor) > process A: exit > process B: exit > > without the garbage collection we'd have leaked a file descriptor > inside the kernel. [.....] Hmm, the last time i looked at this, I believe the whole thing was dealt with by not increasing the file descriptor reference count when it was put in the message header. If process A closed the descriptor before process B actually recvmsg()d it, it would be EBADF. The recvmsg() actually incremented the reference count. I always assumed that this was a result of not wanting to have any funny garbage collecting code ? Of course looking at the code now, it increases fp->f_count in unp_internalize(), so maybe I was on drugs then.... Assuming I wasn't on drugs (maybe the behaviour was changed - cvs annotate suggests some activity around March 9, but that was the file*/int alignment stuff), I think it would be valid to go back to the old behaviour (not increasing f_count and letting the original owner actually close the descriptor while f_msgcount != 0). Does any of this make sense ? Or am I just describing a different case (where process B doesn't exit) ? > -- > -Alfred Perlstein - [bright@wintelcom.net|alfred@freebsd.org] > "I have the heart of a child; I keep it in a jar on my desk." -- Brian Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message