From owner-freebsd-current@FreeBSD.ORG Wed Aug 20 01:12:43 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A8C6716A4BF for ; Wed, 20 Aug 2003 01:12:43 -0700 (PDT) Received: from stork.mail.pas.earthlink.net (stork.mail.pas.earthlink.net [207.217.120.188]) by mx1.FreeBSD.org (Postfix) with ESMTP id 147BF43FE1 for ; Wed, 20 Aug 2003 01:12:43 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from user-38lc1fj.dialup.mindspring.com ([209.86.5.243] helo=mindspring.com) by stork.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 19pO55-0006gz-00; Wed, 20 Aug 2003 01:12:36 -0700 Message-ID: <3F432D41.F8FD5834@mindspring.com> Date: Wed, 20 Aug 2003 01:11:45 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Dan Nelson References: <20030819110750.Q452@alpha.siliconlandmark.com> <20030819171155.GC5141@dan.emsphone.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a4c30de86fc36c4bb521a9f8e7484ea9c5a8438e0f32a48e08350badd9bab72f9c350badd9bab72f9c cc: current@freebsd.org cc: Andre Guibert de Bruet Subject: Re: fwcontrol -r missing a close() call X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Aug 2003 08:12:43 -0000 Dan Nelson wrote: > In the last episode (Aug 19), Andre Guibert de Bruet said: > > open("/dev/fw0.0",0x2,01001132500) = 3 (0x3) > > ioctl(3,FW_IBUSRST,0xbfbff400) = 0 (0x0) > > exit(0x0) > > process exit, rval = 0 > > > > We're not closing fd #3 before exiting the process. This is also the case > > with 4.8-STABLE. > > > > Semantics? Nit-picking? Both? :) > > Why bother closing a fd when exit() will do it for you? You don't > close stdout when you're done with it :) I used to think this way too. Then I had to deal with some multithreaded applications that failed to pthread_join() or pthread_kill() their threads, AND with applications that had called blocking calls on fd's in one thread, and then closed the fd's out from under the blocking calls in another, thus triggering a kernel panic, AND applications which failed to realize a signal may interrupt a close() call, making it return -1 with errno == EINTR, thus leaking descriptors on any close that was interrupted by a signal. After dealing with all that, I have to say that the lack of an explicit close of an fd is an incredibly bad example for any programmer who might read your code. As such, it should be fixed, since it may be your own foot you are shooting in the future by providing a bad example to some programmer that then writes code that you decide you want to run on your machine. Don't even get me started on the people who think that all the world is Linux, and fail to bzero() their sockaddr_in's before filling out only some of the structure members, and having all the various connect/bind/other socket related calls fail on non-Linux machines because the programmers didn't know how to properly use the interfaces they were calling. -- Terry