From owner-freebsd-hackers@freebsd.org Wed Jan 10 11:12:33 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 09254E796E3 for ; Wed, 10 Jan 2018 11:12:33 +0000 (UTC) (envelope-from se@freebsd.org) Received: from mailout06.t-online.de (mailout06.t-online.de [194.25.134.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mailout00.t-online.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BEE196E807; Wed, 10 Jan 2018 11:12:32 +0000 (UTC) (envelope-from se@freebsd.org) Received: from fwd15.aul.t-online.de (fwd15.aul.t-online.de [172.20.27.63]) by mailout06.t-online.de (Postfix) with SMTP id 4DD2E41C6C44; Wed, 10 Jan 2018 12:12:29 +0100 (CET) Received: from Stefans-MBP-LAN.fritz.box (bRCgkvZXrhtqx4gn2OVWo9wXLngP-4XpEBUElqM2AlySnfRSwE+lVz-L1gbID0FZ73@[87.151.219.126]) by fwd15.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1eZEJ2-2XpnSy0; Wed, 10 Jan 2018 12:12:28 +0100 Subject: Re: Is it considered to be ok to not check the return code of close(2) in base? To: Poul-Henning Kamp Cc: "Rodney W. Grimes" , Eric van Gyzen , Brooks Davis , Ian Lepore , Alan Somers , Freebsd hackers list , Yuri , Eugene Grosbein References: <201801081800.w08I0D0q022877@pdx.rh.CN85.dnsmgr.net> <21075.1515581257@critter.freebsd.dk> From: Stefan Esser Message-ID: <0ec49613-0eb5-6c6d-f9aa-f88cf4c22659@freebsd.org> Date: Wed, 10 Jan 2018 12:12:27 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <21075.1515581257@critter.freebsd.dk> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ID: bRCgkvZXrhtqx4gn2OVWo9wXLngP-4XpEBUElqM2AlySnfRSwE+lVz-L1gbID0FZ73 X-TOI-MSGID: 6a85e584-6838-45da-ab93-bb24e4401669 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: Wed, 10 Jan 2018 11:12:33 -0000 Am 10.01.18 um 11:47 schrieb Poul-Henning Kamp: > -------- > In message , 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 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