closedir - change in the libc

Mario Oshogbo oshogbo at FreeBSD.org
Fri Aug 9 09:59:59 UTC 2013


Hi,

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.

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.

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 save.

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.

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.

Chears,
oshogbo

[1] https://wiki.freebsd.org/SummerOfCode2013/CapsicumFeatures
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fdclosedir.patch
Type: text/x-patch
Size: 1631 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20130809/651bc395/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20130809/651bc395/attachment.sig>


More information about the freebsd-arch mailing list