From owner-freebsd-hackers@freebsd.org Fri Jan 5 22:57:45 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 73590EA4898 for ; Fri, 5 Jan 2018 22:57:45 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from hz.grosbein.net (hz.grosbein.net [78.47.246.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "hz.grosbein.net", Issuer "hz.grosbein.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 0011A6389A; Fri, 5 Jan 2018 22:57:44 +0000 (UTC) (envelope-from eugen@grosbein.net) Received: from eg.sd.rdtc.ru (root@eg.sd.rdtc.ru [62.231.161.221] (may be forged)) by hz.grosbein.net (8.15.2/8.15.2) with ESMTPS id w05MvaP6042267 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 5 Jan 2018 23:57:37 +0100 (CET) (envelope-from eugen@grosbein.net) X-Envelope-From: eugen@grosbein.net X-Envelope-To: eric@vangyzen.net Received: from [10.58.0.4] ([10.58.0.4]) by eg.sd.rdtc.ru (8.15.2/8.15.2) with ESMTPS id w05MvXxX030890 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Sat, 6 Jan 2018 05:57:33 +0700 (+07) (envelope-from eugen@grosbein.net) Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? To: Eric van Gyzen , Brooks Davis , Alan Somers References: <24acbd94-c52f-e71a-8a96-d608a10963c6@rawbw.com> <1514572041.12000.7.camel@freebsd.org> <20180105221330.GD95035@spindle.one-eyed-alien.net> <5A4FF989.1040709@grosbein.net> <7b977409-96ee-5acb-60d0-3b0e124495f0@vangyzen.net> Cc: Yuri , Ian Lepore , Freebsd hackers list From: Eugene Grosbein Message-ID: <5A5002D9.9080205@grosbein.net> Date: Sat, 6 Jan 2018 05:57:29 +0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <7b977409-96ee-5acb-60d0-3b0e124495f0@vangyzen.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=2.2 required=5.0 tests=BAYES_00, LOCAL_FROM, RDNS_NONE autolearn=no autolearn_force=no version=3.4.1 X-Spam-Report: * -2.3 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * 2.6 LOCAL_FROM From my domains * 1.9 RDNS_NONE Delivered to internal network by a host with no rDNS X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on hz.grosbein.net 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: Fri, 05 Jan 2018 22:57:45 -0000 06.01.2018 5:26, Eric van Gyzen wrote: >>>> I would argue the opposite. There are very few reasons why close(s) would >>>> ever fail, and the most likely is EBADF. EBADF indicates a programming >>>> bug, like a double close or use of an uninitialized variable. Those could >>>> easily turn into worse bugs in the future. So I think the best course of >>>> action is to check the return code, assert() on EBADF, and ignore, or >>>> possibly log, other errors. >>> >>> For this specific case, I think there would be value in an option to >>> have the kernel kill any process that calls close(fd) where fd != -1 >>> where EBADF would be returned. >> >> A medicine should not be worse worse than the disease, imho. > > In a multi-threaded application, a double-close can close completely > unrelated file descriptors, which can be a nightmare to diagnose. In > that case, death by signal is far better than the disease. A kernel cannot know if close() was called for "unrealated" but correct file descriptor.