Date: Wed, 10 Jan 2018 12:12:27 +0100 From: Stefan Esser <se@freebsd.org> To: Poul-Henning Kamp <phk@phk.freebsd.dk> Cc: "Rodney W. Grimes" <freebsd-rwg@pdx.rh.CN85.dnsmgr.net>, Eric van Gyzen <eric@vangyzen.net>, Brooks Davis <brooks@freebsd.org>, Ian Lepore <ian@freebsd.org>, Alan Somers <asomers@freebsd.org>, Freebsd hackers list <freebsd-hackers@freebsd.org>, Yuri <yuri@rawbw.com>, Eugene Grosbein <eugen@grosbein.net> Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? Message-ID: <0ec49613-0eb5-6c6d-f9aa-f88cf4c22659@freebsd.org> In-Reply-To: <21075.1515581257@critter.freebsd.dk> References: <201801081800.w08I0D0q022877@pdx.rh.CN85.dnsmgr.net> <b7d5cc97-2042-42ff-914c-35a28560932b@freebsd.org> <21075.1515581257@critter.freebsd.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
Am 10.01.18 um 11:47 schrieb Poul-Henning Kamp: > -------- > In message <b7d5cc97-2042-42ff-914c-35a28560932b@freebsd.org>, Stefan Esser wri > tes: > >>> Ok, so lets get a bit more clever, >>> #ifdef DEBUG_CLOSE >>> #define close(f) assert(close(f) && errno != EBADF) >>> #endif >> >> This will lead to close() being removed from the program, >> if NDEBUG is defined ... >> >> So, at least test for NDEBUG in addition to DEBUG_CLOSE, >> to enable this macro. > > More importantly, it will lead to the assert failing if close(2) > succeeds... Oh, yes, I missed that detail ;-) > The NDEBUG details is easiest solved by: > > #undef NDEBUG // assert()'s not to be removed > #include <assert.h> There has been the much better suggestion by Conrad Meyer (which uses a GCC extension that might not be supported by CLANG?) and the LD_PRELOAD hack suggested by Konstantin Belousov, which even works without recompilation of the program that is to be checked. I should have read the full thread before replying to a post in the middle of the discussion ... Regards, STefan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0ec49613-0eb5-6c6d-f9aa-f88cf4c22659>