POSIX-portable (i.e. glibc) way to list all open file descriptors?
I would like to obtain a list of all open file descriptors for a program. This is to mitigate a security issue with an exec program having access to all of its parent's file descriptors; they need to be closed before the exec call except for 0-4.
My first thought is to list all character devices in /proc/self/fd and close all but those I need. Is there a libc way to do this so that I can use this application on BSD, etc.? Thanks.
ta0kira
edit: close-on-exec should work I think...
Last edited by ta0kira; 07-21-2007 at 11:54 AM.
|