Date: Sat, 10 Aug 2013 23:38:44 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Jilles Tjoelker <jilles@stack.nl> Cc: freebsd-arch@freebsd.org, Mario Oshogbo <oshogbo@FreeBSD.org> Subject: Re: closedir - change in the libc Message-ID: <20130810213844.GA1400@garage.freebsd.pl> In-Reply-To: <20130809105934.GA32419@stack.nl> References: <5204BD94.7050800@FreeBSD.org> <20130809105934.GA32419@stack.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 09, 2013 at 12:59:34PM +0200, Jilles Tjoelker wrote: > On Fri, Aug 09, 2013 at 11:59:48AM +0200, Mario Oshogbo wrote: > > I'm a student attending in GSoC'13 in project "Write new features for > > Capsicum" [1] and I would like to propose a little change to the libc. >=20 > > In the libc we have the function opendir(3) and fdopendir(3) which are > > responsible for opening directories. We also have function closedir(3) > > which is responsible for free the structure allocated by two previous > > funcions. >=20 > > The problem with the closedir(3) is that he close fd used as argument of > > fdopendir(3). I think programmer should be able to make a choice if he > > want to close this descriptor automatically or not. Of course we are > > able to use for dup(2) function and save fd before calling fdopendir(3) > > to prevent closing but I think this is the one syscall which we could s= ave. >=20 > > To support the propose I would like to give some example. I working now > > on making the fts(3) more sandbox friendly which means I would like to > > remove all fchdir(2) functions and operate only on fd. One of the steps > > I perform is changing the opendir(3) to the fdopendir(3). I also must > > remember the fd of currently opened directory after perform fclosedir. > > If we have N of directories we must perform N additional dup(2) and N > > additional close(2) functions to save this fd. >=20 > > So I would like to propose function called fdclosedir which will free > > DIR structure but will not close fd attached to DIR structure. This > > function also could return this fd which make it useful with the > > opendir(3) function, when we don't know the fd but we would like free > > DIR structure and perform some operations only on fd. I attach diff file > > with my proposal of change. >=20 > While this looks sensible, the only advantage is cleaner code and less > memory usage. Instead of additional dup()/close(), you could also keep > the DIR around as long as you need the fd. [...] This change is useful, I needed it in unrelated work to Mariusz's. I wanted to "borrow" my directory descriptor to some function, which were doing fdopendir(3) on it and to make it possible to not leak memory on return from this function I had to dup(2) this descriptor. I'd love to see fdclose() for similar reasons (see bin/75767, among others). --=20 Pawel Jakub Dawidek http://www.wheelsystems.com FreeBSD committer http://www.FreeBSD.org Am I Evil? Yes, I Am! http://mobter.com --jRHKVT23PllUwdXP Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iEYEARECAAYFAlIGsuQACgkQForvXbEpPzSTIwCg7/rf4M4iF85ubS/HOMbCdFPC 3nsAoLbxf3cTVR0GUKH9GqDb59+Vo4AX =Spn5 -----END PGP SIGNATURE----- --jRHKVT23PllUwdXP--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130810213844.GA1400>