Is it considered to be ok to not check the return code of close(2) in base?

Brooks Davis brooks at freebsd.org
Sat Jan 6 21:59:50 UTC 2018


On Fri, Jan 05, 2018 at 06:10:55PM -0700, Ian Lepore wrote:
> On Fri, 2018-01-05 at 15:17 -0800, Conrad Meyer wrote:
> > On Fri, Jan 5, 2018 at 2:34 PM, Poul-Henning Kamp <phk at phk.freebsd.dk
> > > wrote:
> > > 
> > > Brookes suggestion, while well intentioned, wouldn't get very far,
> > > because it is common for shells and shell-like programs to do:
> > > 
> > > ????????for (i = 3; i < ALOT; i++)
> > > ????????????????(void)close(i);
> > > 
> > > To get rid of unwanted filedescriptors from syslog(3), getpwent(3)
> > > etc.
> > > in the child process.
> > > 
> > > Yes, I know about closefrom(2), but a lot of programs still don't
> > > use it.
> > 
> > That seems like a good way to quickly identify programs in base that
> > still do not use closefrom().
> 
> Portable programs MUST iterate 3-ALOT, because closefrom() is not
> available in linux and other OSes.

The portable API is terrible and closefrom() with arguments
other than 3 (or maybe 4) is in many ways worse with require dup2(2)
shenanigans.  A non-crap (but harder to adopt) API would be an extended
execve(2) that takes an array of FDs to be installed in the given
positions.  (I'd probably make the array be name-value pairs, as I believe
cloudabi does, since magic offsets into a kernel array have no business
in a 21st century IPC API.)

-- Brooks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20180106/677c4101/attachment.sig>


More information about the freebsd-hackers mailing list