From owner-freebsd-hackers@freebsd.org Mon Jan 8 17:52:01 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F3104E7AABF for ; Mon, 8 Jan 2018 17:52:01 +0000 (UTC) (envelope-from eric@vangyzen.net) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [199.48.133.146]) by mx1.freebsd.org (Postfix) with ESMTP id DB30E692CC; Mon, 8 Jan 2018 17:52:01 +0000 (UTC) (envelope-from eric@vangyzen.net) Received: from sweettea.beer.town (unknown [76.164.8.130]) by smtp.vangyzen.net (Postfix) with ESMTPSA id 80FEA5646F; Mon, 8 Jan 2018 11:52:00 -0600 (CST) Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? To: "Rodney W. Grimes" , Eugene Grosbein Cc: Brooks Davis , Alan Somers , Yuri , Ian Lepore , Freebsd hackers list References: <201801081655.w08GtO3D022568@pdx.rh.CN85.dnsmgr.net> From: Eric van Gyzen Message-ID: Date: Mon, 8 Jan 2018 11:51:56 -0600 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <201801081655.w08GtO3D022568@pdx.rh.CN85.dnsmgr.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2018 17:52:02 -0000 On 01/08/2018 10:55, Rodney W. Grimes wrote: >> 08.01.2018 23:13, Eric van Gyzen wrote: >> >>> Right, which is the reason such bugs are hard to diagnose. Optionally >>> killing the process on close->EBADF would help find buggy code when >>> another thread did NOT re-open the file descriptor between the two close >>> calls. >> >> Wouldn't "close(f); assert(errno != EBADF);" be better? Putting the code in one place is far better than putting it in N places...after /finding/ those N places. Indeed, the purpose of this code is to help people find those places, even in their own code, outside of base. > Or even > #ifdef DEBUG_CLOSE > #define close(f) close(f); assert(errno != EBADF); > #endif errno could have been EBADF before the close(). A successful close() does not modify errno. So, this would have be larger, making it even more unpalatable. > Then the people that want to go chasing these errors can, > and the rest of us are untouched. Every mention in this thread of killing the process has called it optional. Tools, not policy. Eric