From owner-freebsd-hackers@freebsd.org Mon Jan 8 18:00:15 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 F34DCE7B2FF for ; Mon, 8 Jan 2018 18:00:15 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (br1.CN84in.dnsmgr.net [69.59.192.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B010169A69; Mon, 8 Jan 2018 18:00:15 +0000 (UTC) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: from pdx.rh.CN85.dnsmgr.net (localhost [127.0.0.1]) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3) with ESMTP id w08I0DAZ022878; Mon, 8 Jan 2018 10:00:13 -0800 (PST) (envelope-from freebsd-rwg@pdx.rh.CN85.dnsmgr.net) Received: (from freebsd-rwg@localhost) by pdx.rh.CN85.dnsmgr.net (8.13.3/8.13.3/Submit) id w08I0D0q022877; Mon, 8 Jan 2018 10:00:13 -0800 (PST) (envelope-from freebsd-rwg) From: "Rodney W. Grimes" Message-Id: <201801081800.w08I0D0q022877@pdx.rh.CN85.dnsmgr.net> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? In-Reply-To: To: Eric van Gyzen Date: Mon, 8 Jan 2018 10:00:13 -0800 (PST) CC: Eugene Grosbein , Yuri , Brooks Davis , Ian Lepore , Alan Somers , Freebsd hackers list X-Mailer: ELM [version 2.4ME+ PL121h (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Mailman-Approved-At: Mon, 08 Jan 2018 19:08:13 +0000 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 18:00:16 -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. I agree with that. > > 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. Ok, so lets get a bit more clever, #ifdef DEBUG_CLOSE #define close(f) assert(close(f) && errno != EBADF) #endif There, now only if close failed do we check errno, how does that work for you? And if it doesnt I am sure you can code up a #define that does work well. > > > 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. I am not certain on that, I think some of the proposals seemed to make the change non optional, but maybe I was reading too much between the lines. -- Rod Grimes rgrimes@freebsd.org