Date: Mon, 8 Jan 2018 20:42:33 +0200 From: Konstantin Belousov <kostikbel@gmail.com> To: Conrad Meyer <cem@freebsd.org> Cc: Andrew Duane <aduane@juniper.net>, 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: <20180108184233.GL1684@kib.kiev.ua> In-Reply-To: <CAG6CVpXq5rx6HW=UuHD29D7EZPr0z7LfZ4Rox1j6u=qMyGvpnQ@mail.gmail.com> References: <201801081655.w08GtO3D022568@pdx.rh.CN85.dnsmgr.net> <df6f98a5-76db-d6d8-6321-d35b59eeec22@vangyzen.net> <SN1PR0501MB212559C6D852EBEEA3A89C7CCE130@SN1PR0501MB2125.namprd05.prod.outlook.com> <CAG6CVpXq5rx6HW=UuHD29D7EZPr0z7LfZ4Rox1j6u=qMyGvpnQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 08, 2018 at 10:13:19AM -0800, Conrad Meyer wrote: > On Mon, Jan 8, 2018 at 10:05 AM, Andrew Duane <aduane@juniper.net> wrote: > > Of course, my OCD will kick in and say this would need to be something like: > > > > #ifdef DEBUG_CLOSE > > #define close(f) do {if (close(f) < 0) assert(errno != EBADF); } while (0) > > #endif > > > > Have to watch those macro replacements like "if (need_to_close) close(f);". And the close succeeding :-) > > Of course, this has turned into nerd sniping. But I'll take my turn. > > Better to use the GCC "statement expression" extension so that the > return value of "close()" can still be used by callers naive to the > macro. > > #define close(f) ({ int __ret; __ret = (close)(f); if (__ret < 0) > assert(errno != EBADF); __ret; }) You can create a dso which interposes close(3), calls original close() resolved by dlsym(RTLD_NEXT), and checks for the error, for use with LD_PRELOAD environment variable. No need to vandali^H^H^H^hack on either kernel nor userland code.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180108184233.GL1684>