Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Jan 2018 21:59:47 +0000
From:      Brooks Davis <brooks@freebsd.org>
To:        Ian Lepore <ian@freebsd.org>
Cc:        cem@freebsd.org, Poul-Henning Kamp <phk@phk.freebsd.dk>, 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:  <20180106215947.GG95035@spindle.one-eyed-alien.net>
In-Reply-To: <1515201055.1865.5.camel@freebsd.org>
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> <24173.1515191675@critter.freebsd.dk> <CAG6CVpULXoq6w4Xb%2BiSJ08phFuiCPhEod25Y4Am5PN9R=R5iZQ@mail.gmail.com> <1515201055.1865.5.camel@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--QNDPHrPUIc00TOLW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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@phk.freebsd.dk
> > > wrote:
> > >=20
> > > Brookes suggestion, while well intentioned, wouldn't get very far,
> > > because it is common for shells and shell-like programs to do:
> > >=20
> > > ????????for (i =3D 3; i < ALOT; i++)
> > > ????????????????(void)close(i);
> > >=20
> > > To get rid of unwanted filedescriptors from syslog(3), getpwent(3)
> > > etc.
> > > in the child process.
> > >=20
> > > Yes, I know about closefrom(2), but a lot of programs still don't
> > > use it.
> >=20
> > That seems like a good way to quickly identify programs in base that
> > still do not use closefrom().
>=20
> 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

--QNDPHrPUIc00TOLW
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEcBAEBAgAGBQJaUUbSAAoJEKzQXbSebgfAC1kH+wUkAsZ0B17uxoL0Bvisj8nO
cLTwJ0H0iY8zwsTXKpUFK/4yLcML+CO0MJta3xHDXnQcDbzd4UCLGt+dybTeP6bW
967Zb9PWrM/ZFQ7R+7LimaHeQnJTEz0g7M+fxuaAFfCVfvBSMWpiGm3Ic3PeCXs2
+CgI7zjVFWrawTOaPZOM4xxlxE+NU1tc5YMvhyZxClUNWOC7I1DVeCNcU14XIJgd
16FlzU6WaAPVL7T17U0biHjB7CPHzhZsiiE2IR8HQEFS2Z2LMdFY5jwdZhJYT4ry
d10X7CKwSSYmRgopokKFgE0NzIamc3N1sdgQRtvuiPIulCsaXarv7ZOcog1CzPU=
=QuZ2
-----END PGP SIGNATURE-----

--QNDPHrPUIc00TOLW--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180106215947.GG95035>