Date: Sat, 6 Jan 2018 05:57:29 +0700 From: Eugene Grosbein <eugen@grosbein.net> To: Eric van Gyzen <eric@vangyzen.net>, Brooks Davis <brooks@freebsd.org>, Alan Somers <asomers@freebsd.org> Cc: Yuri <yuri@rawbw.com>, Ian Lepore <ian@freebsd.org>, Freebsd hackers list <freebsd-hackers@freebsd.org> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? Message-ID: <5A5002D9.9080205@grosbein.net> In-Reply-To: <7b977409-96ee-5acb-60d0-3b0e124495f0@vangyzen.net> References: <24acbd94-c52f-e71a-8a96-d608a10963c6@rawbw.com> <1514572041.12000.7.camel@freebsd.org> <CAOtMX2jSonHQ9xzVD3Q9XS2twBm_CT3Tquwn%2Bf6zmc7aV0QerQ@mail.gmail.com> <20180105221330.GD95035@spindle.one-eyed-alien.net> <5A4FF989.1040709@grosbein.net> <7b977409-96ee-5acb-60d0-3b0e124495f0@vangyzen.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5A5002D9.9080205>